Skip to content

Commit

Permalink
Add secret tests for parseFlag behavior
Browse files Browse the repository at this point in the history
  • Loading branch information
macmv committed Oct 13, 2023
1 parent 22d54b4 commit 537b916
Showing 1 changed file with 31 additions and 11 deletions.
42 changes: 31 additions & 11 deletions test/lib/secret.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,37 @@
import { expect } from "chai";
import { Secret } from "../../src/lib/secret";

describe("secret", () => {
describe("Secret.parse", () => {
it("disallows empty secrets", () => {
expect(() => Secret.parse("")).to.throw("Secret cannot be empty");
});

it("disallows scoped secrets", () => {
expect(() => Secret.parse("fn1234:foo")).to.throw(
"Secret cannot be scoped"
);
});
});

describe("Secret.parseFlag", () => {
it("disallows empty secrets", () => {
expect(() => Secret.parseFlag("")).to.throw("Secret cannot be empty");
});

it("allows scoped secrets", () => {
Secret.parseFlag("fn1234:foo");
});

it("disallows appending scopes to scoped secrets", () => {
const secret = Secret.parseFlag("fn1234:foo");

expect(() => secret.appendScope("bar")).to.throw(
"Cannot specify database with a secret that contains a database"
);
});
});

describe("Secret", () => {
it("appends paths scoped secrets", () => {
const secret = Secret.parse("fn1234");
expect(secret.databaseScope).to.eql([]);
Expand All @@ -21,16 +51,6 @@ describe("secret", () => {
expect(secret.databaseScope).to.eql(["foo", "bar"]);
});

it("disallows empty secrets", () => {
expect(() => Secret.parse("")).to.throw("Secret cannot be empty");
});

it("disallows scoped secrets", () => {
expect(() => Secret.parse("fn1234:foo")).to.throw(
"Secret cannot be scoped"
);
});

it("builds a secret with a role", () => {
const secret = Secret.parse("fn1234");
expect(secret.buildSecret()).to.equal("fn1234");
Expand Down

0 comments on commit 537b916

Please sign in to comment.