Skip to content

Commit 06e42b4

Browse files
committed
Test that lockdown specifically adds authorise
As requested by @thomseddon here: https://github.com/thomseddon/node-oauth2-server/pull/119#discussion_r20351706
1 parent b53e9c9 commit 06e42b4

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

lib/oauth2server.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ OAuth2Server.prototype.authorise = function () {
6767
var self = this;
6868

6969
return function (req, res, next) {
70-
new Authorise(self, req, next);
70+
return new Authorise(self, req, next);
7171
};
7272
};
7373

test/lockdown.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ var express = require('express'),
2020
should = require('should');
2121

2222
var oauth2server = require('../');
23+
var Authorise = require('../lib/authorise');
2324

2425
var bootstrap = function (oauthConfig) {
2526
var app = express();
@@ -105,7 +106,24 @@ describe('Lockdown pattern', function() {
105106
app.oauth.lockdown(app);
106107
});
107108

109+
function mockRequest(authoriseFactory) {
110+
var req = {
111+
get: function () {},
112+
query: { access_token: { expires: null } }
113+
};
114+
var next = function () {};
115+
116+
app.oauth.model.getAccessToken = function (t, c) { c(null, t); };
117+
118+
return authoriseFactory(req, null, next);
119+
}
120+
108121
it('adds authorise to non-bypassed routes', function () {
122+
var authorise = mockRequest(app.routes.get[0].callbacks[0]);
123+
authorise.should.be.an.instanceOf(Authorise);
124+
});
125+
126+
it('runs non-bypassed routes after authorise', function () {
109127
app.routes.get[0].callbacks[1].should.equal(privateAction);
110128
});
111129

0 commit comments

Comments
 (0)