[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:
parent
61b3759736
commit
ea0035f658
|
@ -1,6 +1,9 @@
|
||||||
import { StateService } from "@bitwarden/common/platform/abstractions/state.service";
|
import { StateService } from "@bitwarden/common/platform/abstractions/state.service";
|
||||||
import { DefaultPassphraseGenerationOptions } from "@bitwarden/common/tools/generator/passphrase";
|
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 { PasswordGeneratorOptions } from "@bitwarden/common/tools/generator/password/password-generator-options";
|
||||||
|
|
||||||
import { Response } from "../models/response";
|
import { Response } from "../models/response";
|
||||||
|
@ -64,7 +67,10 @@ class Options {
|
||||||
this.capitalize = CliUtils.convertBooleanOption(passedOptions?.capitalize);
|
this.capitalize = CliUtils.convertBooleanOption(passedOptions?.capitalize);
|
||||||
this.includeNumber = CliUtils.convertBooleanOption(passedOptions?.includeNumber);
|
this.includeNumber = CliUtils.convertBooleanOption(passedOptions?.includeNumber);
|
||||||
this.ambiguous = CliUtils.convertBooleanOption(passedOptions?.ambiguous);
|
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.type = passedOptions?.passphrase ? "passphrase" : "password";
|
||||||
this.separator = CliUtils.convertStringOption(
|
this.separator = CliUtils.convertStringOption(
|
||||||
passedOptions?.separator,
|
passedOptions?.separator,
|
||||||
|
@ -74,8 +80,14 @@ class Options {
|
||||||
passedOptions?.words,
|
passedOptions?.words,
|
||||||
DefaultPassphraseGenerationOptions.numWords,
|
DefaultPassphraseGenerationOptions.numWords,
|
||||||
);
|
);
|
||||||
this.minNumber = CliUtils.convertNumberOption(passedOptions?.minNumber, 1);
|
this.minNumber = CliUtils.convertNumberOption(
|
||||||
this.minSpecial = CliUtils.convertNumberOption(passedOptions?.minSpecial, 1);
|
passedOptions?.minNumber,
|
||||||
|
DefaultPasswordGenerationOptions.minNumber,
|
||||||
|
);
|
||||||
|
this.minSpecial = CliUtils.convertNumberOption(
|
||||||
|
passedOptions?.minSpecial,
|
||||||
|
DefaultPasswordGenerationOptions.minSpecial,
|
||||||
|
);
|
||||||
|
|
||||||
if (!this.uppercase && !this.lowercase && !this.special && !this.number) {
|
if (!this.uppercase && !this.lowercase && !this.special && !this.number) {
|
||||||
this.lowercase = true;
|
this.lowercase = true;
|
||||||
|
|
|
@ -78,6 +78,6 @@ export const DefaultPasswordGenerationOptions: Partial<PasswordGenerationOptions
|
||||||
lowercase: true,
|
lowercase: true,
|
||||||
number: true,
|
number: true,
|
||||||
minNumber: 1,
|
minNumber: 1,
|
||||||
special: true,
|
special: false,
|
||||||
minSpecial: 1,
|
minSpecial: 0,
|
||||||
});
|
});
|
||||||
|
|
|
@ -23,7 +23,7 @@ const DefaultOptions: PasswordGeneratorOptions = {
|
||||||
lowercase: true,
|
lowercase: true,
|
||||||
minLowercase: 0,
|
minLowercase: 0,
|
||||||
special: false,
|
special: false,
|
||||||
minSpecial: 1,
|
minSpecial: 0,
|
||||||
type: "password",
|
type: "password",
|
||||||
numWords: 3,
|
numWords: 3,
|
||||||
wordSeparator: "-",
|
wordSeparator: "-",
|
||||||
|
|
Loading…
Reference in New Issue