Skip to content

Commit

Permalink
Clean up token creation for form post tests
Browse files Browse the repository at this point in the history
  • Loading branch information
joshcanhelp committed Dec 13, 2019
1 parent 1948f1b commit 607f166
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 26 deletions.
2 changes: 1 addition & 1 deletion EXAMPLES.md
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ app.use(auth({
handleCallback: async function (req, res, next) {
const client = req.openid.client;
try {
req.session.openidTokens.userinfo = await client.userinfo(req.session.openidTokens);
req.session.userinfo = await client.userinfo(req.session.openidTokens);
next();
} catch(e) {
next(e);
Expand Down
45 changes: 20 additions & 25 deletions test/callback_route_form_post.tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,22 @@ function testCase(params) {
};
}

function makeIdToken(payload) {
if (typeof payload !== 'object' ) {
payload = {
'nickname': '__test_nickname__',
'iss': 'https://test.auth0.com/',
'sub': '__test_sub__',
'aud': clientID,
'iat': Math.round(Date.now() / 1000),
'exp': Math.round(Date.now() / 1000) + 60000,
'nonce': '__test_nonce__'
};
}

return jwt.sign(payload, cert.key, { algorithm: 'RS256', header: { kid: cert.kid } });
}

//For the purpose of this test the fake SERVER returns the error message in the body directly
//production application should have an error middleware.
//http://expressjs.com/en/guide/error-handling.html
Expand Down Expand Up @@ -162,7 +178,7 @@ describe('callback routes response_type: id_token, response_mode: form_post', fu
},
body: {
state: '__test_state__',
id_token: jwt.sign({sub: '__test_sub__'}, cert.key, { algorithm: 'RS256' })
id_token: makeIdToken({sub: '__test_sub__'})
},
assertions() {
it('should return 400', function() {
Expand All @@ -182,13 +198,7 @@ describe('callback routes response_type: id_token, response_mode: form_post', fu
},
body: {
state: '__test_state__',
id_token: jwt.sign({
'iss': 'https://test.auth0.com/',
'sub': '__test_sub__',
'aud': clientID,
'exp': Math.round(Date.now() / 1000) + 60000,
'nonce': '__test_nonce__'
}, cert.key, { algorithm: 'RS256', header: { kid: cert.kid } })
id_token: makeIdToken()
},
assertions() {
it('should return the reason to the error handler', function() {
Expand All @@ -205,15 +215,7 @@ describe('callback routes response_type: id_token, response_mode: form_post', fu
},
body: {
state: '__test_state__',
id_token: jwt.sign({
'nickname': '__test_nickname__',
'iss': 'https://test.auth0.com/',
'sub': '__test_sub__',
'aud': clientID,
'iat': Math.round(Date.now() / 1000),
'exp': Math.round(Date.now() / 1000) + 60000,
'nonce': '__test_nonce__'
}, cert.key, { algorithm: 'RS256', header: { kid: cert.kid } })
id_token: makeIdToken()
},
assertions() {
it('should return 302', function() {
Expand Down Expand Up @@ -275,14 +277,7 @@ describe('callback routes response_type: id_token, response_mode: form_post', fu
},
body: {
state: '__test_state__',
id_token: jwt.sign({
'iss': 'https://test.auth0.com/',
'sub': '__test_sub__',
'aud': clientID,
'iat': Math.round(Date.now() / 1000),
'exp': Math.round(Date.now() / 1000) + 60000,
'nonce': '__test_nonce__'
}, cert.key, { algorithm: 'RS256', header: { kid: cert.kid } })
id_token: makeIdToken()
},
assertions() {
it('throws an error from the custom handler', function() {
Expand Down

0 comments on commit 607f166

Please sign in to comment.