mirror of
https://github.com/bitwarden/browser.git
synced 2024-12-18 15:47:57 +01:00
[PM-14198] zero minimums when the character category is disabled (#11906)
This commit is contained in:
parent
e95af8269f
commit
b2811e07ce
@ -2,6 +2,7 @@ import { Constraint } from "@bitwarden/common/tools/types";
|
||||
|
||||
import { sum } from "../util";
|
||||
|
||||
const Zero: Constraint<number> = { min: 0, max: 0 };
|
||||
const AtLeastOne: Constraint<number> = { min: 1 };
|
||||
const RequiresTrue: Constraint<boolean> = { requiredValue: true };
|
||||
|
||||
@ -159,6 +160,7 @@ export {
|
||||
enforceConstant,
|
||||
readonlyTrueWhen,
|
||||
fitLength,
|
||||
Zero,
|
||||
AtLeastOne,
|
||||
RequiresTrue,
|
||||
};
|
||||
|
@ -1,6 +1,6 @@
|
||||
import { DefaultPasswordBoundaries, DefaultPasswordGenerationOptions, Policies } from "../data";
|
||||
|
||||
import { AtLeastOne } from "./constraints";
|
||||
import { AtLeastOne, Zero } from "./constraints";
|
||||
import { DynamicPasswordPolicyConstraints } from "./dynamic-password-policy-constraints";
|
||||
|
||||
describe("DynamicPasswordPolicyConstraints", () => {
|
||||
@ -207,7 +207,7 @@ describe("DynamicPasswordPolicyConstraints", () => {
|
||||
expect(calibrated.constraints.minNumber).toEqual(dynamic.constraints.minNumber);
|
||||
});
|
||||
|
||||
it("disables the minNumber constraint when the state's number flag is false", () => {
|
||||
it("outputs the zero constraint when the state's number flag is false", () => {
|
||||
const dynamic = new DynamicPasswordPolicyConstraints(Policies.Password.disabledValue);
|
||||
const state = {
|
||||
...DefaultPasswordGenerationOptions,
|
||||
@ -216,7 +216,7 @@ describe("DynamicPasswordPolicyConstraints", () => {
|
||||
|
||||
const calibrated = dynamic.calibrate(state);
|
||||
|
||||
expect(calibrated.constraints.minNumber).toBeUndefined();
|
||||
expect(calibrated.constraints.minNumber).toEqual(Zero);
|
||||
});
|
||||
|
||||
it("outputs the minSpecial constraint when the state's special flag is true", () => {
|
||||
@ -231,7 +231,7 @@ describe("DynamicPasswordPolicyConstraints", () => {
|
||||
expect(calibrated.constraints.minSpecial).toEqual(dynamic.constraints.minSpecial);
|
||||
});
|
||||
|
||||
it("disables the minSpecial constraint when the state's special flag is false", () => {
|
||||
it("outputs the zero constraint when the state's special flag is false", () => {
|
||||
const dynamic = new DynamicPasswordPolicyConstraints(Policies.Password.disabledValue);
|
||||
const state = {
|
||||
...DefaultPasswordGenerationOptions,
|
||||
@ -240,23 +240,7 @@ describe("DynamicPasswordPolicyConstraints", () => {
|
||||
|
||||
const calibrated = dynamic.calibrate(state);
|
||||
|
||||
expect(calibrated.constraints.minSpecial).toBeUndefined();
|
||||
});
|
||||
|
||||
it("copies the minimum length constraint", () => {
|
||||
const dynamic = new DynamicPasswordPolicyConstraints(Policies.Password.disabledValue);
|
||||
|
||||
const calibrated = dynamic.calibrate(DefaultPasswordGenerationOptions);
|
||||
|
||||
expect(calibrated.constraints.minSpecial).toBeUndefined();
|
||||
});
|
||||
|
||||
it("overrides the minimum length constraint when it is less than the sum of the state's minimums", () => {
|
||||
const dynamic = new DynamicPasswordPolicyConstraints(Policies.Password.disabledValue);
|
||||
|
||||
const calibrated = dynamic.calibrate(DefaultPasswordGenerationOptions);
|
||||
|
||||
expect(calibrated.constraints.minSpecial).toBeUndefined();
|
||||
expect(calibrated.constraints.minSpecial).toEqual(Zero);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@ -7,7 +7,7 @@ import {
|
||||
import { DefaultPasswordBoundaries } from "../data";
|
||||
import { PasswordGeneratorPolicy, PasswordGeneratorSettings } from "../types";
|
||||
|
||||
import { atLeast, atLeastSum, maybe, readonlyTrueWhen, AtLeastOne } from "./constraints";
|
||||
import { atLeast, atLeastSum, maybe, readonlyTrueWhen, AtLeastOne, Zero } from "./constraints";
|
||||
import { PasswordPolicyConstraints } from "./password-policy-constraints";
|
||||
|
||||
/** Creates state constraints by blending policy and password settings. */
|
||||
@ -68,8 +68,8 @@ export class DynamicPasswordPolicyConstraints
|
||||
...this.constraints,
|
||||
minLowercase: maybe<number>(lowercase, this.constraints.minLowercase ?? AtLeastOne),
|
||||
minUppercase: maybe<number>(uppercase, this.constraints.minUppercase ?? AtLeastOne),
|
||||
minNumber: maybe<number>(number, this.constraints.minNumber),
|
||||
minSpecial: maybe<number>(special, this.constraints.minSpecial),
|
||||
minNumber: maybe<number>(number, this.constraints.minNumber) ?? Zero,
|
||||
minSpecial: maybe<number>(special, this.constraints.minSpecial) ?? Zero,
|
||||
};
|
||||
|
||||
// lower bound of length must always at least fit its sub-lengths
|
||||
|
Loading…
Reference in New Issue
Block a user