Fixed a load of test failures I'd somehow missed ?!?!! (Thanks go to @dshaw for noticing)

This commit is contained in:
ciaranj 2010-05-18 13:57:01 +01:00
parent 24bcc8c712
commit 341136d554
4 changed files with 17 additions and 13 deletions

View File

@ -2,11 +2,12 @@ var sys= require('sys')
var OAuth= require('../lib/oauth').OAuth; var OAuth= require('../lib/oauth').OAuth;
var oa= new OAuth("http://term.ie/oauth/example/request_token.php?foo=bar", var oa= new OAuth("http://term.ie/oauth/example/request_token.php",
"http://term.ie/oauth/example/access_token.php", "http://term.ie/oauth/example/access_token.php",
"key", "key",
"secret", "secret",
"1.0", "1.0",
null,
"HMAC-SHA1") "HMAC-SHA1")
oa.getOAuthRequestToken(function(error, oauth_token, oauth_token_secret, results){ oa.getOAuthRequestToken(function(error, oauth_token, oauth_token_secret, results){

View File

@ -7,6 +7,7 @@ var oa= new OAuth("http://term.ie/oauth/example/request_token.php?foo=bar",
"key", "key",
"secret", "secret",
"1.0", "1.0",
null,
"PLAINTEXT") "PLAINTEXT")
oa.getOAuthRequestToken(function(error, oauth_token, oauth_token_secret, results){ oa.getOAuthRequestToken(function(error, oauth_token, oauth_token_secret, results){

View File

@ -207,6 +207,7 @@ exports.OAuth.prototype._performSecureRequest= function( oauth_token, oauth_toke
headers["Content-Type"]= "application/x-www-form-urlencoded" headers["Content-Type"]= "application/x-www-form-urlencoded"
var path; var path;
if( !parsedUrl.pathname || parsedUrl.pathname == "" ) parsedUrl.pathname ="/";
if( parsedUrl.query ) path= parsedUrl.pathname + "?"+ parsedUrl.query ; if( parsedUrl.query ) path= parsedUrl.pathname + "?"+ parsedUrl.query ;
else path= parsedUrl.pathname; else path= parsedUrl.pathname;
@ -243,7 +244,6 @@ exports.OAuth.prototype.getOauthAccessToken= function(oauth_token, oauth_token_s
} }
}) })
} }
exports.OAuth.prototype.getProtectedResource= function(url, method, oauth_token, oauth_token_secret, callback) { exports.OAuth.prototype.getProtectedResource= function(url, method, oauth_token, oauth_token_secret, callback) {
this._performSecureRequest( oauth_token, oauth_token_secret, method, url, null, callback ); this._performSecureRequest( oauth_token, oauth_token_secret, method, url, null, callback );
} }

View File

@ -5,7 +5,7 @@ describe 'node-oauth'
describe 'Auth' describe 'Auth'
describe 'OAuth' describe 'OAuth'
it 'should generate the signature base string described in http://oauth.net/core/1.0/#sig_base_example' it 'should generate the signature base string described in http://oauth.net/core/1.0/#sig_base_example'
oa= new OAuth(null, null, null, null, null, "HMAC-SHA1"); oa= new OAuth(null, null, null, null, null, null, "HMAC-SHA1");
var result= oa._createSignatureBase("GET", "http://photos.example.net/photos", var result= oa._createSignatureBase("GET", "http://photos.example.net/photos",
"file=vacation.jpg&oauth_consumer_key=dpf43f3p2l4k3l03&oauth_nonce=kllo9940pd9333jh&oauth_signature_method=HMAC-SHA1&oauth_timestamp=1191242096&oauth_token=nnch734d00sl2jdk&oauth_version=1.0&size=original") "file=vacation.jpg&oauth_consumer_key=dpf43f3p2l4k3l03&oauth_nonce=kllo9940pd9333jh&oauth_signature_method=HMAC-SHA1&oauth_timestamp=1191242096&oauth_token=nnch734d00sl2jdk&oauth_version=1.0&size=original")
@ -13,7 +13,7 @@ describe 'node-oauth'
end end
describe 'Url normalisation' describe 'Url normalisation'
before_each before_each
oa= new OAuth(null, null, null, null, null, "HMAC-SHA1"); oa= new OAuth(null, null, null, null, null, null, "HMAC-SHA1");
end end
it 'should strip default ports from urls for use in signature generation' it 'should strip default ports from urls for use in signature generation'
oa._normalizeUrl("https://somehost.com:443/foo/bar").should_be "https://somehost.com/foo/bar" oa._normalizeUrl("https://somehost.com:443/foo/bar").should_be "https://somehost.com/foo/bar"
@ -28,19 +28,19 @@ describe 'node-oauth'
end end
describe 'Url signing' describe 'Url signing'
it 'should provide a valid signature when no token present' it 'should provide a valid signature when no token present'
oa= new OAuth(null, null, "consumerkey", "consumersecret", "1.0", "HMAC-SHA1"); oa= new OAuth(null, null, "consumerkey", "consumersecret", "1.0", null, "HMAC-SHA1");
oa.stub('_getTimestamp').and_return("1272399856") oa.stub('_getTimestamp').and_return("1272399856")
oa.stub('_getNonce').and_return("ybHPeOEkAUJ3k2wJT9Xb43MjtSgTvKqp") oa.stub('_getNonce').and_return("ybHPeOEkAUJ3k2wJT9Xb43MjtSgTvKqp")
oa.signUrl("http://somehost.com:3323/foo/poop?bar=foo").should_be ("http://somehost.com:3323/foo/poop?bar=foo&oauth_consumer_key=consumerkey&oauth_nonce=ybHPeOEkAUJ3k2wJT9Xb43MjtSgTvKqp&oauth_signature_method=HMAC-SHA1&oauth_timestamp=1272399856&oauth_version=1.0&oauth_signature=7ytO8vPSLut2GzHjU9pn1SV9xjc%3D") oa.signUrl("http://somehost.com:3323/foo/poop?bar=foo").should_be ("http://somehost.com:3323/foo/poop?bar=foo&oauth_consumer_key=consumerkey&oauth_nonce=ybHPeOEkAUJ3k2wJT9Xb43MjtSgTvKqp&oauth_signature_method=HMAC-SHA1&oauth_timestamp=1272399856&oauth_version=1.0&oauth_signature=7ytO8vPSLut2GzHjU9pn1SV9xjc%3D")
end end
it 'should provide a valid signature when a token is present' it 'should provide a valid signature when a token is present'
oa= new OAuth(null, null, "consumerkey", "consumersecret", "1.0", "HMAC-SHA1"); oa= new OAuth(null, null, "consumerkey", "consumersecret", "1.0", null, "HMAC-SHA1");
oa.stub('_getTimestamp').and_return("1272399856") oa.stub('_getTimestamp').and_return("1272399856")
oa.stub('_getNonce').and_return("ybHPeOEkAUJ3k2wJT9Xb43MjtSgTvKqp") oa.stub('_getNonce').and_return("ybHPeOEkAUJ3k2wJT9Xb43MjtSgTvKqp")
oa.signUrl("http://somehost.com:3323/foo/poop?bar=foo", "token").should_be ("http://somehost.com:3323/foo/poop?bar=foo&oauth_consumer_key=consumerkey&oauth_nonce=ybHPeOEkAUJ3k2wJT9Xb43MjtSgTvKqp&oauth_signature_method=HMAC-SHA1&oauth_timestamp=1272399856&oauth_token=token&oauth_version=1.0&oauth_signature=9LwCuCWw5sURtpMroIolU3YwsdI%3D") oa.signUrl("http://somehost.com:3323/foo/poop?bar=foo", "token").should_be ("http://somehost.com:3323/foo/poop?bar=foo&oauth_consumer_key=consumerkey&oauth_nonce=ybHPeOEkAUJ3k2wJT9Xb43MjtSgTvKqp&oauth_signature_method=HMAC-SHA1&oauth_timestamp=1272399856&oauth_token=token&oauth_version=1.0&oauth_signature=9LwCuCWw5sURtpMroIolU3YwsdI%3D")
end end
it 'should provide a valid signature when a token and a token secret is present' it 'should provide a valid signature when a token and a token secret is present'
oa= new OAuth(null, null, "consumerkey", "consumersecret", "1.0", "HMAC-SHA1"); oa= new OAuth(null, null, "consumerkey", "consumersecret", "1.0", null, "HMAC-SHA1");
oa.stub('_getTimestamp').and_return("1272399856") oa.stub('_getTimestamp').and_return("1272399856")
oa.stub('_getNonce').and_return("ybHPeOEkAUJ3k2wJT9Xb43MjtSgTvKqp") oa.stub('_getNonce').and_return("ybHPeOEkAUJ3k2wJT9Xb43MjtSgTvKqp")
oa.signUrl("http://somehost.com:3323/foo/poop?bar=foo", "token", "tokensecret").should_be ("http://somehost.com:3323/foo/poop?bar=foo&oauth_consumer_key=consumerkey&oauth_nonce=ybHPeOEkAUJ3k2wJT9Xb43MjtSgTvKqp&oauth_signature_method=HMAC-SHA1&oauth_timestamp=1272399856&oauth_token=token&oauth_version=1.0&oauth_signature=zeOR0Wsm6EG6XSg0Vw%2FsbpoSib8%3D") oa.signUrl("http://somehost.com:3323/foo/poop?bar=foo", "token", "tokensecret").should_be ("http://somehost.com:3323/foo/poop?bar=foo&oauth_consumer_key=consumerkey&oauth_nonce=ybHPeOEkAUJ3k2wJT9Xb43MjtSgTvKqp&oauth_signature_method=HMAC-SHA1&oauth_timestamp=1272399856&oauth_token=token&oauth_version=1.0&oauth_signature=zeOR0Wsm6EG6XSg0Vw%2FsbpoSib8%3D")
@ -49,22 +49,24 @@ describe 'node-oauth'
describe 'host headers for non default ports should contain the port' describe 'host headers for non default ports should contain the port'
describe 'when getProtectedResource is called' describe 'when getProtectedResource is called'
it 'should set the correct Host header when provided with an unusual port' it 'should set the correct Host header when provided with an unusual port'
oa2= new OAuth(null, null, null, null, null, "HMAC-SHA1"); oa2= new OAuth(null, null, null, null, null, null, "HMAC-SHA1");
var mockProvider= {}, var mockProvider= {},
mockRequest= {addListener:function(){}, mockRequest= {addListener:function(){},
end:function(){}}; end:function(){}};
stub(mockProvider, 'request').and_return(mockRequest) stub(mockProvider, 'request').and_return(mockRequest)
mockProvider.should.receive('request', 'once').with_args('GET', an_instance_of(String), {Host:"somehost.com:8080"}) mockProvider.should.receive('request', 'once').with_args('GET', an_instance_of(String), {Host:"somehost.com:8080"})
stub(oa2, '_createClient').and_return(mockProvider) stub(oa2, '_createClient').and_return(mockProvider)
oa2.should.receive('_createClient', 'once').with_args('8080', 'somehost.com') oa2.should.receive('_createClient', 'once') .with_args('8080', 'somehost.com')
oa2.getProtectedResource("http://somehost.com:8080", "GET", "oauth_token", null, function(){})
oa2.getProtectedResource("http://somehost.com:8080", "GET", "oauth_token", null, function(){require('sys').p('dddd')})
end end
end end
describe 'when getOAuthRequestToken is called' describe 'when getOAuthRequestToken is called'
it 'should set the correct Host header when provided with an unusual port' it 'should set the correct Host header when provided with an unusual port'
oa2= new OAuth(null, null, null, null, null, "HMAC-SHA1"); oa2= new OAuth(null, null, null, null, null, null, "HMAC-SHA1");
var mockProvider= {}, var mockProvider= {},
mockRequest= {addListener:function(){}, mockRequest= {addListener:function(){},
end:function(){}}; end:function(){}};
@ -79,7 +81,7 @@ describe 'node-oauth'
describe 'when getOauthAccessToken is called' describe 'when getOauthAccessToken is called'
it 'should set the correct Host header when provided with an unusual port' it 'should set the correct Host header when provided with an unusual port'
oa2= new OAuth(null, null, null, null, null, "HMAC-SHA1"); oa2= new OAuth(null, null, null, null, null, null, "HMAC-SHA1");
var mockProvider= {}, var mockProvider= {},
mockRequest= {addListener:function(){}, mockRequest= {addListener:function(){},
end:function(){}}; end:function(){}};