Skip to content

Commit 0540102

Browse files
committed
test: fixup to use env.supported in rsaes.ts
1 parent 0a81a9a commit 0540102

File tree

1 file changed

+9
-17
lines changed

1 file changed

+9
-17
lines changed

tap/rsaes.ts

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import type QUnit from 'qunit'
22
import type * as jose from '../src/index.js'
33
import * as roundtrip from './encrypt.js'
4+
import * as env from './env.js'
45

56
export default (
67
QUnit: QUnit,
@@ -12,27 +13,18 @@ export default (
1213

1314
const kps: Record<string, jose.GenerateKeyPairResult> = {}
1415

15-
type Vector = [string, boolean]
16-
const algorithms: Vector[] = [
17-
['RSA-OAEP', true],
18-
['RSA-OAEP-256', true],
19-
['RSA-OAEP-384', true],
20-
['RSA-OAEP-512', true],
21-
]
16+
const algorithms = ['RSA-OAEP', 'RSA-OAEP-256', 'RSA-OAEP-384', 'RSA-OAEP-512']
2217

23-
function title(vector: Vector) {
24-
const [alg, works] = vector
18+
function title(alg: string, supported = true) {
2519
let result = ''
26-
if (!works) {
20+
if (!supported) {
2721
result = '[not supported] '
2822
}
2923
result += `${alg}`
3024
return result
3125
}
3226

33-
for (const vector of algorithms) {
34-
const [alg, works] = vector
35-
27+
for (const alg of algorithms) {
3628
const execute = async (t: typeof QUnit.assert) => {
3729
if (!kps[alg]) {
3830
kps[alg] = await keys.generateKeyPair(alg, { extractable: true })
@@ -49,11 +41,11 @@ export default (
4941
await roundtrip.jwt(t, lib, keys, alg, 'A128GCM', kps[alg])
5042
}
5143

52-
if (works) {
53-
test(title(vector), execute)
54-
test(`${title(vector)} JWT`, jwt)
44+
if (env.supported(alg)) {
45+
test(title(alg), execute)
46+
test(`${title(alg)} JWT`, jwt)
5547
} else {
56-
test(title(vector), async (t) => {
48+
test(title(alg, false), async (t) => {
5749
await t.rejects(execute(t))
5850
})
5951
}

0 commit comments

Comments
 (0)