kopia lustrzana https://gitlab.com/rysiekpl/libresilient
cli: test for signed-integrity gen-keypair action (ref. #66)
rodzic
a6985e8521
commit
7858687e5b
|
@ -3,7 +3,8 @@ import {
|
||||||
assertThrows,
|
assertThrows,
|
||||||
assertRejects,
|
assertRejects,
|
||||||
assertEquals,
|
assertEquals,
|
||||||
assertStringIncludes
|
assertStringIncludes,
|
||||||
|
assertObjectMatch
|
||||||
} from "https://deno.land/std@0.167.0/testing/asserts.ts";
|
} from "https://deno.land/std@0.167.0/testing/asserts.ts";
|
||||||
|
|
||||||
// this needs to be the same as the pubkey in:
|
// this needs to be the same as the pubkey in:
|
||||||
|
@ -271,3 +272,63 @@ Deno.test("gen-integrity signs the data correctly", async () => {
|
||||||
jwt['./__denotests__/mocks/hello.txt'],
|
jwt['./__denotests__/mocks/hello.txt'],
|
||||||
pubkey))
|
pubkey))
|
||||||
})
|
})
|
||||||
|
|
||||||
|
Deno.test("get-pubkey works correctly", async () => {
|
||||||
|
const bi = await import('../../plugins/signed-integrity/cli.js')
|
||||||
|
const gp = bi.actions["get-pubkey"]
|
||||||
|
assertRejects(gp.run, Error, "No keyfile provided.")
|
||||||
|
assertRejects(async ()=>{
|
||||||
|
await gp.run('no-such-file')
|
||||||
|
}, Error, "No such file or directory")
|
||||||
|
assertRejects(async ()=>{
|
||||||
|
await gp.run(['no-such-file'])
|
||||||
|
}, Error, "No such file or directory")
|
||||||
|
assertEquals(
|
||||||
|
await gp.run('./__denotests__/mocks/keyfile.json'),
|
||||||
|
'{"kty":"EC","crv":"P-384","alg":"ES384","x":"rrFawYTuFo8ZjoDxaztUU-c_RAwjw1Y9Tp3j4nH4WsY2Zlizf40Mvz_0BUkVVZCw","y":"HaFct6PVK2CQ7ZT2SHClnN-knmGfjY_DFwc6qrAu1s0DFZ8fEUuNdmkTlj9T4NQw","key_ops":["verify"],"ext":true}'
|
||||||
|
)
|
||||||
|
assertEquals(
|
||||||
|
await gp.run(['./__denotests__/mocks/keyfile.json', 'irrelevant']),
|
||||||
|
'{"kty":"EC","crv":"P-384","alg":"ES384","x":"rrFawYTuFo8ZjoDxaztUU-c_RAwjw1Y9Tp3j4nH4WsY2Zlizf40Mvz_0BUkVVZCw","y":"HaFct6PVK2CQ7ZT2SHClnN-knmGfjY_DFwc6qrAu1s0DFZ8fEUuNdmkTlj9T4NQw","key_ops":["verify"],"ext":true}'
|
||||||
|
)
|
||||||
|
});
|
||||||
|
|
||||||
|
Deno.test("gen-keypair works correctly", async () => {
|
||||||
|
const bi = await import('../../plugins/signed-integrity/cli.js')
|
||||||
|
const gk = bi.actions["gen-keypair"]
|
||||||
|
const keypair = JSON.parse(await gk.run())
|
||||||
|
assert('privateKey' in keypair)
|
||||||
|
assert('x' in keypair.privateKey)
|
||||||
|
assert('y' in keypair.privateKey)
|
||||||
|
assert('d' in keypair.privateKey)
|
||||||
|
assertObjectMatch(
|
||||||
|
keypair.privateKey,
|
||||||
|
{
|
||||||
|
kty: "EC",
|
||||||
|
crv: "P-384",
|
||||||
|
alg: "ES384",
|
||||||
|
key_ops: [
|
||||||
|
"sign"
|
||||||
|
],
|
||||||
|
ext: true
|
||||||
|
}
|
||||||
|
)
|
||||||
|
assert('publicKey' in keypair)
|
||||||
|
assert('x' in keypair.publicKey)
|
||||||
|
assert('y' in keypair.publicKey)
|
||||||
|
assert(!('d' in keypair.publicKey))
|
||||||
|
assertObjectMatch(
|
||||||
|
keypair.publicKey,
|
||||||
|
{
|
||||||
|
kty: "EC",
|
||||||
|
crv: "P-384",
|
||||||
|
alg: "ES384",
|
||||||
|
key_ops: [
|
||||||
|
"verify"
|
||||||
|
],
|
||||||
|
ext: true
|
||||||
|
}
|
||||||
|
)
|
||||||
|
assert((keypair.privateKey.x == keypair.publicKey.x))
|
||||||
|
assert((keypair.privateKey.y == keypair.publicKey.y))
|
||||||
|
});
|
||||||
|
|
Ładowanie…
Reference in New Issue