This repository has been archived by the owner on Jun 17, 2022. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
23 changed files
with
1,933 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
import Substitute, { Arg } from "@fluffy-spoon/substitute"; | ||
|
||
import { CryptoService } from "jslib-common/abstractions/crypto.service"; | ||
import { AttachmentData } from "jslib-common/models/data/attachmentData"; | ||
import { Attachment } from "jslib-common/models/domain/attachment"; | ||
import { SymmetricCryptoKey } from "jslib-common/models/domain/symmetricCryptoKey"; | ||
import { ContainerService } from "jslib-common/services/container.service"; | ||
|
||
import { makeStaticByteArray, mockEnc } from "../utils"; | ||
|
||
describe("Attachment", () => { | ||
let data: AttachmentData; | ||
|
||
beforeEach(() => { | ||
data = { | ||
id: "id", | ||
url: "url", | ||
fileName: "fileName", | ||
key: "key", | ||
size: "1100", | ||
sizeName: "1.1 KB", | ||
}; | ||
}); | ||
|
||
it("Convert from empty", () => { | ||
const data = new AttachmentData(); | ||
const attachment = new Attachment(data); | ||
|
||
expect(attachment).toEqual({ | ||
id: null, | ||
url: null, | ||
size: undefined, | ||
sizeName: null, | ||
key: null, | ||
fileName: null, | ||
}); | ||
}); | ||
|
||
it("Convert", () => { | ||
const attachment = new Attachment(data); | ||
|
||
expect(attachment).toEqual({ | ||
size: "1100", | ||
id: "id", | ||
url: "url", | ||
sizeName: "1.1 KB", | ||
fileName: { encryptedString: "fileName", encryptionType: 0 }, | ||
key: { encryptedString: "key", encryptionType: 0 }, | ||
}); | ||
}); | ||
|
||
it("toAttachmentData", () => { | ||
const attachment = new Attachment(data); | ||
expect(attachment.toAttachmentData()).toEqual(data); | ||
}); | ||
|
||
it("Decrypt", async () => { | ||
const attachment = new Attachment(); | ||
attachment.id = "id"; | ||
attachment.url = "url"; | ||
attachment.size = "1100"; | ||
attachment.sizeName = "1.1 KB"; | ||
attachment.key = mockEnc("key"); | ||
attachment.fileName = mockEnc("fileName"); | ||
|
||
const cryptoService = Substitute.for<CryptoService>(); | ||
cryptoService.getOrgKey(null).resolves(null); | ||
cryptoService.decryptToBytes(Arg.any(), Arg.any()).resolves(makeStaticByteArray(32)); | ||
|
||
(window as any).bitwardenContainerService = new ContainerService(cryptoService); | ||
|
||
const view = await attachment.decrypt(null); | ||
|
||
expect(view).toEqual({ | ||
id: "id", | ||
url: "url", | ||
size: "1100", | ||
sizeName: "1.1 KB", | ||
fileName: "fileName", | ||
key: expect.any(SymmetricCryptoKey), | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
import { CardData } from "jslib-common/models/data/cardData"; | ||
import { Card } from "jslib-common/models/domain/card"; | ||
|
||
import { mockEnc } from "../utils"; | ||
|
||
describe("Card", () => { | ||
let data: CardData; | ||
|
||
beforeEach(() => { | ||
data = { | ||
cardholderName: "encHolder", | ||
brand: "encBrand", | ||
number: "encNumber", | ||
expMonth: "encMonth", | ||
expYear: "encYear", | ||
code: "encCode", | ||
}; | ||
}); | ||
|
||
it("Convert from empty", () => { | ||
const data = new CardData(); | ||
const card = new Card(data); | ||
|
||
expect(card).toEqual({ | ||
cardholderName: null, | ||
brand: null, | ||
number: null, | ||
expMonth: null, | ||
expYear: null, | ||
code: null, | ||
}); | ||
}); | ||
|
||
it("Convert", () => { | ||
const card = new Card(data); | ||
|
||
expect(card).toEqual({ | ||
cardholderName: { encryptedString: "encHolder", encryptionType: 0 }, | ||
brand: { encryptedString: "encBrand", encryptionType: 0 }, | ||
number: { encryptedString: "encNumber", encryptionType: 0 }, | ||
expMonth: { encryptedString: "encMonth", encryptionType: 0 }, | ||
expYear: { encryptedString: "encYear", encryptionType: 0 }, | ||
code: { encryptedString: "encCode", encryptionType: 0 }, | ||
}); | ||
}); | ||
|
||
it("toCardData", () => { | ||
const card = new Card(data); | ||
expect(card.toCardData()).toEqual(data); | ||
}); | ||
|
||
it("Decrypt", async () => { | ||
const card = new Card(); | ||
card.cardholderName = mockEnc("cardHolder"); | ||
card.brand = mockEnc("brand"); | ||
card.number = mockEnc("number"); | ||
card.expMonth = mockEnc("expMonth"); | ||
card.expYear = mockEnc("expYear"); | ||
card.code = mockEnc("code"); | ||
|
||
const view = await card.decrypt(null); | ||
|
||
expect(view).toEqual({ | ||
_brand: "brand", | ||
_number: "number", | ||
_subTitle: null, | ||
cardholderName: "cardHolder", | ||
code: "code", | ||
expMonth: "expMonth", | ||
expYear: "expYear", | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.