Skip to content

Commit

Permalink
update import tests. add import to build/deploy
Browse files Browse the repository at this point in the history
  • Loading branch information
Olivia Thet committed Feb 26, 2024
1 parent 9fd580f commit 325da3d
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 48 deletions.
2 changes: 2 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,11 @@ COPY nginx.conf /etc/nginx/nginx.conf
COPY auth /usr/share/nginx/auth
COPY auth /usr/share/nginx/recovery
COPY export /usr/share/nginx/export
COPY import /usr/share/nginx/import

EXPOSE 8080/tcp
EXPOSE 8081/tcp
EXPOSE 8082/tcp
EXPOSE 8083/tcp

CMD ["nginx"]
57 changes: 9 additions & 48 deletions import/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,61 +57,22 @@ describe("TKHQ", () => {
expect(item).toBeNull();
})

it("gets and sets embedded key in localStorage", async () => {
expect(TKHQ.getEmbeddedKey()).toBe(null);
it("gets and sets embedded target key in localStorage", async () => {
expect(TKHQ.getTargetEmbeddedKey()).toBe(null);

// Set a dummy "key"
TKHQ.setEmbeddedKey({"foo": "bar"});
expect(TKHQ.getEmbeddedKey()).toEqual({"foo": "bar"});
})

it("inits embedded key and is idempotent", async () => {
expect(TKHQ.getEmbeddedKey()).toBe(null);
await TKHQ.initEmbeddedKey();
const generatedKey = TKHQ.getEmbeddedKey();
expect(generatedKey).not.toBeNull()

// This should have no effect; generated key should stay the same
await TKHQ.initEmbeddedKey();
expect(TKHQ.getEmbeddedKey()).toEqual(generatedKey);
TKHQ.setTargetEmbeddedKey({"foo": "bar"});
expect(TKHQ.getTargetEmbeddedKey()).toEqual({"foo": "bar"});
})

it("generates P256 keys", async () => {
let key = await TKHQ.generateTargetKey();
it("imports P256 keys", async () => {
const targetPubHex = "0491ccb68758b822a6549257f87769eeed37c6cb68a6c6255c5f238e2b6e6e61838c8ac857f2e305970a6435715f84e5a2e4b02a4d1e5289ba7ec7910e47d2d50f";
const targetPublicBuf = TKHQ.uint8arrayFromHexString(targetPubHex);
const key = await TKHQ.importTargetKey(new Uint8Array(targetPublicBuf));
expect(key.kty).toEqual("EC");
expect(key.ext).toBe(true);
expect(key.crv).toBe("P-256");
expect(key.key_ops).toContain("deriveBits");
})

// it("parses private key correctly", async () => {
// const keyHex = "0x13eff5b3f9c63eab5d53cff5149f01606b69325496e0e98b53afa938d890cd2e";
// const parsedKey = TKHQ.parseKey(TKHQ.uint8arrayFromHexString(keyHex.slice(2)));
// expect(parsedKey).toEqual(keyHex);
// })

// it("parses wallet with only mnemonic correctly", async () => {
// const mnemonic = "suffer surround soup duck goose patrol add unveil appear eye neglect hurry alpha project tomorrow embody hen wish twenty join notable amused burden treat";
// const encoder = new TextEncoder("utf-8");
// const encodedWallet = encoder.encode(mnemonic);
// const parsedWallet = TKHQ.parseWallet(encodedWallet);
// expect(parsedWallet.mnemonic).toEqual(mnemonic);
// expect(parsedWallet.passphrase).toBeNull();
// })

// it("parses wallet mnemonic and passphrase correctly", async () => {
// const mnemonic = "suffer surround soup duck goose patrol add unveil appear eye neglect hurry alpha project tomorrow embody hen wish twenty join notable amused burden treat";
// const passphrase = "secret!";
// const encoder = new TextEncoder("utf-8");
// const encodedWallet = encoder.encode(mnemonic + "\n" + passphrase);
// const parsedWallet = TKHQ.parseWallet(encodedWallet);
// expect(parsedWallet.mnemonic).toEqual(mnemonic);
// expect(parsedWallet.passphrase).toEqual(passphrase);
// })

it("contains p256JWKPrivateToPublic", async () => {
// TODO: test this
expect(true).toBe(true);
expect(key.key_ops).toEqual([]);
})

it("contains additionalAssociatedData", async () => {
Expand Down
5 changes: 5 additions & 0 deletions kustomize/resources.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ spec:
containerPort: 8081
- name: recovery
containerPort: 8082
- name: import
containerPort: 8083
livenessProbe:
httpGet:
path: /health
Expand Down Expand Up @@ -51,3 +53,6 @@ spec:
- name: http-recovery
port: 8082
targetPort: recovery
- name: http-import
port: 8083
targetPort: import
5 changes: 5 additions & 0 deletions nginx.conf
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,9 @@ http {
listen 8082;
root /usr/share/nginx/recovery;
}

server {
listen 8083;
root /usr/share/nginx/import;
}
}

0 comments on commit 325da3d

Please sign in to comment.