Repair missing commit(s)

This commit is contained in:
ciaranj 2014-12-18 20:12:24 +00:00
parent 9e27f4c128
commit a4b96af335
4 changed files with 76 additions and 17 deletions

View File

@ -77,11 +77,16 @@ describe('OAuth2',function(){
Change History
==============
* 0.9.12
- OAuth1/2: Can now pass Buffer instance directly for PUTs+POSTs (thank you Evan Prodromou)
- OAuth1: Improve interoperability with libraries that mess with the prototype. (thank you Jose Ignacio Andres)
- OAuth2: Adds PUT support for OAuth2 (thank you Derek Brooks)
- OAuth1: Improves use_strict compatibility (thank you Ted Goddard)
* 0.9.11
- OAuth2: No longer sends the type=webserver argument with the OAuth2 requests (thank you bendiy)
- OAuth2: Provides a default (and overrideable) User-Agent header (thanks to Andrew Martens & Daniel Mahlow)
- OAuth1: New followRedirects client option (true by default) (thanks to Pieter Joost van de Sande)
- OAuth1: Adds RSA-SHA1 support (thanks to Jeffrey D. Van Alstine & Michael Garvin & Andreas Knecht)
- OAuth2: No longer sends the type=webserver argument with the OAuth2 requests (thank you bendiy)
- OAuth2: Provides a default (and overrideable) User-Agent header (thanks to Andrew Martens & Daniel Mahlow)
- OAuth1: New followRedirects client option (true by default) (thanks to Pieter Joost van de Sande)
- OAuth1: Adds RSA-SHA1 support (thanks to Jeffrey D. Van Alstine & Michael Garvin & Andreas Knecht)
* 0.9.10
- OAuth2: Addresses 2 issues that came in with 0.9.9, #129 & #125 (thank you José F. Romaniello)
* 0.9.9
@ -149,6 +154,10 @@ Change History
Contributors (In no particular order)
=====================================
* Evan Prodromou
* Jose Ignacio Andres
* Ted Goddard
* Derek Brooks
* Ciaran Jessup - ciaranj@gmail.com
* Mark Wubben - http://equalmedia.com/
* Ryan LeFevre - http://meltingice.net

View File

@ -60,6 +60,7 @@ exports.OAuth2.prototype._chooseHttpLibrary= function( parsedUrl ) {
exports.OAuth2.prototype._request= function(method, url, headers, post_body, access_token, callback) {
var creds = crypto.createCredentials({ });
var parsedUrl= URL.parse( url, true );
if( parsedUrl.protocol == "https:" && !parsedUrl.port ) {
parsedUrl.port= 443;
@ -83,7 +84,16 @@ exports.OAuth2.prototype._request= function(method, url, headers, post_body, acc
realHeaders['User-Agent'] = 'Node-oauth';
}
realHeaders['Content-Length']= post_body ? Buffer.byteLength(post_body) : 0;
if( post_body ) {
if ( Buffer.isBuffer(post_body) ) {
realHeaders["Content-Length"]= post_body.length;
} else {
realHeaders["Content-Length"]= Buffer.byteLength(post_body);
}
} else {
realHeaders["Content-length"]= 0;
}
if( access_token && !('Authorization' in realHeaders)) {
if( ! parsedUrl.query ) parsedUrl.query= {};
parsedUrl.query[this._accessTokenName]= access_token;
@ -193,10 +203,12 @@ exports.OAuth2.prototype.getProtectedResource= function(url, access_token, callb
}
exports.OAuth2.prototype.get= function(url, access_token, callback) {
var headers= {};
if( this._useAuthorizationHeaderForGET ) {
headers= {'Authorization': this.buildAuthHeader(access_token) }
var headers= {'Authorization': this.buildAuthHeader(access_token) }
access_token= null;
}
else {
headers= {};
}
this._request("GET", url, headers, "", access_token, callback );
}

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.11"
, "version" : "0.9.12"
, "directories" : { "lib" : "./lib" }
, "main" : "index.js"
, "author" : "Ciaran Jessup <ciaranj@gmail.com>"

View File

@ -1,5 +1,6 @@
var vows = require('vows'),
assert = require('assert'),
https = require('https'),
OAuth2= require('../lib/oauth2').OAuth2,
url = require('url');
@ -158,6 +159,29 @@ vows.describe('OAuth2').addBatch({
}
oa._request("POST", "", {"Content-Type":"text/plain"}, "THIS_IS_A_POST_BODY_STRING");
assert.ok( bodyWritten );
},
'we should see a given buffer being sent to the request' : function(oa) {
var bodyWritten= false;
oa._chooseHttpLibrary= function() {
return {
request: function(options) {
assert.equal(options.headers["Content-Type"], "application/octet-stream");
assert.equal(options.headers["Content-Length"], 4);
assert.equal(options.method, "POST");
return {
end: function() {},
on: function() {},
write: function(body) {
bodyWritten= true;
assert.isNotNull(body);
assert.equal(4, body.length)
}
}
}
};
}
oa._request("POST", "", {"Content-Type":"application/octet-stream"}, new Buffer([1,2,3,4]));
assert.ok( bodyWritten );
}
},
'When PUTing': {
@ -183,6 +207,29 @@ vows.describe('OAuth2').addBatch({
}
oa._request("PUT", "", {"Content-Type":"text/plain"}, "THIS_IS_A_PUT_BODY_STRING");
assert.ok( bodyWritten );
},
'we should see a given buffer being sent to the request' : function(oa) {
var bodyWritten= false;
oa._chooseHttpLibrary= function() {
return {
request: function(options) {
assert.equal(options.headers["Content-Type"], "application/octet-stream");
assert.equal(options.headers["Content-Length"], 4);
assert.equal(options.method, "PUT");
return {
end: function() {},
on: function() {},
write: function(body) {
bodyWritten= true;
assert.isNotNull(body);
assert.equal(4, body.length)
}
}
}
};
}
oa._request("PUT", "", {"Content-Type":"application/octet-stream"}, new Buffer([1,2,3,4]));
assert.ok( bodyWritten );
}
}
},
@ -209,14 +256,5 @@ vows.describe('OAuth2').addBatch({
oa.get("", {});
}
}
},
'HTTPS URL connection testing, ': {
topic: function() {
var oa = new OAuth2("clientId", "clientSecret");
oa._request('GET', 'https://www.bing.com/', {}, null, '', this.callback);
},
'we should correctly get the response code == 200': function(error, result, response) {
assert.equal(response.statusCode, 200);
}
}
}).export(module);