diff --git a/package.json b/package.json index ea979cd..25a3023 100644 --- a/package.json +++ b/package.json @@ -15,10 +15,12 @@ "license": "Apache-2.0", "devDependencies": { "@types/chai": "^4.2.22", + "@types/chai-as-promised": "^7.1.4", "@types/mime-types": "^2.1.1", "@types/mocha": "^9.0.0", "@types/node": "^14.14.37", "chai": "^4.3.4", + "chai-as-promised": "^7.1.1", "cross-env": "^7.0.3", "mocha": "^9.1.3", "prettier": "^2.4.1", diff --git a/tests/encrypt.test.ts b/tests/encrypt.test.ts index 0977b41..072e53b 100644 --- a/tests/encrypt.test.ts +++ b/tests/encrypt.test.ts @@ -1,6 +1,7 @@ import * as fs from "fs"; import * as path from "path"; -import { expect } from "chai"; +import * as chai from "chai"; +import chaiAsPromised from "chai-as-promised"; import { base64ToBase32, bufferToArrayBuffer } from "../src/misc"; import { decryptArrayBuffer, @@ -9,6 +10,9 @@ import { encryptStringToBase32, } from "../src/encrypt"; +chai.use(chaiAsPromised); +const expect = chai.expect; + describe("Encryption tests", () => { beforeEach(function () { global.window = { @@ -22,6 +26,14 @@ describe("Encryption tests", () => { expect(await encryptStringToBase32(k, password)).to.not.equal(k); }); + it("should raise error using different password", async () => { + const k = "secret text"; + const password = "hey"; + const password2 = "hey2"; + const enc = await encryptStringToBase32(k, password); + await expect(decryptBase32ToString(enc, password2)).to.be.rejected; + }); + it("should encrypt and decrypt string and get the same result returned", async () => { const k = "jfkkjkjbce7983ycdeknkkjckooAIUHIDIBIE((*BII)njD/d/dd/d/sjxhux"; const password = "hfiuibec989###oiu982bj1`";