From 3668fed7b4267546f7293b78413d34adf487f01e Mon Sep 17 00:00:00 2001 From: Alec Rippberger Date: Thu, 10 Apr 2025 15:41:12 -0500 Subject: [PATCH] Update naming for consistency --- .../two-factor-auth.component.spec.ts | 15 ++++++++------ .../two-factor-auth.component.ts | 20 +++++++++---------- .../two-factor-auth-cache.service.ts | 10 +++++----- 3 files changed, 24 insertions(+), 21 deletions(-) diff --git a/libs/auth/src/angular/two-factor-auth/two-factor-auth.component.spec.ts b/libs/auth/src/angular/two-factor-auth/two-factor-auth.component.spec.ts index beae2478fd5..fc9d5b9a110 100644 --- a/libs/auth/src/angular/two-factor-auth/two-factor-auth.component.spec.ts +++ b/libs/auth/src/angular/two-factor-auth/two-factor-auth.component.spec.ts @@ -34,7 +34,7 @@ import { FakeAccountService, mockAccountServiceWith } from "@bitwarden/common/sp import { UserId } from "@bitwarden/common/types/guid"; import { DialogService, ToastService } from "@bitwarden/components"; -import { TwoFactorAuthCacheService } from "../../common/services/auth-request/two-factor-auth-cache.service"; +import { TwoFactorAuthComponentCacheService } from "../../common/services/auth-request/two-factor-auth-cache.service"; import { AnonLayoutWrapperDataService } from "../anon-layout/anon-layout-wrapper-data.service"; import { TwoFactorAuthComponentService } from "./two-factor-auth-component.service"; @@ -71,7 +71,7 @@ describe("TwoFactorAuthComponent", () => { let anonLayoutWrapperDataService: MockProxy; let mockEnvService: MockProxy; let mockLoginSuccessHandlerService: MockProxy; - let mockTwoFactorAuthCacheService: MockProxy; + let mockTwoFactorAuthCompCacheService: MockProxy; let mockUserDecryptionOpts: { noMasterPassword: UserDecryptionOptions; @@ -112,9 +112,9 @@ describe("TwoFactorAuthComponent", () => { anonLayoutWrapperDataService = mock(); - mockTwoFactorAuthCacheService = mock(); - mockTwoFactorAuthCacheService.getCachedTwoFactorAuth.mockReturnValue(null); - mockTwoFactorAuthCacheService.init.mockResolvedValue(); + mockTwoFactorAuthCompCacheService = mock(); + mockTwoFactorAuthCompCacheService.getCachedData.mockReturnValue(null); + mockTwoFactorAuthCompCacheService.init.mockResolvedValue(); mockUserDecryptionOpts = { noMasterPassword: new UserDecryptionOptions({ @@ -200,7 +200,10 @@ describe("TwoFactorAuthComponent", () => { { provide: EnvironmentService, useValue: mockEnvService }, { provide: AnonLayoutWrapperDataService, useValue: anonLayoutWrapperDataService }, { provide: LoginSuccessHandlerService, useValue: mockLoginSuccessHandlerService }, - { provide: TwoFactorAuthCacheService, useValue: mockTwoFactorAuthCacheService }, + { + provide: TwoFactorAuthComponentCacheService, + useValue: mockTwoFactorAuthCompCacheService, + }, ], }); diff --git a/libs/auth/src/angular/two-factor-auth/two-factor-auth.component.ts b/libs/auth/src/angular/two-factor-auth/two-factor-auth.component.ts index 5af56654dbd..54899104bb2 100644 --- a/libs/auth/src/angular/two-factor-auth/two-factor-auth.component.ts +++ b/libs/auth/src/angular/two-factor-auth/two-factor-auth.component.ts @@ -46,7 +46,7 @@ import { ToastService, } from "@bitwarden/components"; -import { TwoFactorAuthCacheService } from "../../common/services/auth-request/two-factor-auth-cache.service"; +import { TwoFactorAuthComponentCacheService } from "../../common/services/auth-request/two-factor-auth-cache.service"; import { AnonLayoutWrapperDataService } from "../anon-layout/anon-layout-wrapper-data.service"; import { TwoFactorAuthAuthenticatorIcon, @@ -103,7 +103,7 @@ interface TwoFactorCacheData { ], providers: [ { - provide: TwoFactorAuthCacheService, + provide: TwoFactorAuthComponentCacheService, }, ], }) @@ -180,7 +180,7 @@ export class TwoFactorAuthComponent implements OnInit, OnDestroy { private anonLayoutWrapperDataService: AnonLayoutWrapperDataService, private environmentService: EnvironmentService, private loginSuccessHandlerService: LoginSuccessHandlerService, - private twoFactorCacheService: TwoFactorAuthCacheService, + private twoFactorCacheService: TwoFactorAuthComponentCacheService, ) {} async ngOnInit() { @@ -194,7 +194,7 @@ export class TwoFactorAuthComponent implements OnInit, OnDestroy { // Load persisted form data if available let loadedCachedProviderType = false; - const persistedData = this.twoFactorCacheService.getCachedTwoFactorAuth(); + const persistedData = this.twoFactorCacheService.getCachedData(); if (persistedData) { if (persistedData.token) { this.form.patchValue({ token: persistedData.token }); @@ -233,9 +233,9 @@ export class TwoFactorAuthComponent implements OnInit, OnDestroy { */ async saveFormDataWithPartialData(data: Partial) { // Get current cached data - const currentData = this.twoFactorCacheService.getCachedTwoFactorAuth(); + const currentData = this.twoFactorCacheService.getCachedData(); - this.twoFactorCacheService.cacheTwoFactorAuth({ + this.twoFactorCacheService.cacheData({ token: data?.token ?? currentData?.token ?? "", remember: data?.remember ?? currentData?.remember ?? false, selectedProviderType: @@ -347,7 +347,7 @@ export class TwoFactorAuthComponent implements OnInit, OnDestroy { const rememberValue = remember ?? this.rememberFormControl.value ?? false; // Persist form data before submitting - this.twoFactorCacheService.cacheTwoFactorAuth({ + this.twoFactorCacheService.cacheData({ token: tokenValue, remember: rememberValue, selectedProviderType: this.selectedProviderType, @@ -375,7 +375,7 @@ export class TwoFactorAuthComponent implements OnInit, OnDestroy { async selectOtherTwoFactorMethod() { // Persist current form data before navigating to another method - this.twoFactorCacheService.cacheTwoFactorAuth({ + this.twoFactorCacheService.cacheData({ token: "", remember: false, selectedProviderType: this.selectedProviderType, @@ -396,7 +396,7 @@ export class TwoFactorAuthComponent implements OnInit, OnDestroy { await this.setAnonLayoutDataByTwoFactorProviderType(); // Update the persisted provider type when a new one is chosen - this.twoFactorCacheService.cacheTwoFactorAuth({ + this.twoFactorCacheService.cacheData({ token: "", remember: false, selectedProviderType: response.type, @@ -481,7 +481,7 @@ export class TwoFactorAuthComponent implements OnInit, OnDestroy { private async handleAuthResult(authResult: AuthResult) { // Clear form cache - this.twoFactorCacheService.clearCachedTwoFactorAuth(); + this.twoFactorCacheService.clearCachedData(); if (await this.handleMigrateEncryptionKey(authResult)) { return; // stop login process diff --git a/libs/auth/src/common/services/auth-request/two-factor-auth-cache.service.ts b/libs/auth/src/common/services/auth-request/two-factor-auth-cache.service.ts index 70a03787874..39cee4c06f3 100644 --- a/libs/auth/src/common/services/auth-request/two-factor-auth-cache.service.ts +++ b/libs/auth/src/common/services/auth-request/two-factor-auth-cache.service.ts @@ -30,13 +30,13 @@ export interface TwoFactorAuthData { } /** - * This is a cache service used for the login via auth request component. + * This is a cache service used for the two factor auth component. * * There is sensitive information stored temporarily here. Cache will be cleared * after 2 minutes. */ @Injectable() -export class TwoFactorAuthCacheService { +export class TwoFactorAuthComponentCacheService { private viewCacheService: ViewCacheService = inject(ViewCacheService); private configService: ConfigService = inject(ConfigService); @@ -67,7 +67,7 @@ export class TwoFactorAuthCacheService { /** * Update the cache with the new TwoFactorAuthData. */ - cacheTwoFactorAuth(data: TwoFactorAuthData): void { + cacheData(data: TwoFactorAuthData): void { if (!this.featureEnabled) { return; } @@ -83,7 +83,7 @@ export class TwoFactorAuthCacheService { /** * Clears the cached TwoFactorAuthData. */ - clearCachedTwoFactorAuth(): void { + clearCachedData(): void { if (!this.featureEnabled) { return; } @@ -94,7 +94,7 @@ export class TwoFactorAuthCacheService { /** * Returns the cached TwoFactorAuthData when available. */ - getCachedTwoFactorAuth(): TwoFactorAuthCache | null { + getCachedData(): TwoFactorAuthCache | null { if (!this.featureEnabled) { return null; }