Add web interface and tests

This commit is contained in:
aet
2021-11-05 03:17:18 -04:00
parent 7f41a50fb1
commit fe926be0a6
66 changed files with 3390 additions and 1275 deletions

View File

@ -1,11 +1,9 @@
import { resolve } from "path";
import { describe, it, beforeEach } from "mocha";
import { expect } from "chai";
// import { fs, vol } from "memfs"
import type { Vault } from "../src/index";
import { OnePassword } from "../src/index";
// import adapter from "../src/adapters/node";
import type { Vault } from "../packages/opvault.js/index";
import { OnePassword } from "../packages/opvault.js/index";
describe("OnePassword", () => {
const freddy = resolve(__dirname, "../freddy-2013-12-04.opvault");
@ -49,9 +47,44 @@ describe("OnePassword", () => {
await vault.unlock("freddy");
});
it("reads overviews", () => {
const overviews = vault.overviews.values();
expect(overviews).to.have.lengthOf(29);
it("reads notes", async () => {
const item = (await vault.getItem({
title: "A note with some attachments",
}))!;
expect(item).to.exist;
expect(item.uuid).to.equal("F2DB5DA3FCA64372A751E0E85C67A538");
expect(item.attachments).to.have.lengthOf(2);
expect(item.details).to.deep.equal({
notesPlain: "This note has two attachments.",
});
expect(item.overview).to.deep.equal({
title: "A note with some attachments",
ps: 0,
ainfo: "This note has two attachments.",
});
});
it("decrypts items", async () => {
const decrypted = require("./decrypted.json");
expect(vault.isLocked).to.be.false;
for (const [uuid, item] of Object.entries<any>(decrypted)) {
const actual = await vault.getItem(uuid);
expect(actual).to.exist;
expect(actual!.overview).to.deep.equal(item.overview);
expect(actual!.details).to.deep.equal(item.itemDetails);
expect(actual!.attachments).to.have.lengthOf(item.attachments.length);
for (const [i, attachment] of actual!.attachments.entries()) {
const expected = item.attachments[i];
await attachment.unlock();
expect(attachment.metadata).to.deep.equal(expected.metadata);
expect(attachment.file.toString("base64")).to.deep.equal(
expected.file
);
expect(attachment.icon.toString("base64")).to.deep.equal(
expected.icon
);
}
}
});
});
@ -64,7 +97,8 @@ describe("OnePassword", () => {
vault.lock();
expect(vault.isLocked).to.be.true;
expect(() => vault.overviews.values()).to.throw();
expect(vault.getItem("F2DB5DA3FCA64372A751E0E85C67A538")).to.eventually
.throw;
});
});
});