From 407d1b3719c91b68fc71621df43acda99c492a3a Mon Sep 17 00:00:00 2001 From: "Steven R. Loomis" Date: Tue, 9 Aug 2016 15:58:06 -0700 Subject: [PATCH] auth: use utf8 for hmac MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Thanks to https://github.com/nodejs/node/issues/5499#issuecomment-190493397 … it seems that crypto.….update() needs to take an encoding parameter. * Add a test case for non-utf8 text in upload Fixes: https://github.com/IBM-Bluemix/gp-js-client/issues/34 --- lib/gp-hmac.js | 2 +- test/client-test.js | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/gp-hmac.js b/lib/gp-hmac.js index 2aa97b5..fa4a5fd 100644 --- a/lib/gp-hmac.js +++ b/lib/gp-hmac.js @@ -101,7 +101,7 @@ GaasHmac.prototype.apply = function(obj, authorizations) { //var hmacBuffer = new Buffer(hmacText, this.ENC); var hmacHash = crypto.createHmac(this.HMAC_SHA1_ALGORITHM, this.secretBuffer ) - .update(hmacText) + .update(hmacText, 'utf8') .digest('base64'); //if(this.VERBOSE) console.log('hmacHash = ' + hmacHash ); var hmacHeader = this.AUTH_SCHEME + ' ' + this.user + ':' + hmacHash; diff --git a/test/client-test.js b/test/client-test.js index 5cb6fd3..0dc9d49 100644 --- a/test/client-test.js +++ b/test/client-test.js @@ -959,7 +959,8 @@ describe('gaasClient.bundle()', function() { Q.ninvoke(proj, "create", {sourceLanguage: gaasTest.SOURCES[0], targetLanguages: [gaasTest.SOURCES[0],gaasTest.CYRILLIC]}) .then(function(resp) { Q.ninvoke(proj, "uploadResourceStrings", {languageId: gaasTest.SOURCES[0], strings: { - hello: 'Hello, World!' + hello: 'Hello, World!', + "msgError": "—" }}) .then(function(resp){ done(); }, done); }, done);