mirror of
https://github.com/bitwarden/clients.git
synced 2026-07-04 21:05:54 +08:00
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:
parent
08f6ab58ee
commit
ecbab67b8b
@ -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", () => {
|
||||
|
||||
@ -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))
|
||||
|
||||
Loading…
Reference in New Issue
Block a user