Skip to content

Commit 88ef515

Browse files
added test for validateRedirectUri
1 parent 3df52fd commit 88ef515

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

lib/handlers/authorize-handler.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ AuthorizeHandler.prototype.getClient = function(request) {
195195
}
196196

197197
if (redirectUri && typeof self.model.validateRedirectUri === 'function') {
198-
if (self.model.validateRedirectUri(redirectUri, client.redirectUris)) {
198+
if (!self.model.validateRedirectUri(redirectUri, client.redirectUris)) {
199199
throw new InvalidClientError('Invalid client: `redirect_uri` does not match client value');
200200
}
201201
} else if (redirectUri && !client.redirectUris.includes(redirectUri)) {

test/unit/handlers/authorize-handler_test.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,4 +99,34 @@ describe('AuthorizeHandler', function() {
9999
.catch(should.fail);
100100
});
101101
});
102+
103+
describe('validateRedirectUri()', function() {
104+
it('should call `model.validateRedirectUri()`', function() {
105+
const client = { grants: ['authorization_code'], redirectUris: ['http://example.com/cb'] };
106+
const redirect_uri = 'http://example.com/cb/2';
107+
const model = {
108+
getAccessToken: function() {},
109+
getClient: sinon.stub().returns(client),
110+
saveAuthorizationCode: function() {},
111+
validateRedirectUri: sinon.stub().returns(true)
112+
};
113+
const handler = new AuthorizeHandler({ authorizationCodeLifetime: 120, model: model });
114+
const request = new Request({ body: { client_id: 12345, client_secret: 'secret', redirect_uri }, headers: {}, method: {}, query: {} });
115+
116+
return handler.getClient(request)
117+
.then(function() {
118+
model.getClient.callCount.should.equal(1);
119+
model.getClient.firstCall.args.should.have.length(2);
120+
model.getClient.firstCall.args[0].should.equal(12345);
121+
model.getClient.firstCall.thisValue.should.equal(model);
122+
123+
model.validateRedirectUri.callCount.should.equal(1);
124+
model.validateRedirectUri.firstCall.args.should.have.length(2);
125+
model.validateRedirectUri.firstCall.args[0].should.equal(redirect_uri);
126+
model.validateRedirectUri.firstCall.args[1].should.equal(client.redirectUris);
127+
model.validateRedirectUri.firstCall.thisValue.should.equal(model);
128+
})
129+
.catch(should.fail);
130+
});
131+
});
102132
});

0 commit comments

Comments
 (0)