deno.land / x / oauth4webapi@v1.2.2 / tap / generate.ts

generate.ts
View Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
import type QUnit from 'qunit'import * as lib from '../src/index.js'import * as env from './env.js'
function isRSA(alg: string) { return alg.startsWith('RS') || alg.startsWith('PS')}
export default (QUnit: QUnit) => { const { module, test } = QUnit module('generate.ts') test('"alg" value validation', async (t) => { for (const value of [null, 1, 0, Infinity, Boolean, undefined, false, true, '']) { await t.rejects(lib.generateKeyPair(<any>value), /"alg" must be a non-empty string/) } })
test('unknown algorithm', async (t) => { await t.rejects(lib.generateKeyPair(<any>'foo'), /UnsupportedOperationError/) })
const algs = <lib.JWSAlgorithm[]>['RS256', 'PS256', 'ES256']
if (env.isDeno || env.isNode) { algs.push('EdDSA') }
for (const alg of algs) { test(`${alg} defaults`, async (t) => { const { publicKey, privateKey } = await lib.generateKeyPair(alg) t.deepEqual(publicKey.usages, ['verify']) t.deepEqual(privateKey.usages, ['sign']) t.equal(publicKey.extractable, true) t.equal(privateKey.extractable, false)
if (isRSA(alg)) { // @ts-expect-error t.equal(publicKey.algorithm.modulusLength, 2048) t.deepEqual( // @ts-expect-error new Uint8Array(publicKey.algorithm.publicExponent), new Uint8Array([0x01, 0x00, 0x01]), ) // @ts-expect-error t.equal(privateKey.algorithm.modulusLength, 2048) t.deepEqual( // @ts-expect-error new Uint8Array(privateKey.algorithm.publicExponent), new Uint8Array([0x01, 0x00, 0x01]), ) } })
test(`${alg} extractable`, async (t) => { { const { publicKey, privateKey } = await lib.generateKeyPair(alg, { extractable: false }) t.equal(publicKey.extractable, true) t.equal(privateKey.extractable, false) }
{ const { publicKey, privateKey } = await lib.generateKeyPair(alg, { extractable: true }) t.equal(publicKey.extractable, true) t.equal(privateKey.extractable, true) } })
if (isRSA(alg)) { test(`${alg} modulusLength`, async (t) => { const { publicKey, privateKey } = await lib.generateKeyPair(alg, { modulusLength: 3072 }) // @ts-expect-error t.equal(publicKey.algorithm.modulusLength, 3072) // @ts-expect-error t.equal(privateKey.algorithm.modulusLength, 3072) }) } }}
oauth4webapi

Version Info

Tagged at
2 years ago