add a few more tests

This commit is contained in:
AJ ONeal 2019-03-15 13:53:49 -06:00
parent 5060c505b6
commit e6de23532b
1 changed files with 49 additions and 36 deletions

View File

@ -23,7 +23,8 @@ keyfetch.oidcJwks(testIss).then(function (hits) {
/*global Promise*/
var keypairs = require('keypairs.js');
keypairs.generate().then(function (pair) {
return keypairs.signJwt({
return Promise.all([
keypairs.signJwt({
jwk: pair.private, iss: 'https://example.com/', sub: 'mikey', exp: '1h'
}).then(function (jwt) {
return Promise.all([
@ -52,6 +53,19 @@ keypairs.generate().then(function (pair) {
, keyfetch.jwt.verify(jwt, { jwk: pair.public, claims: { iss: 'https://example.com/' } })
, keyfetch.jwt.verify(jwt, { jwk: pair.public, claims: { iss: 'https://example.com' } })
.then(e("inexact claim")).catch(throwIfNotExpected)
]);
})
, keypairs.signJwt({
jwk: pair.private, iss: false, sub: 'mikey', exp: '1h'
}).then(function (jwt) {
return Promise.all([
keyfetch.jwt.verify(jwt, { jwk: pair.public })
, keyfetch.jwt.verify(jwt)
.then(e("should have an issuer")).catch(throwIfNotExpected)
, keyfetch.jwt.verify(jwt, { jwk: pair.public, issuers: ['https://example.com/'] })
.then(e("fail when issuer specified and doesn't exist")).catch(throwIfNotExpected)
]);
})
]).then(function () {
console.log("JWT PASSES");
}).catch(function (err) {
@ -59,7 +73,6 @@ keypairs.generate().then(function (pair) {
console.error(err);
process.exit(1);
});
});
});
/*
var jwt = '...';