1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-22 19:23:52 +00:00

[PM-8979] Check that user is authed before getting user config (#10031)

* Check that user is authed before getting user config

* Accept PR Suggestion

Co-authored-by: Andreas Coroiu <acoroiu@bitwarden.com>

* Use Strict Equal

---------

Co-authored-by: Andreas Coroiu <acoroiu@bitwarden.com>
This commit is contained in:
Justin Baur
2024-07-15 10:41:10 -04:00
committed by GitHub
parent 5a46c7d5cc
commit 5fcf4bbd10
5 changed files with 56 additions and 6 deletions

View File

@@ -14,6 +14,8 @@ import {
mockAccountServiceWith,
} from "../../../../spec";
import { subscribeTo } from "../../../../spec/observable-tracker";
import { AuthService } from "../../../auth/abstractions/auth.service";
import { AuthenticationStatus } from "../../../auth/enums/authentication-status";
import { UserId } from "../../../types/guid";
import { ConfigApiServiceAbstraction } from "../../abstractions/config/config-api.service.abstraction";
import { ServerConfig } from "../../abstractions/config/server-config";
@@ -39,6 +41,9 @@ describe("ConfigService", () => {
const configApiService = mock<ConfigApiServiceAbstraction>();
const environmentService = mock<EnvironmentService>();
const logService = mock<LogService>();
const authService = mock<AuthService>({
authStatusFor$: (userId) => of(AuthenticationStatus.Unlocked),
});
let stateProvider: FakeStateProvider;
let globalState: FakeGlobalState<Record<ApiUrl, ServerConfig>>;
let userState: FakeSingleUserState<ServerConfig>;
@@ -71,6 +76,7 @@ describe("ConfigService", () => {
environmentService,
logService,
stateProvider,
authService,
);
});
@@ -188,6 +194,30 @@ describe("ConfigService", () => {
});
});
it("gets global config when there is an locked active user", async () => {
await accountService.switchAccount(userId);
environmentService.environment$ = of(environmentFactory(activeApiUrl));
globalState.stateSubject.next({
[activeApiUrl]: serverConfigFactory(activeApiUrl + "global"),
});
userState.nextState(serverConfigFactory(userId));
const sut = new DefaultConfigService(
configApiService,
environmentService,
logService,
stateProvider,
mock<AuthService>({
authStatusFor$: () => of(AuthenticationStatus.Locked),
}),
);
const config = await firstValueFrom(sut.serverConfig$);
expect(config.gitHash).toEqual(activeApiUrl + "global");
});
describe("environment change", () => {
let sut: DefaultConfigService;
let environmentSubject: Subject<Environment>;
@@ -205,6 +235,7 @@ describe("ConfigService", () => {
environmentService,
logService,
stateProvider,
authService,
);
});