Skip to content

Commit b36e45e

Browse files
committed
test: add export check to x509 pem import tests
1 parent e839ecb commit b36e45e

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

tap/pem.ts

+8-3
Original file line numberDiff line numberDiff line change
@@ -120,8 +120,9 @@ export default (QUnit: QUnit, lib: typeof jose) => {
120120
;[alg, crv] = alg
121121
}
122122

123+
let x509 = false
123124
let importFn: typeof lib.importSPKI | typeof lib.importPKCS8 | typeof lib.importX509
124-
let exportFn: typeof lib.exportSPKI | typeof lib.exportPKCS8 | undefined = undefined
125+
let exportFn: typeof lib.exportSPKI | typeof lib.exportPKCS8
125126
switch (true) {
126127
case pem.startsWith('-----BEGIN PRIVATE KEY-----'): {
127128
importFn = lib.importPKCS8
@@ -135,17 +136,21 @@ export default (QUnit: QUnit, lib: typeof jose) => {
135136
}
136137
case pem.startsWith('-----BEGIN CERTIFICATE-----'): {
137138
importFn = lib.importX509
139+
exportFn = lib.exportSPKI
140+
x509 = true
138141
break
139142
}
140143
default:
141-
continue
144+
throw new Error()
142145
}
143146

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

147-
if (exportFn) {
150+
if (!x509) {
148151
t.strictEqual(normalize(await exportFn(k)), normalize(pem))
152+
} else {
153+
await exportFn(k)
149154
}
150155
t.ok(1)
151156
}

0 commit comments

Comments
 (0)