1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-15 15:53:27 +00:00

[PM-15882] Remove unlock with PIN policy (#13352)

* Remove policy with PIN in Web Vault

* Remove policy with PIN in Browser Extension

* Remove policy with PIN in Desktop

* Remove policy with PIN in Desktop

* unit tests coverage

* unit tests coverage

* unit tests coverage

* private access method error

* private access method error

* private access method error

* PM-18498: Unlock Options Padding Off When PIN Is Removed

* PM-18498: Unlock Options Padding Off When PIN Is Removed
This commit is contained in:
Maciej Zieniuk
2025-02-21 22:16:13 +01:00
committed by GitHub
parent 3800610bb6
commit 78202e14ae
21 changed files with 747 additions and 26 deletions

View File

@@ -35,18 +35,6 @@ export abstract class BasePolicyComponent implements OnInit {
}
}
loadData() {
this.data.patchValue(this.policyResponse.data ?? {});
}
buildRequestData() {
if (this.data != null) {
return this.data.value;
}
return null;
}
buildRequest() {
const request = new PolicyRequest();
request.enabled = this.enabled.value;
@@ -55,4 +43,16 @@ export abstract class BasePolicyComponent implements OnInit {
return Promise.resolve(request);
}
protected loadData() {
this.data.patchValue(this.policyResponse.data ?? {});
}
protected buildRequestData() {
if (this.data != null) {
return this.data.value;
}
return null;
}
}

View File

@@ -10,3 +10,4 @@ export { SendOptionsPolicy } from "./send-options.component";
export { SingleOrgPolicy } from "./single-org.component";
export { TwoFactorAuthenticationPolicy } from "./two-factor-authentication.component";
export { PoliciesComponent } from "./policies.component";
export { RemoveUnlockWithPinPolicy } from "./remove-unlock-with-pin.component";

View File

@@ -8,6 +8,7 @@ import { PasswordGeneratorPolicyComponent } from "./password-generator.component
import { PersonalOwnershipPolicyComponent } from "./personal-ownership.component";
import { PoliciesComponent } from "./policies.component";
import { PolicyEditComponent } from "./policy-edit.component";
import { RemoveUnlockWithPinPolicyComponent } from "./remove-unlock-with-pin.component";
import { RequireSsoPolicyComponent } from "./require-sso.component";
import { ResetPasswordPolicyComponent } from "./reset-password.component";
import { SendOptionsPolicyComponent } from "./send-options.component";
@@ -28,6 +29,7 @@ import { TwoFactorAuthenticationPolicyComponent } from "./two-factor-authenticat
TwoFactorAuthenticationPolicyComponent,
PoliciesComponent,
PolicyEditComponent,
RemoveUnlockWithPinPolicyComponent,
],
exports: [
DisableSendPolicyComponent,
@@ -41,6 +43,7 @@ import { TwoFactorAuthenticationPolicyComponent } from "./two-factor-authenticat
TwoFactorAuthenticationPolicyComponent,
PoliciesComponent,
PolicyEditComponent,
RemoveUnlockWithPinPolicyComponent,
],
})
export class PoliciesModule {}

View File

@@ -0,0 +1,4 @@
<bit-form-control>
<input type="checkbox" id="enabled" bitCheckbox [formControl]="enabled" />
<bit-label>{{ "turnOn" | i18n }}</bit-label>
</bit-form-control>

View File

@@ -0,0 +1,110 @@
import { CommonModule } from "@angular/common";
import { NO_ERRORS_SCHEMA } from "@angular/core";
import { ComponentFixture, TestBed } from "@angular/core/testing";
import { ReactiveFormsModule } from "@angular/forms";
import { By } from "@angular/platform-browser";
import { mock } from "jest-mock-extended";
import { I18nPipe } from "@bitwarden/angular/platform/pipes/i18n.pipe";
import { PolicyType } from "@bitwarden/common/admin-console/enums";
import { PolicyResponse } from "@bitwarden/common/admin-console/models/response/policy.response";
import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service";
import {
RemoveUnlockWithPinPolicy,
RemoveUnlockWithPinPolicyComponent,
} from "./remove-unlock-with-pin.component";
describe("RemoveUnlockWithPinPolicy", () => {
const policy = new RemoveUnlockWithPinPolicy();
it("should have correct attributes", () => {
expect(policy.name).toEqual("removeUnlockWithPinPolicyTitle");
expect(policy.description).toEqual("removeUnlockWithPinPolicyDesc");
expect(policy.type).toEqual(PolicyType.RemoveUnlockWithPin);
expect(policy.component).toEqual(RemoveUnlockWithPinPolicyComponent);
});
});
describe("RemoveUnlockWithPinPolicyComponent", () => {
let component: RemoveUnlockWithPinPolicyComponent;
let fixture: ComponentFixture<RemoveUnlockWithPinPolicyComponent>;
const i18nService = mock<I18nService>();
beforeEach(async () => {
await TestBed.configureTestingModule({
imports: [CommonModule, ReactiveFormsModule],
declarations: [RemoveUnlockWithPinPolicyComponent, I18nPipe],
providers: [
{ provide: I18nService, useValue: mock<I18nService>() },
{ provide: I18nService, useValue: i18nService },
],
schemas: [NO_ERRORS_SCHEMA],
}).compileComponents();
fixture = TestBed.createComponent(RemoveUnlockWithPinPolicyComponent);
component = fixture.componentInstance;
});
it("input selected on load when policy enabled", async () => {
component.policyResponse = new PolicyResponse({
id: "policy1",
organizationId: "org1",
type: PolicyType.RemoveUnlockWithPin,
enabled: true,
});
component.ngOnInit();
fixture.detectChanges();
expect(component.enabled.value).toBe(true);
const inputElement = fixture.debugElement.query(By.css("input"));
expect(inputElement).not.toBeNull();
expect(inputElement.properties).toMatchObject({
id: "enabled",
type: "checkbox",
checked: true,
});
});
it("input not selected on load when policy disabled", async () => {
component.policyResponse = new PolicyResponse({
id: "policy1",
organizationId: "org1",
type: PolicyType.RemoveUnlockWithPin,
enabled: false,
});
component.ngOnInit();
fixture.detectChanges();
expect(component.enabled.value).toBe(false);
const inputElement = fixture.debugElement.query(By.css("input"));
expect(inputElement).not.toBeNull();
expect(inputElement.properties).toMatchObject({
id: "enabled",
type: "checkbox",
checked: false,
});
});
it("turn on message label", async () => {
component.policyResponse = new PolicyResponse({
id: "policy1",
organizationId: "org1",
type: PolicyType.RemoveUnlockWithPin,
enabled: false,
});
i18nService.t.mockReturnValue("Turn on");
component.ngOnInit();
fixture.detectChanges();
const bitLabelElement = fixture.debugElement.query(By.css("bit-label"));
expect(bitLabelElement).not.toBeNull();
const textNodes = bitLabelElement.childNodes
.filter((node) => node.nativeNode.nodeType === Node.TEXT_NODE)
.map((node) => node.nativeNode.wholeText?.trim());
expect(textNodes).toContain("Turn on");
});
});

View File

@@ -0,0 +1,18 @@
import { Component } from "@angular/core";
import { PolicyType } from "@bitwarden/common/admin-console/enums";
import { BasePolicy, BasePolicyComponent } from "./base-policy.component";
export class RemoveUnlockWithPinPolicy extends BasePolicy {
name = "removeUnlockWithPinPolicyTitle";
description = "removeUnlockWithPinPolicyDesc";
type = PolicyType.RemoveUnlockWithPin;
component = RemoveUnlockWithPinPolicyComponent;
}
@Component({
selector: "remove-unlock-with-pin",
templateUrl: "remove-unlock-with-pin.component.html",
})
export class RemoveUnlockWithPinPolicyComponent extends BasePolicyComponent {}

View File

@@ -45,6 +45,7 @@ import {
SendOptionsPolicy,
SingleOrgPolicy,
TwoFactorAuthenticationPolicy,
RemoveUnlockWithPinPolicy,
} from "./admin-console/organizations/policies";
const BroadcasterSubscriptionId = "AppComponent";
@@ -255,6 +256,7 @@ export class AppComponent implements OnDestroy, OnInit {
this.policyListService.addPolicies([
new TwoFactorAuthenticationPolicy(),
new MasterPasswordPolicy(),
new RemoveUnlockWithPinPolicy(),
new ResetPasswordPolicy(),
new PasswordGeneratorPolicy(),
new SingleOrgPolicy(),

View File

@@ -10455,5 +10455,11 @@
},
"assignedExceedsAvailable": {
"message": "Assigned seats exceed available seats."
},
"removeUnlockWithPinPolicyTitle": {
"message": "Remove Unlock with PIN"
},
"removeUnlockWithPinPolicyDesc": {
"message": "Do not allow members to unlock their account with a PIN."
}
}