Files
opvault.js/test/profile.test.ts
proteriax 98cc916432 Update
2021-07-18 16:12:04 -04:00

55 lines
1.6 KiB
TypeScript

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";
describe("OnePassword", () => {
const freddy = resolve(__dirname, "../freddy-2013-12-04.opvault");
describe("getProfileNames", () => {
it("freddy", async () => {
const instance = new OnePassword({ path: freddy });
expect(await instance.getProfileNames()).to.deep.equal(["default"]);
});
it.skip("ignores faulty folders", async () => {});
});
describe("unlock", () => {
let vault: Vault;
beforeEach(async () => {
vault = await new OnePassword({ path: freddy }).getProfile("default");
});
it("accepts correct password", () => {
expect(() => vault.unlock("freddy")).to.not.throw();
expect(vault.isLocked).to.be.false;
});
it("rejects wrong password", () => {
["Freddy", "_freddy", ""].forEach((password) => {
expect(() => vault.unlock(password)).to.throw("Invalid password");
expect(vault.isLocked).to.be.true;
});
});
});
describe("lock", () => {
it("locks", async () => {
const instance = new OnePassword({ path: freddy });
const vault = await instance.getProfile("default");
vault.unlock("freddy");
expect(vault.isLocked).to.be.false;
vault.lock();
expect(vault.isLocked).to.be.true;
expect(() => vault.overviews.values()).to.throw();
});
});
});