diff --git a/lib/strategy.js b/lib/strategy.js index 0dec8d7..fc50aaf 100644 --- a/lib/strategy.js +++ b/lib/strategy.js @@ -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}); } diff --git a/package.json b/package.json index 83ba23b..4ab9f5c 100644 --- a/package.json +++ b/package.json @@ -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": { diff --git a/test/bootstrap/node.js b/test/bootstrap/node.js index c99b18e..4f09d45 100644 --- a/test/bootstrap/node.js +++ b/test/bootstrap/node.js @@ -1,3 +1,7 @@ -var chai = require('chai'); +var chai = require('chai') + , passport = require('chai-passport-strategy'); + +chai.use(passport); + global.expect = chai.expect; diff --git a/test/strategy-test.js b/test/strategy-test.js index e205927..cb0df53 100644 --- a/test/strategy-test.js +++ b/test/strategy-test.js @@ -377,6 +377,7 @@ vows.describe('FacebookStrategy').addBatch({ }, }, + // OK 'strategy when sending back an error_code': { topic: function() { var strategy = new FacebookStrategy({ diff --git a/test/strategy.test.js b/test/strategy.test.js index 2e7251f..cfe0d65 100644 --- a/test/strategy.test.js +++ b/test/strategy.test.js @@ -1,4 +1,5 @@ -var FacebookStrategy = require('../lib/strategy'); +var chai = require('chai') + , FacebookStrategy = require('../lib/strategy'); describe('Strategy', function() { @@ -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.'); + }); + }); + });