1
0
mirror of https://github.com/bitwarden/browser synced 2026-02-11 14:04:03 +00:00

Fix tests

This commit is contained in:
Thomas Rittson
2025-03-19 19:48:51 +10:00
parent b70267e2f6
commit 6a2794f3cf
2 changed files with 44 additions and 67 deletions

View File

@@ -3,7 +3,6 @@ import { BehaviorSubject } from "rxjs";
import { ApiService } from "@bitwarden/common/abstractions/api.service";
import { PolicyService } from "@bitwarden/common/admin-console/abstractions/policy/policy.service.abstraction";
import { AccountService } from "@bitwarden/common/auth/abstractions/account.service";
import { TokenService } from "@bitwarden/common/auth/abstractions/token.service";
import { TwoFactorService } from "@bitwarden/common/auth/abstractions/two-factor.service";
import { TwoFactorProviderType } from "@bitwarden/common/auth/enums/two-factor-provider-type";
@@ -17,6 +16,7 @@ import { IdentityTokenResponse } from "@bitwarden/common/auth/models/response/id
import { IdentityTwoFactorResponse } from "@bitwarden/common/auth/models/response/identity-two-factor.response";
import { MasterPasswordPolicyResponse } from "@bitwarden/common/auth/models/response/master-password-policy.response";
import { IUserDecryptionOptionsServerResponse } from "@bitwarden/common/auth/models/response/user-decryption-options/user-decryption-options.response";
import { OpaqueKeyExchangeService } from "@bitwarden/common/auth/opaque/opaque-key-exchange.service";
import { BillingAccountProfileStateService } from "@bitwarden/common/billing/abstractions/account/billing-account-profile-state.service";
import { EncryptService } from "@bitwarden/common/key-management/crypto/abstractions/encrypt.service";
import { FakeMasterPasswordService } from "@bitwarden/common/key-management/master-password/services/fake-master-password.service";
@@ -25,6 +25,7 @@ import {
VaultTimeoutSettingsService,
} from "@bitwarden/common/key-management/vault-timeout";
import { AppIdService } from "@bitwarden/common/platform/abstractions/app-id.service";
import { ConfigService } from "@bitwarden/common/platform/abstractions/config/config.service";
import { EnvironmentService } from "@bitwarden/common/platform/abstractions/environment.service";
import { LogService } from "@bitwarden/common/platform/abstractions/log.service";
import { MessagingService } from "@bitwarden/common/platform/abstractions/messaging.service";
@@ -123,6 +124,8 @@ describe("BaseLoginStrategy", () => {
let vaultTimeoutSettingsService: MockProxy<VaultTimeoutSettingsService>;
let kdfConfigService: MockProxy<KdfConfigService>;
let environmentService: MockProxy<EnvironmentService>;
let configService: MockProxy<ConfigService>;
let opaqueKeyExchangeService: MockProxy<OpaqueKeyExchangeService>;
let passwordLoginStrategy: PasswordLoginStrategy;
let credentials: PasswordHashLoginCredentials;
@@ -147,6 +150,8 @@ describe("BaseLoginStrategy", () => {
passwordStrengthService = mock<PasswordStrengthService>();
billingAccountProfileStateService = mock<BillingAccountProfileStateService>();
environmentService = mock<EnvironmentService>();
configService = mock();
opaqueKeyExchangeService = mock();
vaultTimeoutSettingsService = mock<VaultTimeoutSettingsService>();
@@ -154,28 +159,7 @@ describe("BaseLoginStrategy", () => {
tokenService.decodeAccessToken.calledWith(accessToken).mockResolvedValue(decodedToken);
// The base class is abstract so we test it via PasswordLoginStrategy
passwordLoginStrategy = new PasswordLoginStrategy(
cache,
passwordStrengthService,
policyService,
accountService as unknown as AccountService,
masterPasswordService,
keyService,
encryptService,
apiService,
tokenService,
appIdService,
platformUtilsService,
messagingService,
logService,
stateService,
twoFactorService,
userDecryptionOptionsService,
billingAccountProfileStateService,
vaultTimeoutSettingsService,
kdfConfigService,
environmentService,
);
passwordLoginStrategy = createPasswordLoginStrategy();
credentials = new PasswordHashLoginCredentials(email, masterPassword, new PBKDF2KdfConfig());
});
@@ -500,28 +484,7 @@ describe("BaseLoginStrategy", () => {
new TokenTwoFactorRequest(),
);
passwordLoginStrategy = new PasswordLoginStrategy(
cache,
passwordStrengthService,
policyService,
accountService as AccountService,
masterPasswordService,
keyService,
encryptService,
apiService,
tokenService,
appIdService,
platformUtilsService,
messagingService,
logService,
stateService,
twoFactorService,
userDecryptionOptionsService,
billingAccountProfileStateService,
vaultTimeoutSettingsService,
kdfConfigService,
environmentService,
);
passwordLoginStrategy = createPasswordLoginStrategy(cache);
apiService.postIdentityToken.mockResolvedValue(identityTokenResponseFactory());
@@ -563,32 +526,38 @@ describe("BaseLoginStrategy", () => {
new TokenTwoFactorRequest(),
);
passwordLoginStrategy = new PasswordLoginStrategy(
cache,
passwordStrengthService,
policyService,
accountService as AccountService,
masterPasswordService,
keyService,
encryptService,
apiService,
tokenService,
appIdService,
platformUtilsService,
messagingService,
logService,
stateService,
twoFactorService,
userDecryptionOptionsService,
billingAccountProfileStateService,
vaultTimeoutSettingsService,
kdfConfigService,
environmentService,
);
passwordLoginStrategy = createPasswordLoginStrategy(cache);
const result = await passwordLoginStrategy.logIn(credentials);
expect(result.requiresDeviceVerification).toBe(true);
});
});
function createPasswordLoginStrategy(cache?: PasswordLoginStrategyData) {
return new PasswordLoginStrategy(
cache ?? new PasswordLoginStrategyData(),
passwordStrengthService,
policyService,
configService,
opaqueKeyExchangeService,
accountService,
masterPasswordService,
keyService,
encryptService,
apiService,
tokenService,
appIdService,
platformUtilsService,
messagingService,
logService,
stateService,
twoFactorService,
userDecryptionOptionsService,
billingAccountProfileStateService,
vaultTimeoutSettingsService,
kdfConfigService,
environmentService,
);
}
});

View File

@@ -48,6 +48,8 @@ import { UserDecryptionOptionsService } from "../user-decryption-options/user-de
import { LoginStrategyService } from "./login-strategy.service";
import { CACHE_EXPIRATION_KEY } from "./login-strategy.state";
import { OpaqueKeyExchangeService } from "@bitwarden/common/auth/opaque/opaque-key-exchange.service";
import { ConfigService } from "@bitwarden/common/platform/abstractions/config/config.service";
// TODO: update tests to pass
// TODO: test makePrePasswordLoginMasterKey
@@ -79,6 +81,8 @@ describe("LoginStrategyService", () => {
let kdfConfigService: MockProxy<KdfConfigService>;
let taskSchedulerService: MockProxy<TaskSchedulerService>;
let prePasswordLoginApiService: MockProxy<PrePasswordLoginApiService>;
let configService: MockProxy<ConfigService>;
let opaqueKeyExchangeService: MockProxy<OpaqueKeyExchangeService>;
let stateProvider: FakeGlobalStateProvider;
let loginStrategyCacheExpirationState: FakeGlobalState<Date | null>;
@@ -112,6 +116,8 @@ describe("LoginStrategyService", () => {
kdfConfigService = mock<KdfConfigService>();
taskSchedulerService = mock<TaskSchedulerService>();
prePasswordLoginApiService = mock<PrePasswordLoginApiService>();
configService = mock();
opaqueKeyExchangeService = mock();
sut = new LoginStrategyService(
accountService,
@@ -140,6 +146,8 @@ describe("LoginStrategyService", () => {
kdfConfigService,
taskSchedulerService,
prePasswordLoginApiService,
configService,
opaqueKeyExchangeService,
);
loginStrategyCacheExpirationState = stateProvider.getFake(CACHE_EXPIRATION_KEY);