mirror of
https://github.com/danbulant/jose
synced 2026-05-19 04:18:52 +00:00
test,ci: refactor and add tests using node's experimental globals
This commit is contained in:
parent
94dd89367f
commit
6fc1d4388c
41 changed files with 110 additions and 270 deletions
15
.github/workflows/test.yml
vendored
15
.github/workflows/test.yml
vendored
|
|
@ -112,15 +112,18 @@ jobs:
|
|||
path: dist
|
||||
key: dist-${{ hashFiles('src/**/*.ts') }}-${{ hashFiles('tsconfig/*.json') }}-${{ hashFiles('.github/workflows/*.yml') }}-${{ hashFiles('package.json') }}
|
||||
- run: find test -type f -name '*.mjs' -print0 | xargs -0 sed -i -e "s/await import(/require(/g"
|
||||
if: ${{ startsWith(matrix.node-version, '12') }}
|
||||
- name: Test Node.js crypto
|
||||
if: ${{ startsWith(matrix.node-version, '12') }}
|
||||
- name: Test with Node.js crypto module
|
||||
run: npm run test
|
||||
- name: Test Node.js crypto w/ CryptoKey
|
||||
- name: Test with Node.js crypto module w/ CryptoKey
|
||||
run: npm run test-cryptokey
|
||||
if: ${{ !startsWith(matrix.node-version, '14') && !startsWith(matrix.node-version, '12') }}
|
||||
- name: Test Web Cryptography API
|
||||
if: ${{ !startsWith(matrix.node-version, '14') && !startsWith(matrix.node-version, '12') }}
|
||||
- name: Test with Node.js Web Cryptography API
|
||||
run: npm run test-webcrypto
|
||||
if: ${{ !startsWith(matrix.node-version, '14') && !startsWith(matrix.node-version, '12') }}
|
||||
if: ${{ !startsWith(matrix.node-version, '14') && !startsWith(matrix.node-version, '12') }}
|
||||
- name: Test with Node.js Web API
|
||||
run: npm run test-webapi
|
||||
if: ${{ matrix.experimental }}
|
||||
- run: git reset HEAD --hard
|
||||
|
||||
test-deno:
|
||||
|
|
|
|||
|
|
@ -69,6 +69,12 @@
|
|||
"#dist/webcrypto": {
|
||||
"import": "./dist/node/webcrypto/esm/index.js",
|
||||
"require": "./dist/node/webcrypto/cjs/index.js"
|
||||
},
|
||||
"#dist/webapi/*": {
|
||||
"import": "./dist/browser/*.js"
|
||||
},
|
||||
"#dist/webapi": {
|
||||
"import": "./dist/browser/index.js"
|
||||
}
|
||||
},
|
||||
"exports": {
|
||||
|
|
@ -138,6 +144,7 @@
|
|||
"test-deno": "deno test --reload --jobs --allow-net --allow-read test-deno",
|
||||
"test-browsers": "find test-browser -type f -name '*.js' -print0 | xargs -0 npx esbuild --log-level=warning --outdir=dist-browser-tests --bundle && karma start",
|
||||
"test-cryptokey": "CRYPTOKEY=true npm test",
|
||||
"test-webapi": "WEBAPI=true NODE_OPTIONS='--experimental-fetch --experimental-global-webcrypto --no-warnings' npm test",
|
||||
"test-webcrypto": "WEBCRYPTO=true npm test",
|
||||
"prettier": "npx prettier --loglevel silent --write ./test ./src ./tools ./test-browser ./test-deno ./test-cloudflare-workers"
|
||||
},
|
||||
|
|
|
|||
32
test/dist.mjs
Normal file
32
test/dist.mjs
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
import test from 'ava'
|
||||
|
||||
let root
|
||||
let keyRoot
|
||||
|
||||
if ('WEBCRYPTO' in process.env) {
|
||||
root = keyRoot = '#dist/webcrypto'
|
||||
} else if ('CRYPTOKEY' in process.env) {
|
||||
root = '#dist'
|
||||
keyRoot = '#dist/webcrypto'
|
||||
} else if ('WEBAPI' in process.env) {
|
||||
root = keyRoot = '#dist/webapi'
|
||||
} else {
|
||||
root = keyRoot = '#dist'
|
||||
}
|
||||
|
||||
export { root, keyRoot }
|
||||
|
||||
export function conditional({ webcrypto = 1, electron = 1 } = {}) {
|
||||
let run = test
|
||||
if (
|
||||
!webcrypto &&
|
||||
('WEBCRYPTO' in process.env || 'WEBAPI' in process.env || 'CRYPTOKEY' in process.env)
|
||||
) {
|
||||
run = run.failing
|
||||
}
|
||||
|
||||
if (!electron && 'electron' in process.versions) {
|
||||
run = run.failing
|
||||
}
|
||||
return run
|
||||
}
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
import test from 'ava'
|
||||
import { root } from '../dist.mjs'
|
||||
|
||||
const root = !('WEBCRYPTO' in process.env) ? '#dist' : '#dist/webcrypto'
|
||||
const { CompactEncrypt, compactDecrypt, base64url } = await import(root)
|
||||
|
||||
test('JWE format validation', async (t) => {
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
import test from 'ava'
|
||||
import { root } from '../dist.mjs'
|
||||
|
||||
const root = !('WEBCRYPTO' in process.env) ? '#dist' : '#dist/webcrypto'
|
||||
const { CompactEncrypt } = await import(root)
|
||||
|
||||
test.before(async (t) => {
|
||||
|
|
|
|||
|
|
@ -1,16 +1,5 @@
|
|||
import test from 'ava'
|
||||
|
||||
let root
|
||||
let keyRoot
|
||||
|
||||
if ('WEBCRYPTO' in process.env) {
|
||||
root = keyRoot = '#dist/webcrypto'
|
||||
} else if ('CRYPTOKEY' in process.env) {
|
||||
root = '#dist'
|
||||
keyRoot = '#dist/webcrypto'
|
||||
} else {
|
||||
root = keyRoot = '#dist'
|
||||
}
|
||||
import { root, keyRoot } from '../dist.mjs'
|
||||
|
||||
const { FlattenedEncrypt, flattenedDecrypt, CompactEncrypt, compactDecrypt, base64url } =
|
||||
await import(root)
|
||||
|
|
@ -665,6 +654,7 @@ const vectors = [
|
|||
{
|
||||
title: 'https://www.rfc-editor.org/rfc/rfc7520#section-5.9 - Compressed Content',
|
||||
webcrypto: true,
|
||||
webapi: false,
|
||||
electron: false,
|
||||
reproducible: true,
|
||||
input: {
|
||||
|
|
@ -917,7 +907,13 @@ const vectors = [
|
|||
|
||||
for (const vector of vectors) {
|
||||
let run = test
|
||||
if (('WEBCRYPTO' in process.env || 'CRYPTOKEY' in process.env) && vector.webcrypto === false) {
|
||||
if (
|
||||
('WEBCRYPTO' in process.env || 'CRYPTOKEY' in process.env || 'WEBAPI' in process.env) &&
|
||||
vector.webcrypto === false
|
||||
) {
|
||||
run = run.failing
|
||||
}
|
||||
if ('WEBAPI' in process.env && vector.webapi === false) {
|
||||
run = run.failing
|
||||
}
|
||||
if ('electron' in process.versions && vector.electron === false) {
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
import test from 'ava'
|
||||
import * as crypto from 'crypto'
|
||||
import { root } from '../dist.mjs'
|
||||
|
||||
const root = !('WEBCRYPTO' in process.env) ? '#dist' : '#dist/webcrypto'
|
||||
const { FlattenedEncrypt, flattenedDecrypt, base64url } = await import(root)
|
||||
|
||||
test.before(async (t) => {
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
import test from 'ava'
|
||||
import { root } from '../dist.mjs'
|
||||
|
||||
const root = !('WEBCRYPTO' in process.env) ? '#dist' : '#dist/webcrypto'
|
||||
const { FlattenedEncrypt } = await import(root)
|
||||
|
||||
test.before(async (t) => {
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
import test from 'ava'
|
||||
import * as crypto from 'crypto'
|
||||
import { root } from '../dist.mjs'
|
||||
|
||||
const root = !('WEBCRYPTO' in process.env) ? '#dist' : '#dist/webcrypto'
|
||||
const { GeneralEncrypt, generalDecrypt, generateKeyPair, base64url } = await import(root)
|
||||
|
||||
test.before(async (t) => {
|
||||
|
|
|
|||
|
|
@ -1,17 +1,6 @@
|
|||
import test from 'ava'
|
||||
import * as crypto from 'crypto'
|
||||
|
||||
let root
|
||||
let keyRoot
|
||||
|
||||
if ('WEBCRYPTO' in process.env) {
|
||||
root = keyRoot = '#dist/webcrypto'
|
||||
} else if ('CRYPTOKEY' in process.env) {
|
||||
root = '#dist'
|
||||
keyRoot = '#dist/webcrypto'
|
||||
} else {
|
||||
root = keyRoot = '#dist'
|
||||
}
|
||||
import { conditional, root, keyRoot } from '../dist.mjs'
|
||||
|
||||
const {
|
||||
FlattenedEncrypt,
|
||||
|
|
@ -311,18 +300,6 @@ test(smoke, 'oct256c')
|
|||
test(smoke, 'oct384c')
|
||||
test(smoke, 'oct512c')
|
||||
|
||||
function conditional({ webcrypto = 1, electron = 1 } = {}) {
|
||||
let run = test
|
||||
if (!webcrypto && ('WEBCRYPTO' in process.env || 'CRYPTOKEY' in process.env)) {
|
||||
run = run.failing
|
||||
}
|
||||
|
||||
if (!electron && 'electron' in process.versions) {
|
||||
run = run.failing
|
||||
}
|
||||
return run
|
||||
}
|
||||
|
||||
conditional({ webcrypto: 0 })(smoke, 'rsa1_5')
|
||||
conditional({ webcrypto: 0, electron: 0 })(smoke, 'x25519kw')
|
||||
conditional({ webcrypto: 0 })(smoke, 'x25519dir')
|
||||
|
|
|
|||
|
|
@ -1,16 +1,5 @@
|
|||
import test from 'ava'
|
||||
|
||||
let root
|
||||
let keyRoot
|
||||
|
||||
if ('WEBCRYPTO' in process.env) {
|
||||
root = keyRoot = '#dist/webcrypto'
|
||||
} else if ('CRYPTOKEY' in process.env) {
|
||||
root = '#dist'
|
||||
keyRoot = '#dist/webcrypto'
|
||||
} else {
|
||||
root = keyRoot = '#dist'
|
||||
}
|
||||
import { root, keyRoot } from '../dist.mjs'
|
||||
|
||||
const { FlattenedSign, flattenedVerify } = await import(root)
|
||||
const { importJWK, EmbeddedJWK } = await import(keyRoot)
|
||||
|
|
|
|||
|
|
@ -1,16 +1,5 @@
|
|||
import test from 'ava'
|
||||
|
||||
let root
|
||||
let keyRoot
|
||||
|
||||
if ('WEBCRYPTO' in process.env) {
|
||||
root = keyRoot = '#dist/webcrypto'
|
||||
} else if ('CRYPTOKEY' in process.env) {
|
||||
root = '#dist'
|
||||
keyRoot = '#dist/webcrypto'
|
||||
} else {
|
||||
root = keyRoot = '#dist'
|
||||
}
|
||||
import { conditional, keyRoot } from '../dist.mjs'
|
||||
|
||||
const { importJWK, exportJWK } = await import(keyRoot)
|
||||
|
||||
|
|
@ -199,18 +188,6 @@ test('Uin8tArray can be transformed to a JWK', async (t) => {
|
|||
)
|
||||
})
|
||||
|
||||
function conditional({ webcrypto = 1, electron = 1 } = {}) {
|
||||
let run = test
|
||||
if (!webcrypto && ('WEBCRYPTO' in process.env || 'CRYPTOKEY' in process.env)) {
|
||||
run = run.failing
|
||||
}
|
||||
|
||||
if (!electron && 'electron' in process.versions) {
|
||||
run = run.failing
|
||||
}
|
||||
return run
|
||||
}
|
||||
|
||||
conditional({ webcrypto: 0 })('secret key object can be transformed to a JWK', async (t) => {
|
||||
const keylike = await importJWK(
|
||||
{
|
||||
|
|
|
|||
|
|
@ -1,16 +1,5 @@
|
|||
import test from 'ava'
|
||||
|
||||
let root
|
||||
let keyRoot
|
||||
|
||||
if ('WEBCRYPTO' in process.env) {
|
||||
root = keyRoot = '#dist/webcrypto'
|
||||
} else if ('CRYPTOKEY' in process.env) {
|
||||
root = '#dist'
|
||||
keyRoot = '#dist/webcrypto'
|
||||
} else {
|
||||
root = keyRoot = '#dist'
|
||||
}
|
||||
import { keyRoot } from '../dist.mjs'
|
||||
|
||||
const { calculateJwkThumbprint } = await import(keyRoot)
|
||||
|
||||
|
|
|
|||
|
|
@ -1,16 +1,5 @@
|
|||
import test from 'ava'
|
||||
|
||||
let root
|
||||
let keyRoot
|
||||
|
||||
if ('WEBCRYPTO' in process.env) {
|
||||
root = keyRoot = '#dist/webcrypto'
|
||||
} else if ('CRYPTOKEY' in process.env) {
|
||||
root = '#dist'
|
||||
keyRoot = '#dist/webcrypto'
|
||||
} else {
|
||||
root = keyRoot = '#dist'
|
||||
}
|
||||
import { root, keyRoot } from '../dist.mjs'
|
||||
|
||||
const {
|
||||
jwtVerify,
|
||||
|
|
|
|||
|
|
@ -3,18 +3,10 @@ import nock from 'nock'
|
|||
import timekeeper from 'timekeeper'
|
||||
import { createServer } from 'http'
|
||||
import { once } from 'events'
|
||||
import { root, keyRoot } from '../dist.mjs'
|
||||
|
||||
let root
|
||||
let keyRoot
|
||||
|
||||
if ('WEBCRYPTO' in process.env) {
|
||||
root = keyRoot = '#dist/webcrypto'
|
||||
} else if ('CRYPTOKEY' in process.env) {
|
||||
root = '#dist'
|
||||
keyRoot = '#dist/webcrypto'
|
||||
} else {
|
||||
root = keyRoot = '#dist'
|
||||
}
|
||||
const skipOnUndiciTest = 'WEBAPI' in process.env ? test.skip : test
|
||||
const skipOnUndiciTestSerial = 'WEBAPI' in process.env ? test.skip : test.serial
|
||||
|
||||
const {
|
||||
jwtVerify,
|
||||
|
|
@ -54,7 +46,7 @@ test.afterEach((t) => {
|
|||
|
||||
test.afterEach(() => timekeeper.reset())
|
||||
|
||||
test.serial('RemoteJWKSet', async (t) => {
|
||||
skipOnUndiciTestSerial('RemoteJWKSet', async (t) => {
|
||||
const keys = [
|
||||
{
|
||||
e: 'AQAB',
|
||||
|
|
@ -212,7 +204,7 @@ test.serial('RemoteJWKSet', async (t) => {
|
|||
}
|
||||
})
|
||||
|
||||
test.serial('refreshes the JWKS once off cooldown', async (t) => {
|
||||
skipOnUndiciTestSerial('refreshes the JWKS once off cooldown', async (t) => {
|
||||
timekeeper.freeze(now * 1000)
|
||||
let jwk = {
|
||||
crv: 'P-256',
|
||||
|
|
@ -256,7 +248,7 @@ test.serial('refreshes the JWKS once off cooldown', async (t) => {
|
|||
}
|
||||
})
|
||||
|
||||
test.serial('throws on invalid JWKSet', async (t) => {
|
||||
skipOnUndiciTestSerial('throws on invalid JWKSet', async (t) => {
|
||||
const scope = nock('https://as.example.com').get('/jwks').once().reply(200, 'null')
|
||||
|
||||
const url = new URL('https://as.example.com/jwks')
|
||||
|
|
@ -300,7 +292,7 @@ test.serial('throws on invalid JWKSet', async (t) => {
|
|||
})
|
||||
})
|
||||
|
||||
test('handles ENOTFOUND', async (t) => {
|
||||
skipOnUndiciTest('handles ENOTFOUND', async (t) => {
|
||||
nock.enableNetConnect()
|
||||
const url = new URL('https://op.example.com/jwks')
|
||||
const JWKS = createRemoteJWKSet(url)
|
||||
|
|
@ -309,7 +301,7 @@ test('handles ENOTFOUND', async (t) => {
|
|||
})
|
||||
})
|
||||
|
||||
test('handles ECONNREFUSED', async (t) => {
|
||||
skipOnUndiciTest('handles ECONNREFUSED', async (t) => {
|
||||
nock.enableNetConnect()
|
||||
const url = new URL('http://localhost:3001/jwks')
|
||||
const JWKS = createRemoteJWKSet(url)
|
||||
|
|
@ -318,7 +310,7 @@ test('handles ECONNREFUSED', async (t) => {
|
|||
})
|
||||
})
|
||||
|
||||
test('handles ECONNRESET', async (t) => {
|
||||
skipOnUndiciTest('handles ECONNRESET', async (t) => {
|
||||
nock.enableNetConnect()
|
||||
const url = new URL('http://localhost:3000/jwks')
|
||||
t.context.server.once('connection', (socket) => {
|
||||
|
|
@ -330,7 +322,7 @@ test('handles ECONNRESET', async (t) => {
|
|||
})
|
||||
})
|
||||
|
||||
test('handles a timeout', async (t) => {
|
||||
skipOnUndiciTest('handles a timeout', async (t) => {
|
||||
t.timeout(1000)
|
||||
nock.enableNetConnect()
|
||||
const url = new URL('http://localhost:3000/jwks')
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
import test from 'ava'
|
||||
import { root } from '../dist.mjs'
|
||||
|
||||
const root = !('WEBCRYPTO' in process.env) ? '#dist' : '#dist/webcrypto'
|
||||
const { CompactSign } = await import(root)
|
||||
|
||||
test.before((t) => {
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
import test from 'ava'
|
||||
import * as crypto from 'crypto'
|
||||
import { root } from '../dist.mjs'
|
||||
|
||||
const root = !('WEBCRYPTO' in process.env) ? '#dist' : '#dist/webcrypto'
|
||||
const { compactVerify, CompactSign } = await import(root)
|
||||
|
||||
test.before(async (t) => {
|
||||
|
|
|
|||
|
|
@ -1,16 +1,5 @@
|
|||
import test from 'ava'
|
||||
|
||||
let root
|
||||
let keyRoot
|
||||
|
||||
if ('WEBCRYPTO' in process.env) {
|
||||
root = keyRoot = '#dist/webcrypto'
|
||||
} else if ('CRYPTOKEY' in process.env) {
|
||||
root = '#dist'
|
||||
keyRoot = '#dist/webcrypto'
|
||||
} else {
|
||||
root = keyRoot = '#dist'
|
||||
}
|
||||
import { root, keyRoot } from '../dist.mjs'
|
||||
|
||||
const { FlattenedSign, flattenedVerify, CompactSign, compactVerify } = await import(root)
|
||||
const { importJWK } = await import(keyRoot)
|
||||
|
|
@ -479,7 +468,10 @@ const vectors = [
|
|||
|
||||
for (const vector of vectors) {
|
||||
let conditional
|
||||
if (('WEBCRYPTO' in process.env || 'CRYPTOKEY' in process.env) && vector.webcrypto === false) {
|
||||
if (
|
||||
('WEBCRYPTO' in process.env || 'CRYPTOKEY' in process.env || 'WEBAPI' in process.env) &&
|
||||
vector.webcrypto === false
|
||||
) {
|
||||
conditional = test.failing
|
||||
} else {
|
||||
conditional = test
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
import test from 'ava'
|
||||
import { root } from '../dist.mjs'
|
||||
|
||||
const root = !('WEBCRYPTO' in process.env) ? '#dist' : '#dist/webcrypto'
|
||||
const { FlattenedSign } = await import(root)
|
||||
|
||||
const encode = TextEncoder.prototype.encode.bind(new TextEncoder())
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
import test from 'ava'
|
||||
import { root } from '../dist.mjs'
|
||||
|
||||
const root = !('WEBCRYPTO' in process.env) ? '#dist' : '#dist/webcrypto'
|
||||
const { FlattenedSign } = await import(root)
|
||||
|
||||
test.before(async (t) => {
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
import test from 'ava'
|
||||
import * as crypto from 'crypto'
|
||||
import { root } from '../dist.mjs'
|
||||
|
||||
const root = !('WEBCRYPTO' in process.env) ? '#dist' : '#dist/webcrypto'
|
||||
const { FlattenedSign, flattenedVerify } = await import(root)
|
||||
|
||||
test.before(async (t) => {
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
import test from 'ava'
|
||||
import * as crypto from 'crypto'
|
||||
import { root } from '../dist.mjs'
|
||||
|
||||
const root = !('WEBCRYPTO' in process.env) ? '#dist' : '#dist/webcrypto'
|
||||
const { GeneralSign, generalVerify } = await import(root)
|
||||
|
||||
test.before(async (t) => {
|
||||
|
|
|
|||
|
|
@ -1,17 +1,6 @@
|
|||
import test from 'ava'
|
||||
import * as crypto from 'crypto'
|
||||
|
||||
let root
|
||||
let keyRoot
|
||||
|
||||
if ('WEBCRYPTO' in process.env) {
|
||||
root = keyRoot = '#dist/webcrypto'
|
||||
} else if ('CRYPTOKEY' in process.env) {
|
||||
root = '#dist'
|
||||
keyRoot = '#dist/webcrypto'
|
||||
} else {
|
||||
root = keyRoot = '#dist'
|
||||
}
|
||||
import { conditional, root, keyRoot } from '../dist.mjs'
|
||||
|
||||
const { FlattenedSign, flattenedVerify, FlattenedEncrypt, flattenedDecrypt, base64url } =
|
||||
await import(root)
|
||||
|
|
@ -127,17 +116,5 @@ test(testECDSASigEncoding, 'ES256')
|
|||
test(testECDSASigEncoding, 'ES384')
|
||||
test(testECDSASigEncoding, 'ES512')
|
||||
|
||||
function conditional({ webcrypto = 1, electron = 1 } = {}) {
|
||||
let run = test
|
||||
if (!webcrypto && ('WEBCRYPTO' in process.env || 'CRYPTOKEY' in process.env)) {
|
||||
run = run.failing
|
||||
}
|
||||
|
||||
if (!electron && 'electron' in process.versions) {
|
||||
run = run.failing
|
||||
}
|
||||
return run
|
||||
}
|
||||
|
||||
conditional({ webcrypto: 0 })(testRSAenc, 'RSA1_5')
|
||||
conditional({ webcrypto: 0, electron: 0 })(testECDSASigEncoding, 'ES256K')
|
||||
|
|
|
|||
|
|
@ -1,17 +1,6 @@
|
|||
import test from 'ava'
|
||||
import * as crypto from 'crypto'
|
||||
|
||||
let root
|
||||
let keyRoot
|
||||
|
||||
if ('WEBCRYPTO' in process.env) {
|
||||
root = keyRoot = '#dist/webcrypto'
|
||||
} else if ('CRYPTOKEY' in process.env) {
|
||||
root = '#dist'
|
||||
keyRoot = '#dist/webcrypto'
|
||||
} else {
|
||||
root = keyRoot = '#dist'
|
||||
}
|
||||
import { conditional, root, keyRoot } from '../dist.mjs'
|
||||
|
||||
const {
|
||||
FlattenedSign,
|
||||
|
|
@ -208,18 +197,6 @@ test('as keyobject', smoke, 'oct256', true)
|
|||
test('as keyobject', smoke, 'oct384', true)
|
||||
test('as keyobject', smoke, 'oct512', true)
|
||||
|
||||
function conditional({ webcrypto = 1, electron = 1 } = {}) {
|
||||
let run = test
|
||||
if (!webcrypto && ('WEBCRYPTO' in process.env || 'CRYPTOKEY' in process.env)) {
|
||||
run = run.failing
|
||||
}
|
||||
|
||||
if (!electron && 'electron' in process.versions) {
|
||||
run = run.failing
|
||||
}
|
||||
return run
|
||||
}
|
||||
|
||||
conditional({ webcrypto: 0, electron: 0 })(smoke, 'secp256k1')
|
||||
conditional({ webcrypto: 1 })(smoke, 'ed25519')
|
||||
conditional({ webcrypto: 1, electron: 0 })(smoke, 'ed448')
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
import test from 'ava'
|
||||
import { root } from '../dist.mjs'
|
||||
|
||||
const root = !('WEBCRYPTO' in process.env) ? '#dist' : '#dist/webcrypto'
|
||||
const { FlattenedSign, flattenedVerify } = await import(root)
|
||||
const encode = TextEncoder.prototype.encode.bind(new TextEncoder())
|
||||
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
import test from 'ava'
|
||||
import timekeeper from 'timekeeper'
|
||||
import { root } from '../dist.mjs'
|
||||
|
||||
const root = !('WEBCRYPTO' in process.env) ? '#dist' : '#dist/webcrypto'
|
||||
const { EncryptJWT, jwtDecrypt, CompactEncrypt } = await import(root)
|
||||
|
||||
const now = 1604416038
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
import test from 'ava'
|
||||
import timekeeper from 'timekeeper'
|
||||
import { root } from '../dist.mjs'
|
||||
|
||||
const root = !('WEBCRYPTO' in process.env) ? '#dist' : '#dist/webcrypto'
|
||||
const { EncryptJWT, compactDecrypt, jwtDecrypt } = await import(root)
|
||||
|
||||
const now = 1604416038
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
import test from 'ava'
|
||||
import timekeeper from 'timekeeper'
|
||||
import { root } from '../dist.mjs'
|
||||
|
||||
const root = !('WEBCRYPTO' in process.env) ? '#dist' : '#dist/webcrypto'
|
||||
const { SignJWT, compactVerify, jwtVerify } = await import(root)
|
||||
|
||||
const now = 1604416038
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
import test from 'ava'
|
||||
import timekeeper from 'timekeeper'
|
||||
import { root } from '../dist.mjs'
|
||||
|
||||
const root = !('WEBCRYPTO' in process.env) ? '#dist' : '#dist/webcrypto'
|
||||
const { UnsecuredJWT } = await import(root)
|
||||
|
||||
const now = 1604416038
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
import test from 'ava'
|
||||
import timekeeper from 'timekeeper'
|
||||
import { root } from '../dist.mjs'
|
||||
|
||||
const root = !('WEBCRYPTO' in process.env) ? '#dist' : '#dist/webcrypto'
|
||||
const { SignJWT, jwtVerify, CompactSign } = await import(root)
|
||||
|
||||
const now = 1604416038
|
||||
|
|
|
|||
|
|
@ -1,31 +1,8 @@
|
|||
import test from 'ava'
|
||||
|
||||
let root
|
||||
let keyRoot
|
||||
|
||||
if ('WEBCRYPTO' in process.env) {
|
||||
root = keyRoot = '#dist/webcrypto'
|
||||
} else if ('CRYPTOKEY' in process.env) {
|
||||
root = '#dist'
|
||||
keyRoot = '#dist/webcrypto'
|
||||
} else {
|
||||
root = keyRoot = '#dist'
|
||||
}
|
||||
import { conditional, keyRoot } from '../dist.mjs'
|
||||
|
||||
const jose = await import(keyRoot)
|
||||
|
||||
function conditional({ webcrypto = 1, electron = 1 } = {}) {
|
||||
let run = test
|
||||
if (!webcrypto && ('WEBCRYPTO' in process.env || 'CRYPTOKEY' in process.env)) {
|
||||
run = run.failing
|
||||
}
|
||||
|
||||
if (!electron && 'electron' in process.versions) {
|
||||
run = run.failing
|
||||
}
|
||||
return run
|
||||
}
|
||||
|
||||
const keys = {
|
||||
rsa: {
|
||||
privateKey:
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
import test from 'ava'
|
||||
import { root } from '../dist.mjs'
|
||||
|
||||
const root = !('WEBCRYPTO' in process.env) ? '#dist' : '#dist/webcrypto'
|
||||
const { uint32be } = await import(`${root}/lib/buffer_utils`)
|
||||
|
||||
test('lib/buffer_utils.ts', (t) => {
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
import test from 'ava'
|
||||
import { root } from '../dist.mjs'
|
||||
|
||||
const root = !('WEBCRYPTO' in process.env) ? '#dist' : '#dist/webcrypto'
|
||||
const { default: cek } = await import(`${root}/lib/cek`)
|
||||
|
||||
test('lib/cek.ts', (t) => {
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
import test from 'ava'
|
||||
import { root } from '../dist.mjs'
|
||||
|
||||
const root = !('WEBCRYPTO' in process.env) ? '#dist' : '#dist/webcrypto'
|
||||
const { default: checkIvLength } = await import(`${root}/lib/check_iv_length`)
|
||||
|
||||
test('lib/check_iv_length.ts', (t) => {
|
||||
|
|
|
|||
|
|
@ -1,20 +1,9 @@
|
|||
import test from 'ava'
|
||||
|
||||
let root
|
||||
let keyRoot
|
||||
|
||||
if ('WEBCRYPTO' in process.env) {
|
||||
root = keyRoot = '#dist/webcrypto'
|
||||
} else if ('CRYPTOKEY' in process.env) {
|
||||
root = '#dist'
|
||||
keyRoot = '#dist/webcrypto'
|
||||
} else {
|
||||
root = keyRoot = '#dist'
|
||||
}
|
||||
import { root, keyRoot } from '../dist.mjs'
|
||||
|
||||
let types = 'KeyObject or Uint8Array'
|
||||
let asymmetricTypes = 'KeyObject'
|
||||
if ('WEBCRYPTO' in process.env) {
|
||||
if ('WEBCRYPTO' in process.env || 'WEBAPI' in process.env) {
|
||||
types = 'CryptoKey or Uint8Array'
|
||||
asymmetricTypes = 'CryptoKey'
|
||||
} else if (parseInt(process.versions.node) >= 16) {
|
||||
|
|
@ -78,7 +67,7 @@ test('lib/check_key_type.ts', async (t) => {
|
|||
message: `${asymmetricTypes} instances for symmetric algorithms must be of type "secret"`,
|
||||
})
|
||||
|
||||
if (keyRoot.includes('webcrypto')) {
|
||||
if (keyRoot.includes('web')) {
|
||||
t.throws(() => checkKeyType('PS256', keypair.privateKey, 'verify'), {
|
||||
...expected,
|
||||
message: `${asymmetricTypes} instances for asymmetric algorithm verifying must be of type "public"`,
|
||||
|
|
@ -93,7 +82,7 @@ test('lib/check_key_type.ts', async (t) => {
|
|||
message: `${asymmetricTypes} instances for asymmetric algorithm decryption must be of type "private"`,
|
||||
})
|
||||
|
||||
if (keyRoot.includes('webcrypto')) {
|
||||
if (keyRoot.includes('web')) {
|
||||
t.throws(() => checkKeyType('ECDH-ES', keypair.privateKey, 'encrypt'), {
|
||||
...expected,
|
||||
message: `${asymmetricTypes} instances for asymmetric algorithm encryption must be of type "public"`,
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
import test from 'ava'
|
||||
import { root } from '../dist.mjs'
|
||||
|
||||
const root = !('WEBCRYPTO' in process.env) ? '#dist' : '#dist/webcrypto'
|
||||
const { default: checkP2s } = await import(`${root}/lib/check_p2s`)
|
||||
|
||||
test('lib/check_p2s.ts', (t) => {
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
import test from 'ava'
|
||||
import { root } from '../dist.mjs'
|
||||
|
||||
const root = !('WEBCRYPTO' in process.env) ? '#dist' : '#dist/webcrypto'
|
||||
const { default: iv } = await import(`${root}/lib/iv`)
|
||||
|
||||
test('lib/iv.ts', (t) => {
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
import test from 'ava'
|
||||
import { root } from '../dist.mjs'
|
||||
|
||||
const root = !('WEBCRYPTO' in process.env) ? '#dist' : '#dist/webcrypto'
|
||||
const { default: secs } = await import(`${root}/lib/secs`)
|
||||
|
||||
test('lib/secs.ts', (t) => {
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
import test from 'ava'
|
||||
import { root } from '../dist.mjs'
|
||||
|
||||
const root = !('WEBCRYPTO' in process.env) ? '#dist' : '#dist/webcrypto'
|
||||
const { decodeJwt, errors, base64url } = await import(root)
|
||||
|
||||
test('invalid inputs', (t) => {
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
import test from 'ava'
|
||||
import { root } from '../dist.mjs'
|
||||
|
||||
const root = !('WEBCRYPTO' in process.env) ? '#dist' : '#dist/webcrypto'
|
||||
const { decodeProtectedHeader } = await import(root)
|
||||
|
||||
test('invalid inputs', (t) => {
|
||||
|
|
|
|||
|
|
@ -1,16 +1,5 @@
|
|||
import test from 'ava'
|
||||
|
||||
let root
|
||||
let keyRoot
|
||||
|
||||
if ('WEBCRYPTO' in process.env) {
|
||||
root = keyRoot = '#dist/webcrypto'
|
||||
} else if ('CRYPTOKEY' in process.env) {
|
||||
root = '#dist'
|
||||
keyRoot = '#dist/webcrypto'
|
||||
} else {
|
||||
root = keyRoot = '#dist'
|
||||
}
|
||||
import { conditional, root, keyRoot } from '../dist.mjs'
|
||||
|
||||
const { generateKeyPair, generateSecret } = await import(keyRoot)
|
||||
|
||||
|
|
@ -143,18 +132,6 @@ if ('WEBCRYPTO' in process.env || 'CRYPTOKEY' in process.env) {
|
|||
test('with extractable: true', testKeyPair, 'PS256', { extractable: true })
|
||||
}
|
||||
|
||||
function conditional({ webcrypto = 1, electron = 1 } = {}) {
|
||||
let run = test
|
||||
if (!webcrypto && ('WEBCRYPTO' in process.env || 'CRYPTOKEY' in process.env)) {
|
||||
run = run.failing
|
||||
}
|
||||
|
||||
if (!electron && 'electron' in process.versions) {
|
||||
run = run.failing
|
||||
}
|
||||
return run
|
||||
}
|
||||
|
||||
conditional({ webcrypto: 1 })(testKeyPair, 'EdDSA')
|
||||
conditional({ webcrypto: 1 })('crv: Ed25519', testKeyPair, 'EdDSA', { crv: 'Ed25519' })
|
||||
conditional({ webcrypto: 1, electron: 0 })('crv: Ed448', testKeyPair, 'EdDSA', {
|
||||
|
|
|
|||
Loading…
Reference in a new issue