Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

raise error on undefined secrets #65

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/sign-stream.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ function SignStream(opts) {
this.header = opts.header;
this.encoding = opts.encoding;
this.secret = this.privateKey = this.key = secretStream;
if (this.secret == undefined) return;
this.payload = new DataStream(opts.payload);
this.secret.once('close', function () {
if (!this.payload.writable && this.readable)
Expand Down
20 changes: 19 additions & 1 deletion test/jws.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ const rsaPrivateKeyEncrypted = readfile('rsa-private-encrypted.pem');
const encryptedPassphrase = readfile('encrypted-key-passphrase');
const rsaPublicKey = readfile('rsa-public.pem');
const rsaWrongPublicKey = readfile('rsa-wrong-public.pem');
const undefinedKey = undefined;
const ecdsaPrivateKey = {
'256': readfile('ec256-private.pem'),
'384': readfile('ec384-private.pem'),
Expand Down Expand Up @@ -69,6 +70,24 @@ BITS.forEach(function (bits) {
});
});

BITS.forEach(function (bits) {
test('HMAC using SHA-'+bits+' hash algorithm undefined key test', function (t) {
const alg = 'HS'+bits;
const header = { alg: alg, typ: 'JWT' };
const secret = undefinedKey;
var parts;
t.throws(function () {
parts = jws.sign({
header: header,
payload: payload,
secret: secret,
encoding: 'utf8',
});
})
t.end();
});
});

BITS.forEach(function (bits) {
test('RSASSA using SHA-'+bits+' hash algorithm', function (t) {
const alg = 'RS'+bits;
Expand Down Expand Up @@ -317,7 +336,6 @@ test('jws.verify: missing or invalid algorithm', function (t) {
t.end();
});


test('jws.isValid', function (t) {
const valid = jws.sign({ header: { alg: 'hs256' }, payload: 'hi', secret: 'shhh' });
const invalid = (function(){
Expand Down