mirror of
https://github.com/bitwarden/browser
synced 2025-12-11 13:53:34 +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", () => {
|
it("should return an AttachmentView from an SdkAttachmentView", () => {
|
||||||
|
jest.spyOn(SymmetricCryptoKey, "fromString").mockReturnValue("mockKey" as any);
|
||||||
|
|
||||||
const sdkAttachmentView = {
|
const sdkAttachmentView = {
|
||||||
id: "id",
|
id: "id",
|
||||||
url: "url",
|
url: "url",
|
||||||
@@ -33,6 +35,7 @@ describe("AttachmentView", () => {
|
|||||||
sizeName: "sizeName",
|
sizeName: "sizeName",
|
||||||
fileName: "fileName",
|
fileName: "fileName",
|
||||||
key: "encKeyB64_fromString",
|
key: "encKeyB64_fromString",
|
||||||
|
decryptedKey: "decryptedKey_B64",
|
||||||
} as SdkAttachmentView;
|
} as SdkAttachmentView;
|
||||||
|
|
||||||
const result = AttachmentView.fromSdkAttachmentView(sdkAttachmentView);
|
const result = AttachmentView.fromSdkAttachmentView(sdkAttachmentView);
|
||||||
@@ -43,14 +46,20 @@ describe("AttachmentView", () => {
|
|||||||
size: "size",
|
size: "size",
|
||||||
sizeName: "sizeName",
|
sizeName: "sizeName",
|
||||||
fileName: "fileName",
|
fileName: "fileName",
|
||||||
key: null,
|
key: "mockKey",
|
||||||
encryptedKey: new EncString(sdkAttachmentView.key as string),
|
encryptedKey: new EncString(sdkAttachmentView.key as string),
|
||||||
});
|
});
|
||||||
|
|
||||||
|
expect(SymmetricCryptoKey.fromString).toHaveBeenCalledWith("decryptedKey_B64");
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("toSdkAttachmentView", () => {
|
describe("toSdkAttachmentView", () => {
|
||||||
it("should convert AttachmentView to SdkAttachmentView", () => {
|
it("should convert AttachmentView to SdkAttachmentView", () => {
|
||||||
|
const mockKey = {
|
||||||
|
toBase64: jest.fn().mockReturnValue("keyB64"),
|
||||||
|
} as any;
|
||||||
|
|
||||||
const attachmentView = new AttachmentView();
|
const attachmentView = new AttachmentView();
|
||||||
attachmentView.id = "id";
|
attachmentView.id = "id";
|
||||||
attachmentView.url = "url";
|
attachmentView.url = "url";
|
||||||
@@ -58,8 +67,10 @@ describe("AttachmentView", () => {
|
|||||||
attachmentView.sizeName = "sizeName";
|
attachmentView.sizeName = "sizeName";
|
||||||
attachmentView.fileName = "fileName";
|
attachmentView.fileName = "fileName";
|
||||||
attachmentView.encryptedKey = new EncString("encKeyB64");
|
attachmentView.encryptedKey = new EncString("encKeyB64");
|
||||||
|
attachmentView.key = mockKey;
|
||||||
|
|
||||||
const result = attachmentView.toSdkAttachmentView();
|
const result = attachmentView.toSdkAttachmentView();
|
||||||
|
|
||||||
expect(result).toEqual({
|
expect(result).toEqual({
|
||||||
id: "id",
|
id: "id",
|
||||||
url: "url",
|
url: "url",
|
||||||
@@ -67,7 +78,7 @@ describe("AttachmentView", () => {
|
|||||||
sizeName: "sizeName",
|
sizeName: "sizeName",
|
||||||
fileName: "fileName",
|
fileName: "fileName",
|
||||||
key: "encKeyB64",
|
key: "encKeyB64",
|
||||||
decryptedKey: null,
|
decryptedKey: "keyB64",
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -59,7 +59,8 @@ export class AttachmentView implements View {
|
|||||||
sizeName: this.sizeName,
|
sizeName: this.sizeName,
|
||||||
fileName: this.fileName,
|
fileName: this.fileName,
|
||||||
key: this.encryptedKey?.toJSON(),
|
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.size = obj.size ?? null;
|
||||||
view.sizeName = obj.sizeName ?? null;
|
view.sizeName = obj.sizeName ?? null;
|
||||||
view.fileName = obj.fileName ?? 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);
|
view.encryptedKey = new EncString(obj.key);
|
||||||
|
|
||||||
return view;
|
return view;
|
||||||
|
|||||||
Reference in New Issue
Block a user