1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-06 00:13:28 +00:00

[PM-21022] Remove fido2Credentials when cloning a cipher (#14573)

* remove fido2Credentials from cipherView when cloning a cipher

* add check for login on cloning cipher
This commit is contained in:
Nick Krantz
2025-05-02 10:11:29 -05:00
committed by GitHub
parent d9fee1d1ad
commit ebe3e98a1f
2 changed files with 41 additions and 2 deletions

View File

@@ -1,13 +1,17 @@
import { ChangeDetectorRef } from "@angular/core";
import { ComponentFixture, TestBed } from "@angular/core/testing";
import { ReactiveFormsModule } from "@angular/forms";
import { mock } from "jest-mock-extended";
import { ViewCacheService } from "@bitwarden/angular/platform/abstractions/view-cache.service";
import { ConfigService } from "@bitwarden/common/platform/abstractions/config/config.service";
import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service";
import { Cipher } from "@bitwarden/common/vault/models/domain/cipher";
import { CipherView } from "@bitwarden/common/vault/models/view/cipher.view";
import { Fido2CredentialView } from "@bitwarden/common/vault/models/view/fido2-credential.view";
import { ToastService } from "@bitwarden/components";
import { CipherFormConfig } from "../abstractions/cipher-form-config.service";
import { CipherFormService } from "../abstractions/cipher-form.service";
import { CipherFormCacheService } from "../services/default-cipher-form-cache.service";
@@ -17,20 +21,24 @@ describe("CipherFormComponent", () => {
let component: CipherFormComponent;
let fixture: ComponentFixture<CipherFormComponent>;
const decryptCipher = jest.fn().mockResolvedValue(new CipherView());
beforeEach(async () => {
decryptCipher.mockClear();
await TestBed.configureTestingModule({
imports: [CipherFormComponent, ReactiveFormsModule],
providers: [
{ provide: ChangeDetectorRef, useValue: {} },
{ provide: I18nService, useValue: { t: (key: string) => key } },
{ provide: ToastService, useValue: { showToast: jest.fn() } },
{ provide: CipherFormService, useValue: { saveCipher: jest.fn() } },
{ provide: CipherFormService, useValue: { saveCipher: jest.fn(), decryptCipher } },
{
provide: CipherFormCacheService,
useValue: { init: jest.fn(), getCachedCipherView: jest.fn() },
},
{ provide: ViewCacheService, useValue: { signal: jest.fn(() => () => null) } },
{ provide: ConfigService, useValue: {} },
{ provide: ConfigService, useValue: mock<ConfigService>() },
],
}).compileComponents();
});
@@ -87,4 +95,31 @@ describe("CipherFormComponent", () => {
expect(component.website).toEqual("https://example.com");
});
});
describe("clone", () => {
const cipherView = new CipherView();
cipherView.id = "test-id";
cipherView.login.fido2Credentials = [new Fido2CredentialView()];
beforeEach(() => {
component.config = {
mode: "clone",
originalCipher: new Cipher(),
} as CipherFormConfig;
decryptCipher.mockResolvedValue(cipherView);
});
it("clears id on updatedCipherView", async () => {
await component.ngOnInit();
expect(component["updatedCipherView"]?.id).toBeNull();
});
it("clears fido2Credentials on updatedCipherView", async () => {
await component.ngOnInit();
expect(component["updatedCipherView"]?.login.fido2Credentials).toBeNull();
});
});
});

View File

@@ -243,6 +243,10 @@ export class CipherFormComponent implements AfterViewInit, OnInit, OnChanges, Ci
if (this.config.mode === "clone") {
this.updatedCipherView.id = null;
if (this.updatedCipherView.login) {
this.updatedCipherView.login.fido2Credentials = null;
}
}
} else {
this.updatedCipherView.type = this.config.cipherType;