1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-25 20:53:22 +00:00

[PM-2367] [BEEEP]: Extract password strength from password-generation-service (#5502)

* Extract passwordStrength from passwordGenerationService

Extract passwordStrength from password-generation.service.ts
Create new password-strength.service.ts
Create new password-strength.service.abstraction.ts
Register new password-strength service
Fix usages in libs

* Fix usage in web

* Fix usage in desktop

* Fix usage in CLI

* Fix usage in browser

Move password-generation-factory to tools

* Fix tests

* Change dependency in jslib-services.module
This commit is contained in:
Daniel James Smith
2023-06-13 23:22:25 +02:00
committed by GitHub
parent 22caae116c
commit 72a5ba455c
28 changed files with 224 additions and 111 deletions

View File

@@ -5,10 +5,6 @@ import {
policyServiceFactory,
PolicyServiceInitOptions,
} from "../../../admin-console/background/service-factories/policy-service.factory";
import {
passwordGenerationServiceFactory,
PasswordGenerationServiceInitOptions,
} from "../../../background/service-factories/password-generation-service.factory";
import {
apiServiceFactory,
ApiServiceInitOptions,
@@ -51,6 +47,10 @@ import {
stateServiceFactory,
StateServiceInitOptions,
} from "../../../platform/background/service-factories/state-service.factory";
import {
passwordStrengthServiceFactory,
PasswordStrengthServiceInitOptions,
} from "../../../tools/background/service_factories/password-strength-service.factory";
import {
keyConnectorServiceFactory,
@@ -75,7 +75,7 @@ export type AuthServiceInitOptions = AuthServiceFactoyOptions &
I18nServiceInitOptions &
EncryptServiceInitOptions &
PolicyServiceInitOptions &
PasswordGenerationServiceInitOptions;
PasswordStrengthServiceInitOptions;
export function authServiceFactory(
cache: { authService?: AbstractAuthService } & CachedServices,
@@ -100,7 +100,7 @@ export function authServiceFactory(
await twoFactorServiceFactory(cache, opts),
await i18nServiceFactory(cache, opts),
await encryptServiceFactory(cache, opts),
await passwordGenerationServiceFactory(cache, opts),
await passwordStrengthServiceFactory(cache, opts),
await policyServiceFactory(cache, opts)
)
);

View File

@@ -18,7 +18,7 @@ import { LogService } from "@bitwarden/common/platform/abstractions/log.service"
import { MessagingService } from "@bitwarden/common/platform/abstractions/messaging.service";
import { PlatformUtilsService } from "@bitwarden/common/platform/abstractions/platform-utils.service";
import { StateService } from "@bitwarden/common/platform/abstractions/state.service";
import { PasswordGenerationServiceAbstraction } from "@bitwarden/common/tools/generator/password";
import { PasswordStrengthServiceAbstraction } from "@bitwarden/common/tools/password-strength";
import { BiometricErrors, BiometricErrorTypes } from "../../models/biometricErrors";
@@ -48,7 +48,7 @@ export class LockComponent extends BaseLockComponent {
ngZone: NgZone,
policyApiService: PolicyApiServiceAbstraction,
policyService: InternalPolicyService,
passwordGenerationService: PasswordGenerationServiceAbstraction,
passwordStrengthService: PasswordStrengthServiceAbstraction,
private authService: AuthService,
dialogService: DialogServiceAbstraction
) {
@@ -68,7 +68,7 @@ export class LockComponent extends BaseLockComponent {
ngZone,
policyApiService,
policyService,
passwordGenerationService,
passwordStrengthService,
dialogService
);
this.successRoute = "/tabs/current";

View File

@@ -16,11 +16,11 @@ import {
import { totpServiceFactory } from "../../auth/background/service-factories/totp-service.factory";
import LockedVaultPendingNotificationsItem from "../../background/models/lockedVaultPendingNotificationsItem";
import { eventCollectionServiceFactory } from "../../background/service-factories/event-collection-service.factory";
import { passwordGenerationServiceFactory } from "../../background/service-factories/password-generation-service.factory";
import { Account } from "../../models/account";
import { CachedServices } from "../../platform/background/service-factories/factory-options";
import { stateServiceFactory } from "../../platform/background/service-factories/state-service.factory";
import { BrowserApi } from "../../platform/browser/browser-api";
import { passwordGenerationServiceFactory } from "../../tools/background/service_factories/password-generation-service.factory";
import {
cipherServiceFactory,
CipherServiceInitOptions,

View File

@@ -75,6 +75,10 @@ import {
UsernameGenerationService,
UsernameGenerationServiceAbstraction,
} from "@bitwarden/common/tools/generator/username";
import {
PasswordStrengthService,
PasswordStrengthServiceAbstraction,
} from "@bitwarden/common/tools/password-strength";
import { SendApiService } from "@bitwarden/common/tools/send/services/send-api.service";
import { SendApiService as SendApiServiceAbstraction } from "@bitwarden/common/tools/send/services/send-api.service.abstraction";
import { InternalSendService as InternalSendServiceAbstraction } from "@bitwarden/common/tools/send/services/send.service.abstraction";
@@ -155,6 +159,7 @@ export default class MainBackground {
vaultTimeoutSettingsService: VaultTimeoutSettingsServiceAbstraction;
syncService: SyncServiceAbstraction;
passwordGenerationService: PasswordGenerationServiceAbstraction;
passwordStrengthService: PasswordStrengthServiceAbstraction;
totpService: TotpServiceAbstraction;
autofillService: AutofillServiceAbstraction;
containerService: ContainerService;
@@ -360,6 +365,9 @@ export default class MainBackground {
this.collectionService,
this.policyService
);
this.passwordStrengthService = new PasswordStrengthService();
this.passwordGenerationService = new PasswordGenerationService(
this.cryptoService,
this.policyService,
@@ -391,7 +399,7 @@ export default class MainBackground {
this.twoFactorService,
this.i18nService,
this.encryptService,
this.passwordGenerationService,
this.passwordStrengthService,
this.policyService
);

View File

@@ -6,12 +6,12 @@ import { authServiceFactory } from "../../auth/background/service-factories/auth
import { autofillServiceFactory } from "../../autofill/background/service_factories/autofill-service.factory";
import { GeneratePasswordToClipboardCommand } from "../../autofill/clipboard";
import { AutofillTabCommand } from "../../autofill/commands/autofill-tab-command";
import {
PasswordGenerationServiceInitOptions,
passwordGenerationServiceFactory,
} from "../../background/service-factories/password-generation-service.factory";
import { Account } from "../../models/account";
import { stateServiceFactory } from "../../platform/background/service-factories/state-service.factory";
import {
passwordGenerationServiceFactory,
PasswordGenerationServiceInitOptions,
} from "../../tools/background/service_factories/password-generation-service.factory";
import { CachedServices } from "../background/service-factories/factory-options";
import { logServiceFactory } from "../background/service-factories/log-service.factory";
import { BrowserApi } from "../browser/browser-api";

View File

@@ -63,6 +63,7 @@ import { ContainerService } from "@bitwarden/common/platform/services/container.
import { SearchService } from "@bitwarden/common/services/search.service";
import { PasswordGenerationServiceAbstraction } from "@bitwarden/common/tools/generator/password";
import { UsernameGenerationServiceAbstraction } from "@bitwarden/common/tools/generator/username";
import { PasswordStrengthServiceAbstraction } from "@bitwarden/common/tools/password-strength";
import { SendApiService } from "@bitwarden/common/tools/send/services/send-api.service";
import { SendApiService as SendApiServiceAbstraction } from "@bitwarden/common/tools/send/services/send-api.service.abstraction";
import {
@@ -287,6 +288,11 @@ function getBgService<T>(service: keyof MainBackground) {
useFactory: getBgService<PlatformUtilsService>("platformUtilsService"),
deps: [],
},
{
provide: PasswordStrengthServiceAbstraction,
useFactory: getBgService<PasswordStrengthServiceAbstraction>("passwordStrengthService"),
deps: [],
},
{
provide: PasswordGenerationServiceAbstraction,
useFactory: getBgService<PasswordGenerationServiceAbstraction>("passwordGenerationService"),

View File

@@ -0,0 +1,46 @@
import {
PasswordGenerationService,
PasswordGenerationServiceAbstraction,
} from "@bitwarden/common/tools/generator/password";
import {
policyServiceFactory,
PolicyServiceInitOptions,
} from "../../../admin-console/background/service-factories/policy-service.factory";
import {
CryptoServiceInitOptions,
cryptoServiceFactory,
} from "../../../platform/background/service-factories/crypto-service.factory";
import {
CachedServices,
factory,
FactoryOptions,
} from "../../../platform/background/service-factories/factory-options";
import {
stateServiceFactory,
StateServiceInitOptions,
} from "../../../platform/background/service-factories/state-service.factory";
type PasswordGenerationServiceFactoryOptions = FactoryOptions;
export type PasswordGenerationServiceInitOptions = PasswordGenerationServiceFactoryOptions &
CryptoServiceInitOptions &
PolicyServiceInitOptions &
StateServiceInitOptions;
export function passwordGenerationServiceFactory(
cache: { passwordGenerationService?: PasswordGenerationServiceAbstraction } & CachedServices,
opts: PasswordGenerationServiceInitOptions
): Promise<PasswordGenerationServiceAbstraction> {
return factory(
cache,
"passwordGenerationService",
opts,
async () =>
new PasswordGenerationService(
await cryptoServiceFactory(cache, opts),
await policyServiceFactory(cache, opts),
await stateServiceFactory(cache, opts)
)
);
}

View File

@@ -0,0 +1,23 @@
import {
PasswordStrengthService,
PasswordStrengthServiceAbstraction,
} from "@bitwarden/common/tools/password-strength";
import {
CachedServices,
factory,
FactoryOptions,
} from "../../../platform/background/service-factories/factory-options";
type PasswordStrengthServiceFactoryOptions = FactoryOptions;
export type PasswordStrengthServiceInitOptions = PasswordStrengthServiceFactoryOptions;
export function passwordStrengthServiceFactory(
cache: {
passwordStrengthService?: PasswordStrengthServiceAbstraction;
} & CachedServices,
opts: PasswordStrengthServiceInitOptions
): Promise<PasswordStrengthServiceAbstraction> {
return factory(cache, "passwordStrengthService", opts, async () => new PasswordStrengthService());
}