From d8d1e0bad7f70bed788788f2e538be3008d46654 Mon Sep 17 00:00:00 2001 From: Joe Rozner Date: Thu, 7 Jun 2012 10:44:54 -0700 Subject: [PATCH] fixed issue #64 w/ tests --- lib/oauth.js | 4 ++-- tests/oauth.js | 9 +++++++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/lib/oauth.js b/lib/oauth.js index 6283b1e..94a8e18 100644 --- a/lib/oauth.js +++ b/lib/oauth.js @@ -189,11 +189,11 @@ exports.OAuth.prototype._createSignature= function(signatureBase, tokenSecret) { if( tokenSecret === undefined ) var tokenSecret= ""; else tokenSecret= this._encodeData( tokenSecret ); // consumerSecret is already encoded - var key= this._consumerSecret + "&" + tokenSecret; + var key= this._encodeData(this._consumerSecret) + "&" + this._encodeData(tokenSecret); var hash= "" if( this._signatureMethod == "PLAINTEXT" ) { - hash= this._encodeData(key); + hash= key; } else { if( crypto.Hmac ) { diff --git a/tests/oauth.js b/tests/oauth.js index b52f1e5..f1a07d2 100644 --- a/tests/oauth.js +++ b/tests/oauth.js @@ -32,6 +32,15 @@ vows.describe('OAuth').addBatch({ assert.equal( result, "GET&http%3A%2F%2Fphotos.example.net%2Fphotos&file%3Dvacation.jpg%26oauth_consumer_key%3Ddpf43f3p2l4k3l03%26oauth_nonce%3Dkllo9940pd9333jh%26oauth_signature_method%3DHMAC-SHA1%26oauth_timestamp%3D1191242096%26oauth_token%3Dnnch734d00sl2jdk%26oauth_version%3D1.0%26size%3Doriginal"); } }, + 'When generating the signature base string with PLAINTEXT': { + topic: new OAuth(null, null, null, null, null, null, "PLAINTEXT"), + 'we get the expected result string': function (oa) { + var result= oa._getSignature("GET", "http://photos.example.net/photos", + "file=vacation.jpg&oauth_consumer_key=dpf43f3p2l4k3l03&oauth_nonce=kllo9940pd9333jh&oauth_signature_method=PLAINTEXT&oauth_timestamp=1191242096&oauth_token=nnch734d00sl2jdk&oauth_version=1.0&size=original", + "test"); + assert.equal( result, "&test"); + } + }, 'When normalising a url': { topic: new OAuth(null, null, null, null, null, null, "HMAC-SHA1"), 'default ports should be stripped': function(oa) {