Skip to content

Commit

Permalink
Port test case for authorization error to Mocha.
Browse files Browse the repository at this point in the history
  • Loading branch information
jaredhanson committed Aug 15, 2013
1 parent f52fcf8 commit f14a8ae
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 4 deletions.
2 changes: 1 addition & 1 deletion lib/strategy.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ util.inherits(Strategy, OAuth2Strategy);
*/
Strategy.prototype.authenticate = function(req, options) {
if (req.query && req.query.error_code) {
return this.fail({code: req.query.error_code,
return this.fail({code: parseInt(req.query.error_code, 10),
message: req.query.error_message});
}

Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@
"devDependencies": {
"vows": "0.6.x",
"mocha": "1.x.x",
"chai": "1.x.x"
"chai": "1.x.x",
"chai-passport-strategy": "0.1.x"
},
"engines": { "node": ">= 0.4.0" },
"scripts": {
Expand Down
6 changes: 5 additions & 1 deletion test/bootstrap/node.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
var chai = require('chai');
var chai = require('chai')
, passport = require('chai-passport-strategy');

chai.use(passport);


global.expect = chai.expect;
1 change: 1 addition & 0 deletions test/strategy-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,7 @@ vows.describe('FacebookStrategy').addBatch({
},
},

// OK
'strategy when sending back an error_code': {
topic: function() {
var strategy = new FacebookStrategy({
Expand Down
27 changes: 26 additions & 1 deletion test/strategy.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
var FacebookStrategy = require('../lib/strategy');
var chai = require('chai')
, FacebookStrategy = require('../lib/strategy');


describe('Strategy', function() {
Expand All @@ -13,4 +14,28 @@ describe('Strategy', function() {
expect(strategy.name).to.equal('facebook');
});

describe('handling a return request in which authorization has failed with an error', function() {
var info;

before(function(done) {
chai.passport(strategy)
.fail(function(i) {
info = i;
done();
})
.req(function(req) {
req.query = {};
req.query.error_code = '901';
req.query.error_message = 'This app is in sandbox mode. Edit the app configuration at http://developers.facebook.com/apps to make the app publicly visible.';
})
.authenticate();
});

it('should fail with info', function() {
expect(info).to.not.be.undefined;
expect(info.code).to.equal(901);
expect(info.message).to.equal('This app is in sandbox mode. Edit the app configuration at http://developers.facebook.com/apps to make the app publicly visible.');
});
});

});

0 comments on commit f14a8ae

Please sign in to comment.