-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a513a65
commit 399fbbc
Showing
12 changed files
with
267 additions
and
95 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
import test from 'ava'; | ||
import test from './tester.js'; | ||
|
||
test('sync test', (t) => { | ||
t.pass(); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
/** @typedef {import('ava').TestFn} AvaTestFn */ | ||
|
||
// @ts-ignore Custom cast | ||
export default await (async () => { | ||
if ('Deno' in globalThis) { | ||
const denoAsserts = await import('https://deno.land/[email protected]/testing/asserts.ts'); | ||
/** | ||
* | ||
* @param {string} title | ||
* @param {import('ava').ImplementationFn<any, any>} implementation | ||
*/ | ||
// eslint-disable-next-line no-inner-declarations | ||
function test(title, implementation) { | ||
Deno.test(title, async (t) => { | ||
/** @type {import('ava').ExecutionContext} T */ | ||
const wrapper = { | ||
assert: denoAsserts.assertStrictEquals, | ||
deepEqual: denoAsserts.assertEquals, | ||
// like | ||
fail: denoAsserts.fail, | ||
false(actual, message) { | ||
denoAsserts.assertStrictEquals(actual, false, message); | ||
return true; | ||
}, | ||
falsy(actual, message) { | ||
denoAsserts.assertStrictEquals(!actual, true, message); | ||
return true; | ||
}, | ||
is: denoAsserts.assertStrictEquals, | ||
not(actual, expected) { | ||
denoAsserts.assertStrictEquals(!Object.is(actual, expected), true); | ||
}, | ||
notDeepEqual: denoAsserts.assertNotEquals, | ||
notRegex: denoAsserts.notMatch, | ||
notThrows(fn, message) { | ||
try { | ||
fn(); | ||
} catch { | ||
this.fail(message); | ||
} | ||
}, | ||
async notThrowsAsync(fn, message) { | ||
try { | ||
await fn(); | ||
} catch { | ||
this.fail(message); | ||
} | ||
}, | ||
pass(message) { | ||
denoAsserts.assert(true, message); | ||
}, | ||
regex: denoAsserts.assertMatch, | ||
// snapshot | ||
throws: denoAsserts.assertThrows, | ||
async throwsAsync(fn, expectations, message) { | ||
try { | ||
await fn(); | ||
this.fail(message); | ||
} catch (e) { | ||
this.throws(() => { throw e; }, expectations, message); | ||
} | ||
}, | ||
true(actual, message) { | ||
denoAsserts.assertStrictEquals(actual, true, message); | ||
}, | ||
truthy(actual, message) { | ||
denoAsserts.assert(actual, message); | ||
}, | ||
log: console.debug, | ||
}; | ||
await implementation(wrapper); | ||
}); | ||
} | ||
return test; | ||
} | ||
if ('window' in globalThis) { | ||
// TODO: Tap into browser-based tester | ||
return null; | ||
} | ||
// Node | ||
const ava = await import('ava'); | ||
return ava.default; | ||
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import { formatPEM, pemFromPKCS1, pemFromPKCS8, pkcs1FromPKCS8, pkcs8FromPKCS1 } from '../../utils/certificate.js'; | ||
import test from '../tester.js'; | ||
|
||
const FIXTURES = { | ||
PKCS1: formatPEM(` | ||
-----BEGIN RSA PRIVATE KEY----- | ||
MIIBOgIBAAJBAKj34GkxFhD90vcNLYLInFEX6Ppy1tPf9Cnzj4p4WGeKLs1Pt8Qu | ||
KUpRKfFLfRYC9AIKjbJTWit+CqvjWYzvQwECAwEAAQJAIJLixBy2qpFoS4DSmoEm | ||
o3qGy0t6z09AIJtH+5OeRV1be+N4cDYJKffGzDa88vQENZiRm0GRq6a+HPGQMd2k | ||
TQIhAKMSvzIBnni7ot/OSie2TmJLY4SwTQAevXysE2RbFDYdAiEBCUEaRQnMnbp7 | ||
9mxDXDf6AU0cN/RPBjb9qSHDcWZHGzUCIG2Es59z8ugGrDY+pxLQnwfotadxd+Uy | ||
v/Ow5T0q5gIJAiEAyS4RaI9YG8EWx/2w0T67ZUVAw8eOMB6BIUg0Xcu+3okCIBOs | ||
/5OiPgoTdSy7bcF9IGpSE8ZgGKzgYQVZeN97YE00 | ||
-----END RSA PRIVATE KEY----- | ||
`), | ||
PKCS8: formatPEM(` | ||
-----BEGIN PRIVATE KEY----- | ||
MIIBVAIBADANBgkqhkiG9w0BAQEFAASCAT4wggE6AgEAAkEAqPfgaTEWEP3S9w0t | ||
gsicURfo+nLW09/0KfOPinhYZ4ouzU+3xC4pSlEp8Ut9FgL0AgqNslNaK34Kq+NZ | ||
jO9DAQIDAQABAkAgkuLEHLaqkWhLgNKagSajeobLS3rPT0Agm0f7k55FXVt743hw | ||
Ngkp98bMNrzy9AQ1mJGbQZGrpr4c8ZAx3aRNAiEAoxK/MgGeeLui385KJ7ZOYktj | ||
hLBNAB69fKwTZFsUNh0CIQEJQRpFCcydunv2bENcN/oBTRw39E8GNv2pIcNxZkcb | ||
NQIgbYSzn3Py6AasNj6nEtCfB+i1p3F35TK/87DlPSrmAgkCIQDJLhFoj1gbwRbH | ||
/bDRPrtlRUDDx44wHoEhSDRdy77eiQIgE6z/k6I+ChN1LLttwX0galITxmAYrOBh | ||
BVl433tgTTQ= | ||
-----END PRIVATE KEY----- | ||
`), | ||
}; | ||
|
||
test('pkcs8FromPKCS1', (t) => { | ||
const der = pkcs8FromPKCS1(FIXTURES.PKCS1); | ||
const pem = pemFromPKCS8(der); | ||
t.is(pem, FIXTURES.PKCS8); | ||
}); | ||
|
||
test('pkcs1FromPKCS8', (t) => { | ||
const der = pkcs1FromPKCS8(FIXTURES.PKCS8); | ||
const pem = pemFromPKCS1(der); | ||
t.is(pem, FIXTURES.PKCS1); | ||
}); |
Oops, something went wrong.