Skip to content

Commit eefd821

Browse files
committed
Bumping to 0.9.14 (Treat 20x OAuth2 responses as successes)
1 parent d547f00 commit eefd821

File tree

8 files changed

+65
-24
lines changed

8 files changed

+65
-24
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@
22
# Run all tests
33
#
44
test:
5-
@@node_modules/.bin/vows tests/* --spec
5+
@@node_modules/.bin/vows tests/*tests.js --spec
66

77
.PHONY: test install

Readme.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,8 @@ describe('OAuth2',function(){
7878
7979
Change History
8080
==============
81-
81+
* 0.9.14
82+
- OAuth2: Extend 'successful' token responses to include anything in the 2xx range.
8283
* 0.9.13
8384
- OAuth2: Fixes the "createCredentials() is deprecated, use tls.createSecureContext instead" message. (thank you AJ ONeal)
8485
* 0.9.12

lib/oauth2.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ exports.OAuth2.prototype._executeRequest= function( http_library, options, post_
119119
function passBackControl( response, result ) {
120120
if(!callbackCalled) {
121121
callbackCalled=true;
122-
if( response.statusCode != 200 && (response.statusCode != 301) && (response.statusCode != 302) ) {
122+
if( !(response.statusCode >= 200 && response.statusCode <= 299) && (response.statusCode != 301) && (response.statusCode != 302) ) {
123123
callback({ statusCode: response.statusCode, data: result });
124124
} else {
125125
callback(null, result, response);
@@ -129,7 +129,8 @@ exports.OAuth2.prototype._executeRequest= function( http_library, options, post_
129129

130130
var result= "";
131131

132-
var request = http_library.request(options, function (response) {
132+
var request = http_library.request(options);
133+
request.on('response', function (response) {
133134
response.on("data", function (chunk) {
134135
result+= chunk
135136
});

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{ "name" : "oauth"
22
, "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."
3-
, "version" : "0.9.13"
3+
, "version" : "0.9.14"
44
, "directories" : { "lib" : "./lib" }
55
, "main" : "index.js"
66
, "author" : "Ciaran Jessup <[email protected]>"

tests/oauth2.js renamed to tests/oauth2tests.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,42 @@
11
var vows = require('vows'),
22
assert = require('assert'),
3+
DummyResponse= require('./shared').DummyResponse,
4+
DummyRequest= require('./shared').DummyRequest,
35
https = require('https'),
46
OAuth2= require('../lib/oauth2').OAuth2,
57
url = require('url');
68

79
vows.describe('OAuth2').addBatch({
810
'Given an OAuth2 instance with clientId and clientSecret, ': {
911
topic: new OAuth2("clientId", "clientSecret"),
12+
'When dealing with the response from the OP': {
13+
'we should treat a 201 response as a success': function(oa) {
14+
var callbackCalled= false;
15+
var http_library= {
16+
request: function() {
17+
return new DummyRequest(new DummyResponse(201));
18+
}
19+
};
20+
oa._executeRequest( http_library, {}, null, function(err, result, response) {
21+
callbackCalled= true;
22+
assert.equal(err, null);
23+
});
24+
assert.ok(callbackCalled);
25+
},
26+
'we should treat a 200 response as a success': function(oa) {
27+
var callbackCalled= false;
28+
var http_library= {
29+
request: function() {
30+
return new DummyRequest(new DummyResponse(200));
31+
}
32+
};
33+
oa._executeRequest( http_library, {}, null, function(err, result, response) {
34+
callbackCalled= true;
35+
assert.equal(err, null);
36+
});
37+
assert.ok(callbackCalled);
38+
}
39+
},
1040
'When handling the access token response': {
1141
'we should correctly extract the token if received as form-data': function (oa) {
1242
oa._request= function( method, url, fo, bar, bleh, callback) {

tests/oauth.js renamed to tests/oauthtests.js

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,12 @@
11
var vows = require('vows'),
22
assert = require('assert'),
3+
DummyResponse= require('./shared').DummyResponse,
4+
DummyRequest= require('./shared').DummyRequest,
35
events = require('events'),
46
OAuth= require('../lib/oauth').OAuth,
57
OAuthEcho= require('../lib/oauth').OAuthEcho,
68
crypto = require('crypto');
79

8-
var DummyResponse =function( statusCode ) {
9-
this.statusCode= statusCode;
10-
this.headers= {};
11-
}
12-
DummyResponse.prototype= events.EventEmitter.prototype;
13-
DummyResponse.prototype.setEncoding= function() {}
14-
15-
var DummyRequest =function( response ) {
16-
this.response= response;
17-
}
18-
DummyRequest.prototype= events.EventEmitter.prototype;
19-
DummyRequest.prototype.write= function(post_body){}
20-
DummyRequest.prototype.write= function(post_body){
21-
this.emit('response',this.response);
22-
}
23-
DummyRequest.prototype.end= function(){
24-
this.response.emit('end');
25-
}
26-
2710
//Valid RSA keypair used to test RSA-SHA1 signature method
2811
var RsaPrivateKey = "-----BEGIN RSA PRIVATE KEY-----\n" +
2912
"MIICXQIBAAKBgQDizE4gQP5nPQhzof/Vp2U2DDY3UY/Gxha2CwKW0URe7McxtnmE\n" +
File renamed without changes.

tests/shared.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
var events = require('events');
2+
3+
exports.DummyResponse = function( statusCode ) {
4+
this.statusCode= statusCode;
5+
this.headers= {};
6+
}
7+
exports.DummyResponse.prototype= events.EventEmitter.prototype;
8+
exports.DummyResponse.prototype.setEncoding= function() {}
9+
10+
exports.DummyRequest =function( response ) {
11+
this.response= response;
12+
this.responseSent= false;
13+
}
14+
exports.DummyRequest.prototype= events.EventEmitter.prototype;
15+
exports.DummyRequest.prototype.write= function(post_body){}
16+
exports.DummyRequest.prototype.write= function(post_body){
17+
this.responseSent= true;
18+
this.emit('response',this.response);
19+
}
20+
exports.DummyRequest.prototype.end= function(){
21+
if(!this.responseSent) {
22+
this.responseSent= true;
23+
this.emit('response',this.response);
24+
}
25+
this.response.emit('end');
26+
}

0 commit comments

Comments
 (0)