Merge pull request #92 from clarkorz/fix/passport

Fix "can't config passport#initialize in middleware.json"

Close #92
This commit is contained in:
Miroslav Bajtoš 2015-02-02 18:55:45 +01:00
commit 9dde8b0adf
3 changed files with 43 additions and 1 deletions

View File

@ -280,7 +280,7 @@ function setupMiddleware(app, instructions) {
data.fragment ? ('#' + data.fragment) : ''); data.fragment ? ('#' + data.fragment) : '');
var factory = require(data.sourceFile); var factory = require(data.sourceFile);
if (data.fragment) { if (data.fragment) {
factory = factory[data.fragment]; factory = factory[data.fragment].bind(factory);
} }
assert(typeof factory === 'function', assert(typeof factory === 'function',
'Middleware factory must be a function'); 'Middleware factory must be a function');

View File

@ -467,6 +467,29 @@ describe('executor', function() {
expect(app.componentOptions).to.eql({ option: 'value' }); expect(app.componentOptions).to.eql({ option: 'value' });
}); });
it('configures middleware (that requires `this`)', function(done) {
var passportPath = require.resolve('./fixtures/passport');
boot.execute(app, someInstructions({
middleware: {
phases: ['auth'],
middleware: [
{
sourceFile: passportPath,
fragment: 'initialize',
config: {
phase: 'auth:before'
}
}
]
}
}));
supertest(app)
.get('/')
.expect('passport', 'initialized', done);
});
}); });
function assertValidDataSource(dataSource) { function assertValidDataSource(dataSource) {

19
test/fixtures/passport.js vendored Normal file
View File

@ -0,0 +1,19 @@
var framework = {
initialize: function(passport) {
return function(req, res, next) {
req._passport = passport;
res.setHeader('passport', 'initialized');
next();
};
}
};
var Passport = function() {
this._framework = framework;
};
Passport.prototype.initialize = function() {
return this._framework.initialize(this);
};
module.exports = new Passport();