This commit is contained in:
fyears 2021-11-08 10:00:06 +08:00
parent 7ec2db4006
commit 3609a78465
2 changed files with 15 additions and 1 deletions

View File

@ -15,10 +15,12 @@
"license": "Apache-2.0", "license": "Apache-2.0",
"devDependencies": { "devDependencies": {
"@types/chai": "^4.2.22", "@types/chai": "^4.2.22",
"@types/chai-as-promised": "^7.1.4",
"@types/mime-types": "^2.1.1", "@types/mime-types": "^2.1.1",
"@types/mocha": "^9.0.0", "@types/mocha": "^9.0.0",
"@types/node": "^14.14.37", "@types/node": "^14.14.37",
"chai": "^4.3.4", "chai": "^4.3.4",
"chai-as-promised": "^7.1.1",
"cross-env": "^7.0.3", "cross-env": "^7.0.3",
"mocha": "^9.1.3", "mocha": "^9.1.3",
"prettier": "^2.4.1", "prettier": "^2.4.1",

View File

@ -1,6 +1,7 @@
import * as fs from "fs"; import * as fs from "fs";
import * as path from "path"; 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 { base64ToBase32, bufferToArrayBuffer } from "../src/misc";
import { import {
decryptArrayBuffer, decryptArrayBuffer,
@ -9,6 +10,9 @@ import {
encryptStringToBase32, encryptStringToBase32,
} from "../src/encrypt"; } from "../src/encrypt";
chai.use(chaiAsPromised);
const expect = chai.expect;
describe("Encryption tests", () => { describe("Encryption tests", () => {
beforeEach(function () { beforeEach(function () {
global.window = { global.window = {
@ -22,6 +26,14 @@ describe("Encryption tests", () => {
expect(await encryptStringToBase32(k, password)).to.not.equal(k); 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 () => { it("should encrypt and decrypt string and get the same result returned", async () => {
const k = "jfkkjkjbce7983ycdeknkkjckooAIUHIDIBIE((*BII)njD/d/dd/d/sjxhux"; const k = "jfkkjkjbce7983ycdeknkkjckooAIUHIDIBIE((*BII)njD/d/dd/d/sjxhux";
const password = "hfiuibec989###oiu982bj1`"; const password = "hfiuibec989###oiu982bj1`";