Skip to content

Commit

Permalink
test: add export check to x509 pem import tests
Browse files Browse the repository at this point in the history
  • Loading branch information
panva committed Mar 7, 2024
1 parent e839ecb commit b36e45e
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions tap/pem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,9 @@ export default (QUnit: QUnit, lib: typeof jose) => {
;[alg, crv] = alg
}

let x509 = false
let importFn: typeof lib.importSPKI | typeof lib.importPKCS8 | typeof lib.importX509
let exportFn: typeof lib.exportSPKI | typeof lib.exportPKCS8 | undefined = undefined
let exportFn: typeof lib.exportSPKI | typeof lib.exportPKCS8
switch (true) {
case pem.startsWith('-----BEGIN PRIVATE KEY-----'): {
importFn = lib.importPKCS8
Expand All @@ -135,17 +136,21 @@ export default (QUnit: QUnit, lib: typeof jose) => {
}
case pem.startsWith('-----BEGIN CERTIFICATE-----'): {
importFn = lib.importX509
exportFn = lib.exportSPKI
x509 = true
break
}
default:
continue
throw new Error()
}

const execute = async (t: typeof QUnit.assert) => {
const k = await importFn(pem, <string>alg, { extractable: true })

if (exportFn) {
if (!x509) {
t.strictEqual(normalize(await exportFn(k)), normalize(pem))
} else {
await exportFn(k)
}
t.ok(1)
}
Expand Down

0 comments on commit b36e45e

Please sign in to comment.