[PM-6755] Fix password generation defaults on CLI (#8308)

* Fix minSpecial for pwd generation being set to 1 instead of zero

* Use less magic numbers

---------

Co-authored-by: Daniel James Smith <djsmith85@users.noreply.github.com>
This commit is contained in:
Daniel James Smith 2024-03-19 17:20:57 +01:00 committed by GitHub
parent 61b3759736
commit ea0035f658
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 19 additions and 7 deletions

View File

@ -1,6 +1,9 @@
import { StateService } from "@bitwarden/common/platform/abstractions/state.service";
import { DefaultPassphraseGenerationOptions } from "@bitwarden/common/tools/generator/passphrase";
import { PasswordGenerationServiceAbstraction } from "@bitwarden/common/tools/generator/password";
import {
DefaultPasswordGenerationOptions,
PasswordGenerationServiceAbstraction,
} from "@bitwarden/common/tools/generator/password";
import { PasswordGeneratorOptions } from "@bitwarden/common/tools/generator/password/password-generator-options";
import { Response } from "../models/response";
@ -64,7 +67,10 @@ class Options {
this.capitalize = CliUtils.convertBooleanOption(passedOptions?.capitalize);
this.includeNumber = CliUtils.convertBooleanOption(passedOptions?.includeNumber);
this.ambiguous = CliUtils.convertBooleanOption(passedOptions?.ambiguous);
this.length = CliUtils.convertNumberOption(passedOptions?.length, 14);
this.length = CliUtils.convertNumberOption(
passedOptions?.length,
DefaultPasswordGenerationOptions.length,
);
this.type = passedOptions?.passphrase ? "passphrase" : "password";
this.separator = CliUtils.convertStringOption(
passedOptions?.separator,
@ -74,8 +80,14 @@ class Options {
passedOptions?.words,
DefaultPassphraseGenerationOptions.numWords,
);
this.minNumber = CliUtils.convertNumberOption(passedOptions?.minNumber, 1);
this.minSpecial = CliUtils.convertNumberOption(passedOptions?.minSpecial, 1);
this.minNumber = CliUtils.convertNumberOption(
passedOptions?.minNumber,
DefaultPasswordGenerationOptions.minNumber,
);
this.minSpecial = CliUtils.convertNumberOption(
passedOptions?.minSpecial,
DefaultPasswordGenerationOptions.minSpecial,
);
if (!this.uppercase && !this.lowercase && !this.special && !this.number) {
this.lowercase = true;

View File

@ -78,6 +78,6 @@ export const DefaultPasswordGenerationOptions: Partial<PasswordGenerationOptions
lowercase: true,
number: true,
minNumber: 1,
special: true,
minSpecial: 1,
special: false,
minSpecial: 0,
});

View File

@ -23,7 +23,7 @@ const DefaultOptions: PasswordGeneratorOptions = {
lowercase: true,
minLowercase: 0,
special: false,
minSpecial: 1,
minSpecial: 0,
type: "password",
numWords: 3,
wordSeparator: "-",