-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Remove joi to shrink module size #348
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
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,136 @@ | ||
var jwt = require('../index'); | ||
var expect = require('chai').expect; | ||
var fs = require('fs'); | ||
|
||
describe('schema', function() { | ||
|
||
describe('sign options', function() { | ||
|
||
var cert_rsa_priv = fs.readFileSync(__dirname + '/rsa-private.pem'); | ||
var cert_ecdsa_priv = fs.readFileSync(__dirname + '/ecdsa-private.pem'); | ||
|
||
function sign(options) { | ||
var isEcdsa = options.algorithm && options.algorithm.indexOf('ES') === 0; | ||
jwt.sign({foo: 123}, isEcdsa ? cert_ecdsa_priv : cert_rsa_priv, options); | ||
} | ||
|
||
it('should validate expiresIn', function () { | ||
expect(function () { | ||
sign({ expiresIn: '1 monkey' }); | ||
}).to.throw(/"expiresIn" should be a number of seconds or string representing a timespan/); | ||
expect(function () { | ||
sign({ expiresIn: 1.1 }); | ||
}).to.throw(/"expiresIn" should be a number of seconds or string representing a timespan/); | ||
sign({ expiresIn: '10s' }); | ||
sign({ expiresIn: 10 }); | ||
}); | ||
|
||
it('should validate notBefore', function () { | ||
expect(function () { | ||
sign({ notBefore: '1 monkey' }); | ||
}).to.throw(/"notBefore" should be a number of seconds or string representing a timespan/); | ||
expect(function () { | ||
sign({ notBefore: 1.1 }); | ||
}).to.throw(/"notBefore" should be a number of seconds or string representing a timespan/); | ||
sign({ notBefore: '10s' }); | ||
sign({ notBefore: 10 }); | ||
}); | ||
|
||
it('should validate audience', function () { | ||
expect(function () { | ||
sign({ audience: 10 }); | ||
}).to.throw(/"audience" must be a string or array/); | ||
sign({ audience: 'urn:foo' }); | ||
sign({ audience: ['urn:foo'] }); | ||
}); | ||
|
||
it('should validate algorithm', function () { | ||
expect(function () { | ||
sign({ algorithm: 'foo' }); | ||
}).to.throw(/"algorithm" must be a valid string enum value/); | ||
sign({algorithm: 'RS256'}); | ||
sign({algorithm: 'RS384'}); | ||
sign({algorithm: 'RS512'}); | ||
sign({algorithm: 'ES256'}); | ||
sign({algorithm: 'ES384'}); | ||
sign({algorithm: 'ES512'}); | ||
sign({algorithm: 'HS256'}); | ||
sign({algorithm: 'HS384'}); | ||
sign({algorithm: 'HS512'}); | ||
sign({algorithm: 'none'}); | ||
}); | ||
|
||
it('should validate header', function () { | ||
expect(function () { | ||
sign({ header: 'foo' }); | ||
}).to.throw(/"header" must be an object/); | ||
sign({header: {}}); | ||
}); | ||
|
||
it('should validate encoding', function () { | ||
expect(function () { | ||
sign({ encoding: 10 }); | ||
}).to.throw(/"encoding" must be a string/); | ||
sign({encoding: 'utf8'}); | ||
}); | ||
|
||
it('should validate issuer', function () { | ||
expect(function () { | ||
sign({ issuer: 10 }); | ||
}).to.throw(/"issuer" must be a string/); | ||
sign({issuer: 'foo'}); | ||
}); | ||
|
||
it('should validate subject', function () { | ||
expect(function () { | ||
sign({ subject: 10 }); | ||
}).to.throw(/"subject" must be a string/); | ||
sign({subject: 'foo'}); | ||
}); | ||
|
||
it('should validate noTimestamp', function () { | ||
expect(function () { | ||
sign({ noTimestamp: 10 }); | ||
}).to.throw(/"noTimestamp" must be a boolean/); | ||
sign({noTimestamp: true}); | ||
}); | ||
|
||
it('should validate keyid', function () { | ||
expect(function () { | ||
sign({ keyid: 10 }); | ||
}).to.throw(/"keyid" must be a string/); | ||
sign({keyid: 'foo'}); | ||
}); | ||
|
||
}); | ||
|
||
describe('sign payload registered claims', function() { | ||
|
||
function sign(payload) { | ||
jwt.sign(payload, 'foo123'); | ||
} | ||
|
||
it('should validate iat', function () { | ||
expect(function () { | ||
sign({ iat: '1 monkey' }); | ||
}).to.throw(/"iat" should be a number of seconds/); | ||
sign({ iat: 10.1 }); | ||
}); | ||
|
||
it('should validate exp', function () { | ||
expect(function () { | ||
sign({ exp: '1 monkey' }); | ||
}).to.throw(/"exp" should be a number of seconds/); | ||
sign({ exp: 10.1 }); | ||
}); | ||
|
||
it('should validate nbf', function () { | ||
expect(function () { | ||
sign({ nbf: '1 monkey' }); | ||
}).to.throw(/"nbf" should be a number of seconds/); | ||
sign({ nbf: 10.1 }); | ||
}); | ||
|
||
}); | ||
|
||
}); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do you remove it? is it because with this PR it is tested in the schema test? (if so, I'm ok with that)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, that's correct.