mirror of
https://github.com/bitwarden/browser
synced 2025-12-10 05:13:29 +00:00
[PM-22812] Attachments get corrupted when downgrading from cipherkeys (#15324)
* Map decrypted key returned from SDK to client * Updated sdk dependency
This commit is contained in:
@@ -26,6 +26,8 @@ describe("AttachmentView", () => {
|
||||
});
|
||||
|
||||
it("should return an AttachmentView from an SdkAttachmentView", () => {
|
||||
jest.spyOn(SymmetricCryptoKey, "fromString").mockReturnValue("mockKey" as any);
|
||||
|
||||
const sdkAttachmentView = {
|
||||
id: "id",
|
||||
url: "url",
|
||||
@@ -33,6 +35,7 @@ describe("AttachmentView", () => {
|
||||
sizeName: "sizeName",
|
||||
fileName: "fileName",
|
||||
key: "encKeyB64_fromString",
|
||||
decryptedKey: "decryptedKey_B64",
|
||||
} as SdkAttachmentView;
|
||||
|
||||
const result = AttachmentView.fromSdkAttachmentView(sdkAttachmentView);
|
||||
@@ -43,14 +46,20 @@ describe("AttachmentView", () => {
|
||||
size: "size",
|
||||
sizeName: "sizeName",
|
||||
fileName: "fileName",
|
||||
key: null,
|
||||
key: "mockKey",
|
||||
encryptedKey: new EncString(sdkAttachmentView.key as string),
|
||||
});
|
||||
|
||||
expect(SymmetricCryptoKey.fromString).toHaveBeenCalledWith("decryptedKey_B64");
|
||||
});
|
||||
});
|
||||
|
||||
describe("toSdkAttachmentView", () => {
|
||||
it("should convert AttachmentView to SdkAttachmentView", () => {
|
||||
const mockKey = {
|
||||
toBase64: jest.fn().mockReturnValue("keyB64"),
|
||||
} as any;
|
||||
|
||||
const attachmentView = new AttachmentView();
|
||||
attachmentView.id = "id";
|
||||
attachmentView.url = "url";
|
||||
@@ -58,8 +67,10 @@ describe("AttachmentView", () => {
|
||||
attachmentView.sizeName = "sizeName";
|
||||
attachmentView.fileName = "fileName";
|
||||
attachmentView.encryptedKey = new EncString("encKeyB64");
|
||||
attachmentView.key = mockKey;
|
||||
|
||||
const result = attachmentView.toSdkAttachmentView();
|
||||
|
||||
expect(result).toEqual({
|
||||
id: "id",
|
||||
url: "url",
|
||||
@@ -67,7 +78,7 @@ describe("AttachmentView", () => {
|
||||
sizeName: "sizeName",
|
||||
fileName: "fileName",
|
||||
key: "encKeyB64",
|
||||
decryptedKey: null,
|
||||
decryptedKey: "keyB64",
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -59,7 +59,8 @@ export class AttachmentView implements View {
|
||||
sizeName: this.sizeName,
|
||||
fileName: this.fileName,
|
||||
key: this.encryptedKey?.toJSON(),
|
||||
decryptedKey: null,
|
||||
// TODO: PM-23005 - Temporary field, should be removed when encrypted migration is complete
|
||||
decryptedKey: this.key ? this.key.toBase64() : null,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -77,6 +78,8 @@ export class AttachmentView implements View {
|
||||
view.size = obj.size ?? null;
|
||||
view.sizeName = obj.sizeName ?? null;
|
||||
view.fileName = obj.fileName ?? null;
|
||||
// TODO: PM-23005 - Temporary field, should be removed when encrypted migration is complete
|
||||
view.key = obj.key ? SymmetricCryptoKey.fromString(obj.decryptedKey) : null;
|
||||
view.encryptedKey = new EncString(obj.key);
|
||||
|
||||
return view;
|
||||
|
||||
Reference in New Issue
Block a user