Enhance MasterPassword policy handling in tests and service (#19350)

* Add tests to verify behavior when organizations do not use policies and when users are exempt as owners.
* Update service logic to correctly handle policy retrieval based on user type and organization settings.
This commit is contained in:
Jared 2026-03-09 11:52:23 -04:00 committed by GitHub
parent 08f6ab58ee
commit ecbab67b8b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 29 additions and 1 deletions

View File

@ -188,6 +188,32 @@ describe("PolicyService", () => {
enforceOnLogin: false,
});
});
it("returns undefined when org does not use policies", async () => {
// org3 has usePolicies=false (simulates a Teams org that was downgraded from Enterprise)
singleUserState.nextState(
arrayToRecord([
policyData("1", "org3", PolicyType.MasterPassword, true, { minLength: 10 }),
]),
);
const result = await firstValueFrom(policyService.masterPasswordPolicyOptions$(userId));
expect(result).toBeUndefined();
});
it("returns undefined when user is an owner (exempt from policy)", async () => {
// org2 has OrganizationUserType.Owner; owners are exempt from MasterPassword policy
singleUserState.nextState(
arrayToRecord([
policyData("1", "org2", PolicyType.MasterPassword, true, { minLength: 10 }),
]),
);
const result = await firstValueFrom(policyService.masterPasswordPolicyOptions$(userId));
expect(result).toBeUndefined();
});
});
describe("evaluateMasterPassword", () => {

View File

@ -88,7 +88,9 @@ export class DefaultPolicyService implements PolicyService {
userId: UserId,
policies?: Policy[],
): Observable<MasterPasswordPolicyOptions | undefined> {
const policies$ = policies ? of(policies) : this.policies$(userId);
const policies$ = policies
? of(policies)
: this.policiesByType$(PolicyType.MasterPassword, userId);
return policies$.pipe(
map((obsPolicies) => {
// TODO ([PM-23777]): replace with this.combinePoliciesIntoMasterPasswordPolicyOptions(obsPolicies))