From ff98f4ca6b84db25326ad2b8108324d4fd491f5d Mon Sep 17 00:00:00 2001 From: Thomas Rittson <31796059+eliykat@users.noreply.github.com> Date: Tue, 15 Feb 2022 00:29:44 +1000 Subject: [PATCH] Fix error when using password generator not logged in (#481) * Do not fetch password policy if not logged in * Update deps --- src/commands/generate.command.ts | 15 +++++++++++---- src/commands/serve.command.ts | 5 ++++- src/program.ts | 5 ++++- 3 files changed, 19 insertions(+), 6 deletions(-) diff --git a/src/commands/generate.command.ts b/src/commands/generate.command.ts index 0f08b64a99..89cf2ce9c6 100644 --- a/src/commands/generate.command.ts +++ b/src/commands/generate.command.ts @@ -1,4 +1,5 @@ import { PasswordGenerationService } from "jslib-common/abstractions/passwordGeneration.service"; +import { StateService } from "jslib-common/abstractions/state.service"; import { Response } from "jslib-node/cli/models/response"; import { StringResponse } from "jslib-node/cli/models/response/stringResponse"; @@ -6,7 +7,10 @@ import { StringResponse } from "jslib-node/cli/models/response/stringResponse"; import { CliUtils } from "../utils"; export class GenerateCommand { - constructor(private passwordGenerationService: PasswordGenerationService) {} + constructor( + private passwordGenerationService: PasswordGenerationService, + private stateService: StateService + ) {} async run(cmdOptions: Record): Promise { const normalizedOptions = new Options(cmdOptions); @@ -22,9 +26,12 @@ export class GenerateCommand { capitalize: normalizedOptions.capitalize, includeNumber: normalizedOptions.includeNumber, }; - const enforcedOptions = - await this.passwordGenerationService.enforcePasswordGeneratorPoliciesOnOptions(options); - const password = await this.passwordGenerationService.generatePassword(enforcedOptions[0]); + + const enforcedOptions = (await this.stateService.getIsAuthenticated()) + ? (await this.passwordGenerationService.enforcePasswordGeneratorPoliciesOnOptions(options))[0] + : options; + + const password = await this.passwordGenerationService.generatePassword(enforcedOptions); const res = new StringResponse(password); return Response.success(res); } diff --git a/src/commands/serve.command.ts b/src/commands/serve.command.ts index 9d692aab37..93c4e31f75 100644 --- a/src/commands/serve.command.ts +++ b/src/commands/serve.command.ts @@ -84,7 +84,10 @@ export class ServeCommand { this.main.cryptoService, this.main.apiService ); - this.generateCommand = new GenerateCommand(this.main.passwordGenerationService); + this.generateCommand = new GenerateCommand( + this.main.passwordGenerationService, + this.main.stateService + ); this.syncCommand = new SyncCommand(this.main.syncService); this.statusCommand = new StatusCommand( this.main.environmentService, diff --git a/src/program.ts b/src/program.ts index 1ff242723d..53d0ef5cb5 100644 --- a/src/program.ts +++ b/src/program.ts @@ -322,7 +322,10 @@ export class Program extends BaseProgram { writeLn("", true); }) .action(async (options) => { - const command = new GenerateCommand(this.main.passwordGenerationService); + const command = new GenerateCommand( + this.main.passwordGenerationService, + this.main.stateService + ); const response = await command.run(options); this.processResponse(response); });