diff --git a/libs/auth/src/common/login-strategies/base-login.strategy.spec.ts b/libs/auth/src/common/login-strategies/base-login.strategy.spec.ts index 6ea786c049f..cc673c05936 100644 --- a/libs/auth/src/common/login-strategies/base-login.strategy.spec.ts +++ b/libs/auth/src/common/login-strategies/base-login.strategy.spec.ts @@ -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; let kdfConfigService: MockProxy; let environmentService: MockProxy; + let configService: MockProxy; + let opaqueKeyExchangeService: MockProxy; let passwordLoginStrategy: PasswordLoginStrategy; let credentials: PasswordHashLoginCredentials; @@ -147,6 +150,8 @@ describe("BaseLoginStrategy", () => { passwordStrengthService = mock(); billingAccountProfileStateService = mock(); environmentService = mock(); + configService = mock(); + opaqueKeyExchangeService = mock(); vaultTimeoutSettingsService = mock(); @@ -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, + ); + } }); diff --git a/libs/auth/src/common/services/login-strategies/login-strategy.service.spec.ts b/libs/auth/src/common/services/login-strategies/login-strategy.service.spec.ts index cebd86832c9..d02338eafff 100644 --- a/libs/auth/src/common/services/login-strategies/login-strategy.service.spec.ts +++ b/libs/auth/src/common/services/login-strategies/login-strategy.service.spec.ts @@ -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; let taskSchedulerService: MockProxy; let prePasswordLoginApiService: MockProxy; + let configService: MockProxy; + let opaqueKeyExchangeService: MockProxy; let stateProvider: FakeGlobalStateProvider; let loginStrategyCacheExpirationState: FakeGlobalState; @@ -112,6 +116,8 @@ describe("LoginStrategyService", () => { kdfConfigService = mock(); taskSchedulerService = mock(); prePasswordLoginApiService = mock(); + 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);