Skip to content

Commit 3a1e433

Browse files
added warning in docs, added extra tests that actually use parameters
1 parent 98a9d19 commit 3a1e433

File tree

3 files changed

+52
-1
lines changed

3 files changed

+52
-1
lines changed

docs/model/spec.rst

+5
Original file line numberDiff line numberDiff line change
@@ -1015,6 +1015,11 @@ This model function is **optional**. If not implemented, the ``redirectUri`` sho
10151015
Returns ``true`` if the ``redirectUri`` is valid, ``false`` otherwise.
10161016

10171017
**Remarks:**
1018+
When implementing this method you should take care of possible security risks related to ``redirectUri``.
1019+
.. _rfc6819: https://datatracker.ietf.org/doc/html/rfc6819
1020+
1021+
Section-5.2.3.5 is implemented by default.
1022+
.. _Section-5.2.3.5: https://datatracker.ietf.org/doc/html/rfc6819#section-5.2.3.5
10181023

10191024
::
10201025

test/integration/handlers/authorize-handler_test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -635,7 +635,7 @@ describe('AuthorizeHandler integration', function() {
635635
});
636636

637637
describe('validateRedirectUri()', function() {
638-
it('should support empty model', function() {
638+
it('should support empty method', function() {
639639
const model = {
640640
getAccessToken: function() {},
641641
getClient: function() {},

test/unit/handlers/authorize-handler_test.js

+46
Original file line numberDiff line numberDiff line change
@@ -128,5 +128,51 @@ describe('AuthorizeHandler', function() {
128128
})
129129
.catch(should.fail);
130130
});
131+
132+
it('should be successful validation', function () {
133+
const client = { grants: ['authorization_code'], redirectUris: ['http://example.com/cb'] };
134+
const redirect_uri = 'http://example.com/cb';
135+
const model = {
136+
getAccessToken: function() {},
137+
getClient: sinon.stub().returns(client),
138+
saveAuthorizationCode: function() {},
139+
validateRedirectUri: function (redirectUri, client) {
140+
return client.redirectUris.includes(redirectUri);
141+
}
142+
};
143+
144+
const handler = new AuthorizeHandler({ authorizationCodeLifetime: 120, model: model });
145+
const request = new Request({ body: { client_id: 12345, client_secret: 'secret', redirect_uri }, headers: {}, method: {}, query: {} });
146+
147+
return handler.getClient(request)
148+
.then((client) => {
149+
client.should.equal(client);
150+
});
151+
});
152+
153+
it('should be unsuccessful validation', function () {
154+
const client = { grants: ['authorization_code'], redirectUris: ['http://example.com/cb'] };
155+
const redirect_uri = 'http://example.com/callback';
156+
const model = {
157+
getAccessToken: function() {},
158+
getClient: sinon.stub().returns(client),
159+
saveAuthorizationCode: function() {},
160+
validateRedirectUri: function (redirectUri, client) {
161+
return client.redirectUris.includes(redirectUri);
162+
}
163+
};
164+
165+
const handler = new AuthorizeHandler({ authorizationCodeLifetime: 120, model: model });
166+
const request = new Request({ body: { client_id: 12345, client_secret: 'secret', redirect_uri }, headers: {}, method: {}, query: {} });
167+
168+
return handler.getClient(request)
169+
.then(() => {
170+
throw Error('should not resolve');
171+
})
172+
.catch((err) => {
173+
err.name.should.equal('invalid_client');
174+
err.message.should.equal('Invalid client: `redirect_uri` does not match client value');
175+
});
176+
});
131177
});
132178
});

0 commit comments

Comments
 (0)