|
6 | 6 |
|
7 | 7 | const AuthorizationCodeGrantType = require('../../../lib/grant-types/authorization-code-grant-type');
|
8 | 8 | const InvalidGrantError = require('../../../lib/errors/invalid-grant-error');
|
| 9 | +const ServerError = require('../../../lib/errors/server-error'); |
9 | 10 | const Promise = require('bluebird');
|
10 | 11 | const Request = require('../../../lib/request');
|
11 | 12 | const sinon = require('sinon');
|
@@ -119,6 +120,33 @@ describe('AuthorizationCodeGrantType', function() {
|
119 | 120 | });
|
120 | 121 | });
|
121 | 122 |
|
| 123 | + it('should throw an error in getAuthorizationCode if an invalid code challenge method has been saved', function () { |
| 124 | + const codeVerifier = stringUtil.base64URLEncode(crypto.randomBytes(32)); |
| 125 | + const authorizationCode = { |
| 126 | + authorizationCode: 12345, |
| 127 | + client: { id: 'foobar', isPublic: true }, |
| 128 | + expiresAt: new Date(new Date().getTime() * 2), |
| 129 | + user: {}, |
| 130 | + codeChallengeMethod: 'foobar', // assume this bypassed validation |
| 131 | + codeChallenge: stringUtil.base64URLEncode(crypto.createHash('sha256').update(codeVerifier).digest()) |
| 132 | + }; |
| 133 | + const client = { id: 'foobar', isPublic: true }; |
| 134 | + const model = { |
| 135 | + getAuthorizationCode: function() { return authorizationCode; }, |
| 136 | + revokeAuthorizationCode: function() {}, |
| 137 | + saveToken: function() {} |
| 138 | + }; |
| 139 | + const grantType = new AuthorizationCodeGrantType({ accessTokenLifetime: 123, model: model }); |
| 140 | + const request = new Request({ body: { code: 12345, code_verifier: codeVerifier }, headers: {}, method: {}, query: {} }); |
| 141 | + |
| 142 | + return grantType.getAuthorizationCode(request, client) |
| 143 | + .then(should.fail) |
| 144 | + .catch(function(e) { |
| 145 | + e.should.be.an.instanceOf(ServerError); |
| 146 | + e.message.should.equal('Server error: `getAuthorizationCode()` did not return a valid `codeChallengeMethod` property'); |
| 147 | + }); |
| 148 | + }); |
| 149 | + |
122 | 150 | it('should throw an error if the `code_verifier` is invalid with plain code challenge method', function() {
|
123 | 151 | const codeVerifier = stringUtil.base64URLEncode(crypto.randomBytes(32));
|
124 | 152 | const authorizationCode = {
|
|
0 commit comments