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

@ -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');
}