Bumping to 0.9.14 (Treat 20x OAuth2 responses as successes)

This commit is contained in:
ciaranj 2015-09-22 17:15:04 +01:00
parent d547f00915
commit eefd821ea9
8 changed files with 65 additions and 24 deletions

View File

@ -2,6 +2,6 @@
# Run all tests
#
test:
@@node_modules/.bin/vows tests/* --spec
@@node_modules/.bin/vows tests/*tests.js --spec
.PHONY: test install

View File

@ -78,7 +78,8 @@ describe('OAuth2',function(){
Change History
==============
* 0.9.14
- OAuth2: Extend 'successful' token responses to include anything in the 2xx range.
* 0.9.13
- OAuth2: Fixes the "createCredentials() is deprecated, use tls.createSecureContext instead" message. (thank you AJ ONeal)
* 0.9.12

View File

@ -119,7 +119,7 @@ exports.OAuth2.prototype._executeRequest= function( http_library, options, post_
function passBackControl( response, result ) {
if(!callbackCalled) {
callbackCalled=true;
if( response.statusCode != 200 && (response.statusCode != 301) && (response.statusCode != 302) ) {
if( !(response.statusCode >= 200 && response.statusCode <= 299) && (response.statusCode != 301) && (response.statusCode != 302) ) {
callback({ statusCode: response.statusCode, data: result });
} else {
callback(null, result, response);
@ -129,7 +129,8 @@ exports.OAuth2.prototype._executeRequest= function( http_library, options, post_
var result= "";
var request = http_library.request(options, function (response) {
var request = http_library.request(options);
request.on('response', function (response) {
response.on("data", function (chunk) {
result+= chunk
});

View File

@ -1,6 +1,6 @@
{ "name" : "oauth"
, "description" : "Library for interacting with OAuth 1.0, 1.0A, 2 and Echo. Provides simplified client access and allows for construction of more complex apis and OAuth providers."
, "version" : "0.9.13"
, "version" : "0.9.14"
, "directories" : { "lib" : "./lib" }
, "main" : "index.js"
, "author" : "Ciaran Jessup <ciaranj@gmail.com>"

View File

@ -1,5 +1,7 @@
var vows = require('vows'),
assert = require('assert'),
DummyResponse= require('./shared').DummyResponse,
DummyRequest= require('./shared').DummyRequest,
https = require('https'),
OAuth2= require('../lib/oauth2').OAuth2,
url = require('url');
@ -7,6 +9,34 @@ var vows = require('vows'),
vows.describe('OAuth2').addBatch({
'Given an OAuth2 instance with clientId and clientSecret, ': {
topic: new OAuth2("clientId", "clientSecret"),
'When dealing with the response from the OP': {
'we should treat a 201 response as a success': function(oa) {
var callbackCalled= false;
var http_library= {
request: function() {
return new DummyRequest(new DummyResponse(201));
}
};
oa._executeRequest( http_library, {}, null, function(err, result, response) {
callbackCalled= true;
assert.equal(err, null);
});
assert.ok(callbackCalled);
},
'we should treat a 200 response as a success': function(oa) {
var callbackCalled= false;
var http_library= {
request: function() {
return new DummyRequest(new DummyResponse(200));
}
};
oa._executeRequest( http_library, {}, null, function(err, result, response) {
callbackCalled= true;
assert.equal(err, null);
});
assert.ok(callbackCalled);
}
},
'When handling the access token response': {
'we should correctly extract the token if received as form-data': function (oa) {
oa._request= function( method, url, fo, bar, bleh, callback) {

View File

@ -1,29 +1,12 @@
var vows = require('vows'),
assert = require('assert'),
DummyResponse= require('./shared').DummyResponse,
DummyRequest= require('./shared').DummyRequest,
events = require('events'),
OAuth= require('../lib/oauth').OAuth,
OAuthEcho= require('../lib/oauth').OAuthEcho,
crypto = require('crypto');
var DummyResponse =function( statusCode ) {
this.statusCode= statusCode;
this.headers= {};
}
DummyResponse.prototype= events.EventEmitter.prototype;
DummyResponse.prototype.setEncoding= function() {}
var DummyRequest =function( response ) {
this.response= response;
}
DummyRequest.prototype= events.EventEmitter.prototype;
DummyRequest.prototype.write= function(post_body){}
DummyRequest.prototype.write= function(post_body){
this.emit('response',this.response);
}
DummyRequest.prototype.end= function(){
this.response.emit('end');
}
//Valid RSA keypair used to test RSA-SHA1 signature method
var RsaPrivateKey = "-----BEGIN RSA PRIVATE KEY-----\n" +
"MIICXQIBAAKBgQDizE4gQP5nPQhzof/Vp2U2DDY3UY/Gxha2CwKW0URe7McxtnmE\n" +

26
tests/shared.js Normal file
View File

@ -0,0 +1,26 @@
var events = require('events');
exports.DummyResponse = function( statusCode ) {
this.statusCode= statusCode;
this.headers= {};
}
exports.DummyResponse.prototype= events.EventEmitter.prototype;
exports.DummyResponse.prototype.setEncoding= function() {}
exports.DummyRequest =function( response ) {
this.response= response;
this.responseSent= false;
}
exports.DummyRequest.prototype= events.EventEmitter.prototype;
exports.DummyRequest.prototype.write= function(post_body){}
exports.DummyRequest.prototype.write= function(post_body){
this.responseSent= true;
this.emit('response',this.response);
}
exports.DummyRequest.prototype.end= function(){
if(!this.responseSent) {
this.responseSent= true;
this.emit('response',this.response);
}
this.response.emit('end');
}