mirror of
https://github.com/bitwarden/browser
synced 2025-12-22 11:13:46 +00:00
[PM-6556] reintroduce policy reduction for multi-org accounts (#8409)
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import { mock } from "jest-mock-extended";
|
||||
import { of, firstValueFrom } from "rxjs";
|
||||
|
||||
import { PolicyType } from "../../../admin-console/enums";
|
||||
// FIXME: use index.ts imports once policy abstractions and models
|
||||
@@ -12,39 +13,26 @@ import { SUBADDRESS_SETTINGS } from "../key-definitions";
|
||||
import { SubaddressGeneratorStrategy, UsernameGenerationServiceAbstraction } from ".";
|
||||
|
||||
const SomeUser = "some user" as UserId;
|
||||
const SomePolicy = mock<Policy>({
|
||||
type: PolicyType.PasswordGenerator,
|
||||
data: {
|
||||
minLength: 10,
|
||||
},
|
||||
});
|
||||
|
||||
describe("Email subaddress list generation strategy", () => {
|
||||
describe("evaluator()", () => {
|
||||
it("should throw if the policy type is incorrect", () => {
|
||||
const strategy = new SubaddressGeneratorStrategy(null, null);
|
||||
const policy = mock<Policy>({
|
||||
type: PolicyType.DisableSend,
|
||||
});
|
||||
describe("toEvaluator()", () => {
|
||||
it.each([[[]], [null], [undefined], [[SomePolicy]], [[SomePolicy, SomePolicy]]])(
|
||||
"should map any input (= %p) to the default policy evaluator",
|
||||
async (policies) => {
|
||||
const strategy = new SubaddressGeneratorStrategy(null, null);
|
||||
|
||||
expect(() => strategy.evaluator(policy)).toThrow(new RegExp("Mismatched policy type\\. .+"));
|
||||
});
|
||||
const evaluator$ = of(policies).pipe(strategy.toEvaluator());
|
||||
const evaluator = await firstValueFrom(evaluator$);
|
||||
|
||||
it("should map to the policy evaluator", () => {
|
||||
const strategy = new SubaddressGeneratorStrategy(null, null);
|
||||
const policy = mock<Policy>({
|
||||
type: PolicyType.PasswordGenerator,
|
||||
data: {
|
||||
minLength: 10,
|
||||
},
|
||||
});
|
||||
|
||||
const evaluator = strategy.evaluator(policy);
|
||||
|
||||
expect(evaluator).toBeInstanceOf(DefaultPolicyEvaluator);
|
||||
expect(evaluator.policy).toMatchObject({});
|
||||
});
|
||||
|
||||
it("should map `null` to a default policy evaluator", () => {
|
||||
const strategy = new SubaddressGeneratorStrategy(null, null);
|
||||
const evaluator = strategy.evaluator(null);
|
||||
|
||||
expect(evaluator).toBeInstanceOf(DefaultPolicyEvaluator);
|
||||
});
|
||||
expect(evaluator).toBeInstanceOf(DefaultPolicyEvaluator);
|
||||
},
|
||||
);
|
||||
});
|
||||
|
||||
describe("durableState", () => {
|
||||
|
||||
Reference in New Issue
Block a user