diff --git a/lib/browser.js b/lib/browser.js index 17f7a52..a7945d0 100755 --- a/lib/browser.js +++ b/lib/browser.js @@ -93,8 +93,8 @@ hawk.client = { ts: timestamp, nonce: options.nonce || hawk.utils.randomString(6), method: method, - resource: uri.relative, - host: uri.hostname, + resource: uri.resource, + host: uri.host, port: uri.port, hash: options.hash, ext: options.ext, @@ -201,8 +201,8 @@ hawk.client = { ts: exp, nonce: '', method: 'GET', - resource: uri.relative, // Maintain trailing '?' and query params - host: uri.hostname, + resource: uri.resource, // Maintain trailing '?' and query params + host: uri.host, port: uri.port, ext: options.ext }); @@ -583,29 +583,20 @@ hawk.utils = { return result.join(''); }, + uriRegex: /^([^:]+)\:\/\/(?:[^@]*@)?([^\/:]+)(?:\:(\d+))?([^#]*)(?:#.*)?$/, // scheme://credentials@host:port/resource#fragment parseUri: function (input) { - // From RFC 3986 (except for some groups being non-capturing and two extra groups for 'resource' and 'relative') - var uriRegex = /^(?:([^:\/?#]+):)?(?:\/\/([^\/?#]*))?((([^?#]*)(?:\?([^#]*))?)(?:#(.*))?)/; - var uriKeys = ['source', 'protocol', 'authority', 'resource', 'relative', 'pathname', 'query', 'fragment']; - var authRegex = /^(?:(([^:@]*)(?::([^@]*))?)@)?(\[[^\]]*\]|[^:]*)(?::(\d*))?/; - var authKeys = ['authority', 'userInfo', 'user', 'password', 'hostname', 'port']; - var uri = {}, i; - var parts = uriRegex.exec(input); - - for (i = 0; i < parts.length; ++i) { - uri[uriKeys[i]] = parts[i] || ''; - } - - parts = authRegex.exec(uri['authority']); - - for (i = 0; i < parts.length; ++i) { - uri[authKeys[i]] = parts[i] || ''; + var parts = input.match(hawk.utils.uriRegex); + if (!parts) { + return { host: '', port: '', resource: '' }; } - if (uri.port === '') { - uri.port = (uri.protocol.toLowerCase() === 'http' ? '80' : (uri.protocol.toLowerCase() === 'https' ? '443' : '')); - } + var scheme = parts[1].toLowerCase(); + var uri = { + host: parts[2], + port: parts[3] || (scheme === 'http' ? '80' : (scheme === 'https' ? '443' : '')), + resource: parts[4] + }; return uri; }, diff --git a/package.json b/package.json index f41a0ea..72aeaa6 100755 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "hawk", "description": "HTTP Hawk Authentication Scheme", - "version": "3.1.0", + "version": "3.1.1", "author": "Eran Hammer (http://hueniverse.com)", "contributors": [], "repository": "git://github.com/hueniverse/hawk", diff --git a/test/browser.js b/test/browser.js index 8ca6ca3..9bec675 100755 --- a/test/browser.js +++ b/test/browser.js @@ -44,15 +44,15 @@ describe('Browser', function () { port: 80 }; - credentialsFunc('123456', function (err, credentials) { + credentialsFunc('123456', function (err, credentials1) { - var bewit = Browser.client.bewit('http://example.com/resource/4?a=1&b=2', { credentials: credentials, ttlSec: 60 * 60 * 24 * 365 * 100, ext: 'some-app-data' }); + var bewit = Browser.client.bewit('http://example.com/resource/4?a=1&b=2', { credentials: credentials1, ttlSec: 60 * 60 * 24 * 365 * 100, ext: 'some-app-data' }); req.url += '&bewit=' + bewit; - Hawk.uri.authenticate(req, credentialsFunc, {}, function (err, credentials, attributes) { + Hawk.uri.authenticate(req, credentialsFunc, {}, function (err, credentials2, attributes) { expect(err).to.not.exist(); - expect(credentials.user).to.equal('steve'); + expect(credentials2.user).to.equal('steve'); expect(attributes.ext).to.equal('some-app-data'); done(); }); @@ -68,15 +68,15 @@ describe('Browser', function () { port: 80 }; - credentialsFunc('123456', function (err, credentials) { + credentialsFunc('123456', function (err, credentials1) { - var bewit = Browser.client.bewit('http://example.com/resource/4?a=1&b=2', { credentials: credentials, ttlSec: 60 * 60 * 24 * 365 * 100 }); + var bewit = Browser.client.bewit('http://example.com/resource/4?a=1&b=2', { credentials: credentials1, ttlSec: 60 * 60 * 24 * 365 * 100 }); req.url += '&bewit=' + bewit; - Hawk.uri.authenticate(req, credentialsFunc, {}, function (err, credentials, attributes) { + Hawk.uri.authenticate(req, credentialsFunc, {}, function (err, credentials2, attributes) { expect(err).to.not.exist(); - expect(credentials.user).to.equal('steve'); + expect(credentials2.user).to.equal('steve'); done(); }); }); @@ -242,15 +242,15 @@ describe('Browser', function () { port: 8080 }; - credentialsFunc('123456', function (err, credentials) { + credentialsFunc('123456', function (err, credentials1) { - req.authorization = Browser.client.header('http://example.com:8080/resource/4?filter=a', req.method, { credentials: credentials, ext: 'some-app-data' }).field; + req.authorization = Browser.client.header('http://example.com:8080/resource/4?filter=a', req.method, { credentials: credentials1, ext: 'some-app-data' }).field; expect(req.authorization).to.exist(); - Hawk.server.authenticate(req, credentialsFunc, {}, function (err, credentials, artifacts) { + Hawk.server.authenticate(req, credentialsFunc, {}, function (err, credentials2, artifacts) { expect(err).to.not.exist(); - expect(credentials.user).to.equal('steve'); + expect(credentials2.user).to.equal('steve'); expect(artifacts.ext).to.equal('some-app-data'); done(); }); @@ -270,17 +270,17 @@ describe('Browser', function () { var payload = 'some not so random text'; - credentialsFunc('123456', function (err, credentials) { + credentialsFunc('123456', function (err, credentials1) { - var reqHeader = Browser.client.header('http://example.com:8080/resource/4?filter=a', req.method, { credentials: credentials, ext: 'some-app-data', payload: payload, contentType: req.headers['content-type'] }); + var reqHeader = Browser.client.header('http://example.com:8080/resource/4?filter=a', req.method, { credentials: credentials1, ext: 'some-app-data', payload: payload, contentType: req.headers['content-type'] }); req.headers.authorization = reqHeader.field; - Hawk.server.authenticate(req, credentialsFunc, {}, function (err, credentials, artifacts) { + Hawk.server.authenticate(req, credentialsFunc, {}, function (err, credentials2, artifacts) { expect(err).to.not.exist(); - expect(credentials.user).to.equal('steve'); + expect(credentials2.user).to.equal('steve'); expect(artifacts.ext).to.equal('some-app-data'); - expect(Hawk.server.authenticatePayload(payload, credentials, artifacts, req.headers['content-type'])).to.equal(true); + expect(Hawk.server.authenticatePayload(payload, credentials2, artifacts, req.headers['content-type'])).to.equal(true); var res = { headers: { @@ -292,10 +292,10 @@ describe('Browser', function () { } }; - res.headers['server-authorization'] = Hawk.server.header(credentials, artifacts, { payload: 'some reply', contentType: 'text/plain', ext: 'response-specific' }); + res.headers['server-authorization'] = Hawk.server.header(credentials2, artifacts, { payload: 'some reply', contentType: 'text/plain', ext: 'response-specific' }); expect(res.headers['server-authorization']).to.exist(); - expect(Browser.client.authenticate(res, credentials, artifacts, { payload: 'some reply' })).to.equal(true); + expect(Browser.client.authenticate(res, credentials2, artifacts, { payload: 'some reply' })).to.equal(true); done(); }); }); @@ -314,17 +314,17 @@ describe('Browser', function () { var payload = 'some not so random text'; - credentialsFunc('123456', function (err, credentials) { + credentialsFunc('123456', function (err, credentials1) { - var reqHeader = Browser.client.header('http://example.com:8080/resource/4?filter=a', req.method, { credentials: credentials, ext: 'some-app-data', payload: payload, contentType: req.headers['content-type'] }); + var reqHeader = Browser.client.header('http://example.com:8080/resource/4?filter=a', req.method, { credentials: credentials1, ext: 'some-app-data', payload: payload, contentType: req.headers['content-type'] }); req.headers.authorization = reqHeader.field; - Hawk.server.authenticate(req, credentialsFunc, {}, function (err, credentials, artifacts) { + Hawk.server.authenticate(req, credentialsFunc, {}, function (err, credentials2, artifacts) { expect(err).to.not.exist(); - expect(credentials.user).to.equal('steve'); + expect(credentials2.user).to.equal('steve'); expect(artifacts.ext).to.equal('some-app-data'); - expect(Hawk.server.authenticatePayload(payload, credentials, artifacts, req.headers['content-type'])).to.equal(true); + expect(Hawk.server.authenticatePayload(payload, credentials2, artifacts, req.headers['content-type'])).to.equal(true); var res = { headers: { @@ -336,10 +336,10 @@ describe('Browser', function () { } }; - res.headers['server-authorization'] = Hawk.server.header(credentials, artifacts, { payload: 'some reply', contentType: 'text/plain', ext: 'response-specific' }); + res.headers['server-authorization'] = Hawk.server.header(credentials2, artifacts, { payload: 'some reply', contentType: 'text/plain', ext: 'response-specific' }); expect(res.headers['server-authorization']).to.exist(); - expect(Browser.client.authenticate(res, credentials, artifacts, { payload: 'some reply' })).to.equal(true); + expect(Browser.client.authenticate(res, credentials2, artifacts, { payload: 'some reply' })).to.equal(true); done(); }); }); @@ -354,15 +354,15 @@ describe('Browser', function () { port: 8080 }; - credentialsFunc('123456', function (err, credentials) { + credentialsFunc('123456', function (err, credentials1) { - req.authorization = Browser.client.header('http://example.com:8080/resource/4?filter=a', req.method, { credentials: credentials, ext: 'some-app-data', localtimeOffsetMsec: 100000 }).field; + req.authorization = Browser.client.header('http://example.com:8080/resource/4?filter=a', req.method, { credentials: credentials1, ext: 'some-app-data', localtimeOffsetMsec: 100000 }).field; expect(req.authorization).to.exist(); - Hawk.server.authenticate(req, credentialsFunc, { localtimeOffsetMsec: 100000 }, function (err, credentials, artifacts) { + Hawk.server.authenticate(req, credentialsFunc, { localtimeOffsetMsec: 100000 }, function (err, credentials2, artifacts) { expect(err).to.not.exist(); - expect(credentials.user).to.equal('steve'); + expect(credentials2.user).to.equal('steve'); expect(artifacts.ext).to.equal('some-app-data'); done(); }); @@ -382,17 +382,17 @@ describe('Browser', function () { var payload = 'some not so random text'; - credentialsFunc('123456', function (err, credentials) { + credentialsFunc('123456', function (err, credentials1) { - var reqHeader = Browser.client.header('http://example.com:8080/resource/4?filter=a', req.method, { credentials: credentials, ext: 'some-app-data', payload: payload, contentType: req.headers['content-type'] }); + var reqHeader = Browser.client.header('http://example.com:8080/resource/4?filter=a', req.method, { credentials: credentials1, ext: 'some-app-data', payload: payload, contentType: req.headers['content-type'] }); req.headers.authorization = reqHeader.field; - Hawk.server.authenticate(req, credentialsFunc, {}, function (err, credentials, artifacts) { + Hawk.server.authenticate(req, credentialsFunc, {}, function (err, credentials2, artifacts) { expect(err).to.not.exist(); - expect(credentials.user).to.equal('steve'); + expect(credentials2.user).to.equal('steve'); expect(artifacts.ext).to.equal('some-app-data'); - expect(Hawk.server.authenticatePayload(payload, credentials, artifacts, req.headers['content-type'])).to.equal(true); + expect(Hawk.server.authenticatePayload(payload, credentials2, artifacts, req.headers['content-type'])).to.equal(true); var res = { headers: { @@ -404,10 +404,10 @@ describe('Browser', function () { } }; - res.headers['server-authorization'] = Hawk.server.header(credentials, artifacts); + res.headers['server-authorization'] = Hawk.server.header(credentials2, artifacts); expect(res.headers['server-authorization']).to.exist(); - expect(Browser.client.authenticate(res, credentials, artifacts)).to.equal(true); + expect(Browser.client.authenticate(res, credentials2, artifacts)).to.equal(true); done(); }); }); @@ -426,17 +426,17 @@ describe('Browser', function () { var payload = 'some not so random text'; - credentialsFunc('123456', function (err, credentials) { + credentialsFunc('123456', function (err, credentials1) { - var reqHeader = Browser.client.header('http://example.com:8080/resource/4?filter=a', req.method, { credentials: credentials, ext: 'some-app-data', payload: payload, contentType: req.headers['content-type'] }); + var reqHeader = Browser.client.header('http://example.com:8080/resource/4?filter=a', req.method, { credentials: credentials1, ext: 'some-app-data', payload: payload, contentType: req.headers['content-type'] }); req.headers.authorization = reqHeader.field; - Hawk.server.authenticate(req, credentialsFunc, {}, function (err, credentials, artifacts) { + Hawk.server.authenticate(req, credentialsFunc, {}, function (err, credentials2, artifacts) { expect(err).to.not.exist(); - expect(credentials.user).to.equal('steve'); + expect(credentials2.user).to.equal('steve'); expect(artifacts.ext).to.equal('some-app-data'); - expect(Hawk.server.authenticatePayload(payload, credentials, artifacts, req.headers['content-type'])).to.equal(true); + expect(Hawk.server.authenticatePayload(payload, credentials2, artifacts, req.headers['content-type'])).to.equal(true); var res = { headers: { @@ -448,7 +448,7 @@ describe('Browser', function () { } }; - expect(Browser.client.authenticate(res, credentials, artifacts)).to.equal(true); + expect(Browser.client.authenticate(res, credentials2, artifacts)).to.equal(true); done(); }); }); @@ -463,14 +463,14 @@ describe('Browser', function () { port: 8080 }; - credentialsFunc('123456', function (err, credentials) { + credentialsFunc('123456', function (err, credentials1) { Browser.utils.setNtpOffset(60 * 60 * 1000); - var header = Browser.client.header('http://example.com:8080/resource/4?filter=a', req.method, { credentials: credentials, ext: 'some-app-data' }); + var header = Browser.client.header('http://example.com:8080/resource/4?filter=a', req.method, { credentials: credentials1, ext: 'some-app-data' }); req.authorization = header.field; expect(req.authorization).to.exist(); - Hawk.server.authenticate(req, credentialsFunc, {}, function (err, credentials, artifacts) { + Hawk.server.authenticate(req, credentialsFunc, {}, function (err, credentials2, artifacts2) { expect(err).to.exist(); expect(err.message).to.equal('Stale timestamp'); @@ -479,24 +479,24 @@ describe('Browser', function () { headers: { 'www-authenticate': err.output.headers['WWW-Authenticate'] }, - getResponseHeader: function (header) { + getResponseHeader: function (lookup) { - return res.headers[header.toLowerCase()]; + return res.headers[lookup.toLowerCase()]; } }; expect(Browser.utils.getNtpOffset()).to.equal(60 * 60 * 1000); - expect(Browser.client.authenticate(res, credentials, header.artifacts)).to.equal(true); + expect(Browser.client.authenticate(res, credentials2, header.artifacts)).to.equal(true); expect(Browser.utils.getNtpOffset()).to.equal(0); - req.authorization = Browser.client.header('http://example.com:8080/resource/4?filter=a', req.method, { credentials: credentials, ext: 'some-app-data' }).field; + req.authorization = Browser.client.header('http://example.com:8080/resource/4?filter=a', req.method, { credentials: credentials2, ext: 'some-app-data' }).field; expect(req.authorization).to.exist(); - Hawk.server.authenticate(req, credentialsFunc, {}, function (err, credentials, artifacts) { + Hawk.server.authenticate(req, credentialsFunc, {}, function (err, credentials3, artifacts3) { expect(err).to.not.exist(); - expect(credentials.user).to.equal('steve'); - expect(artifacts.ext).to.equal('some-app-data'); + expect(credentials3.user).to.equal('steve'); + expect(artifacts3.ext).to.equal('some-app-data'); done(); }); }); @@ -512,18 +512,18 @@ describe('Browser', function () { port: 8080 }; - credentialsFunc('123456', function (err, credentials) { + credentialsFunc('123456', function (err, credentials1) { var localStorage = new Browser.internals.LocalStorage(); Browser.utils.setStorage(localStorage); Browser.utils.setNtpOffset(60 * 60 * 1000); - var header = Browser.client.header('http://example.com:8080/resource/4?filter=a', req.method, { credentials: credentials, ext: 'some-app-data' }); + var header = Browser.client.header('http://example.com:8080/resource/4?filter=a', req.method, { credentials: credentials1, ext: 'some-app-data' }); req.authorization = header.field; expect(req.authorization).to.exist(); - Hawk.server.authenticate(req, credentialsFunc, {}, function (err, credentials, artifacts) { + Hawk.server.authenticate(req, credentialsFunc, {}, function (err, credentials2, artifacts2) { expect(err).to.exist(); expect(err.message).to.equal('Stale timestamp'); @@ -532,26 +532,26 @@ describe('Browser', function () { headers: { 'www-authenticate': err.output.headers['WWW-Authenticate'] }, - getResponseHeader: function (header) { + getResponseHeader: function (lookup) { - return res.headers[header.toLowerCase()]; + return res.headers[lookup.toLowerCase()]; } }; expect(parseInt(localStorage.getItem('hawk_ntp_offset'))).to.equal(60 * 60 * 1000); expect(Browser.utils.getNtpOffset()).to.equal(60 * 60 * 1000); - expect(Browser.client.authenticate(res, credentials, header.artifacts)).to.equal(true); + expect(Browser.client.authenticate(res, credentials2, header.artifacts)).to.equal(true); expect(Browser.utils.getNtpOffset()).to.equal(0); expect(parseInt(localStorage.getItem('hawk_ntp_offset'))).to.equal(0); - req.authorization = Browser.client.header('http://example.com:8080/resource/4?filter=a', req.method, { credentials: credentials, ext: 'some-app-data' }).field; + req.authorization = Browser.client.header('http://example.com:8080/resource/4?filter=a', req.method, { credentials: credentials2, ext: 'some-app-data' }).field; expect(req.authorization).to.exist(); - Hawk.server.authenticate(req, credentialsFunc, {}, function (err, credentials, artifacts) { + Hawk.server.authenticate(req, credentialsFunc, {}, function (err, credentials3, artifacts3) { expect(err).to.not.exist(); - expect(credentials.user).to.equal('steve'); - expect(artifacts.ext).to.equal('some-app-data'); + expect(credentials3.user).to.equal('steve'); + expect(artifacts3.ext).to.equal('some-app-data'); done(); }); }); @@ -571,17 +571,17 @@ describe('Browser', function () { var payload = 'some not so random text'; - credentialsFunc('123456', function (err, credentials) { + credentialsFunc('123456', function (err, credentials1) { - var reqHeader = Browser.client.header('http://example.com:8080/resource/4?filter=a', req.method, { credentials: credentials, ext: 'some-app-data', payload: payload, contentType: req.headers['content-type'] }); + var reqHeader = Browser.client.header('http://example.com:8080/resource/4?filter=a', req.method, { credentials: credentials1, ext: 'some-app-data', payload: payload, contentType: req.headers['content-type'] }); req.headers.authorization = reqHeader.field; - Hawk.server.authenticate(req, credentialsFunc, {}, function (err, credentials, artifacts) { + Hawk.server.authenticate(req, credentialsFunc, {}, function (err, credentials2, artifacts) { expect(err).to.not.exist(); - expect(credentials.user).to.equal('steve'); + expect(credentials2.user).to.equal('steve'); expect(artifacts.ext).to.equal('some-app-data'); - expect(Hawk.server.authenticatePayload(payload, credentials, artifacts, req.headers['content-type'])).to.equal(true); + expect(Hawk.server.authenticatePayload(payload, credentials2, artifacts, req.headers['content-type'])).to.equal(true); var res = { headers: { @@ -593,10 +593,10 @@ describe('Browser', function () { } }; - res.headers['server-authorization'] = Hawk.server.header(credentials, artifacts); + res.headers['server-authorization'] = Hawk.server.header(credentials2, artifacts); expect(res.headers['server-authorization']).to.exist(); - expect(Browser.client.authenticate(res, credentials, artifacts, { payload: 'some reply' })).to.equal(false); + expect(Browser.client.authenticate(res, credentials2, artifacts, { payload: 'some reply' })).to.equal(false); done(); }); }); @@ -611,13 +611,13 @@ describe('Browser', function () { port: 8080 }; - credentialsFunc('123456', function (err, credentials) { + credentialsFunc('123456', function (err, credentials1) { - req.authorization = Browser.client.header('http://example.com:8080/resource/4?filter=a', req.method, { credentials: credentials, payload: 'hola!', ext: 'some-app-data' }).field; - Hawk.server.authenticate(req, credentialsFunc, {}, function (err, credentials, artifacts) { + req.authorization = Browser.client.header('http://example.com:8080/resource/4?filter=a', req.method, { credentials: credentials1, payload: 'hola!', ext: 'some-app-data' }).field; + Hawk.server.authenticate(req, credentialsFunc, {}, function (err, credentials2, artifacts) { expect(err).to.not.exist(); - expect(credentials.user).to.equal('steve'); + expect(credentials2.user).to.equal('steve'); expect(artifacts.ext).to.equal('some-app-data'); done(); }); @@ -633,16 +633,16 @@ describe('Browser', function () { port: 8080 }; - credentialsFunc('123456', function (err, credentials) { + credentialsFunc('123456', function (err, credentials1) { - req.authorization = Browser.client.header('http://example.com:8080/resource/4?filter=a', req.method, { credentials: credentials, payload: 'hola!', ext: 'some-app-data' }).field; - Hawk.server.authenticate(req, credentialsFunc, {}, function (err, credentials, artifacts) { + req.authorization = Browser.client.header('http://example.com:8080/resource/4?filter=a', req.method, { credentials: credentials1, payload: 'hola!', ext: 'some-app-data' }).field; + Hawk.server.authenticate(req, credentialsFunc, {}, function (err, credentials2, artifacts) { expect(err).to.not.exist(); - expect(credentials.user).to.equal('steve'); + expect(credentials2.user).to.equal('steve'); expect(artifacts.ext).to.equal('some-app-data'); - expect(Hawk.server.authenticatePayload('hola!', credentials, artifacts)).to.be.true(); - expect(Hawk.server.authenticatePayload('hello!', credentials, artifacts)).to.be.false(); + expect(Hawk.server.authenticatePayload('hola!', credentials2, artifacts)).to.be.true(); + expect(Hawk.server.authenticatePayload('hello!', credentials2, artifacts)).to.be.false(); done(); }); }); @@ -657,13 +657,13 @@ describe('Browser', function () { port: 8080 }; - credentialsFunc('123456', function (err, credentials) { + credentialsFunc('123456', function (err, credentials1) { - req.authorization = Browser.client.header('http://example.com:8080/resource/4?filter=a', req.method, { credentials: credentials, ext: 'some-app-data', app: 'asd23ased' }).field; - Hawk.server.authenticate(req, credentialsFunc, {}, function (err, credentials, artifacts) { + req.authorization = Browser.client.header('http://example.com:8080/resource/4?filter=a', req.method, { credentials: credentials1, ext: 'some-app-data', app: 'asd23ased' }).field; + Hawk.server.authenticate(req, credentialsFunc, {}, function (err, credentials2, artifacts) { expect(err).to.not.exist(); - expect(credentials.user).to.equal('steve'); + expect(credentials2.user).to.equal('steve'); expect(artifacts.ext).to.equal('some-app-data'); expect(artifacts.app).to.equal('asd23ased'); done(); @@ -680,13 +680,13 @@ describe('Browser', function () { port: 8080 }; - credentialsFunc('123456', function (err, credentials) { + credentialsFunc('123456', function (err, credentials1) { - req.authorization = Browser.client.header('http://example.com:8080/resource/4?filter=a', req.method, { credentials: credentials, ext: 'some-app-data', app: 'asd23ased', dlg: '23434szr3q4d' }).field; - Hawk.server.authenticate(req, credentialsFunc, {}, function (err, credentials, artifacts) { + req.authorization = Browser.client.header('http://example.com:8080/resource/4?filter=a', req.method, { credentials: credentials1, ext: 'some-app-data', app: 'asd23ased', dlg: '23434szr3q4d' }).field; + Hawk.server.authenticate(req, credentialsFunc, {}, function (err, credentials2, artifacts) { expect(err).to.not.exist(); - expect(credentials.user).to.equal('steve'); + expect(credentials2.user).to.equal('steve'); expect(artifacts.ext).to.equal('some-app-data'); expect(artifacts.app).to.equal('asd23ased'); expect(artifacts.dlg).to.equal('23434szr3q4d'); @@ -704,10 +704,10 @@ describe('Browser', function () { port: 8080 }; - credentialsFunc('123456', function (err, credentials) { + credentialsFunc('123456', function (err, credentials1) { - req.authorization = Browser.client.header('http://example.com:8080/resource/4?filter=a', req.method, { credentials: credentials, payload: 'hola!', ext: 'some-app-data' }).field; - Hawk.server.authenticate(req, credentialsFunc, { payload: 'byebye!' }, function (err, credentials, artifacts) { + req.authorization = Browser.client.header('http://example.com:8080/resource/4?filter=a', req.method, { credentials: credentials1, payload: 'hola!', ext: 'some-app-data' }).field; + Hawk.server.authenticate(req, credentialsFunc, { payload: 'byebye!' }, function (err, credentials2, artifacts) { expect(err).to.exist(); expect(err.output.payload.message).to.equal('Bad payload hash'); @@ -725,15 +725,15 @@ describe('Browser', function () { port: 8080 }; - credentialsFunc('123456', function (err, credentials) { + credentialsFunc('123456', function (err, credentials1) { - req.authorization = Browser.client.header('http://example.com:8080/resource/4?filter=a', req.method, { credentials: credentials, ext: 'some-app-data' }).field; + req.authorization = Browser.client.header('http://example.com:8080/resource/4?filter=a', req.method, { credentials: credentials1, ext: 'some-app-data' }).field; req.url = '/something/else'; - Hawk.server.authenticate(req, credentialsFunc, {}, function (err, credentials, artifacts) { + Hawk.server.authenticate(req, credentialsFunc, {}, function (err, credentials2, artifacts) { expect(err).to.exist(); - expect(credentials).to.exist(); + expect(credentials2).to.exist(); done(); }); }); @@ -1123,15 +1123,15 @@ describe('Browser', function () { it('generates an authorization then successfully parse it', function (done) { - credentialsFunc('123456', function (err, credentials) { + credentialsFunc('123456', function (err, credentials1) { - var auth = Browser.client.message('example.com', 8080, 'some message', { credentials: credentials }); + var auth = Browser.client.message('example.com', 8080, 'some message', { credentials: credentials1 }); expect(auth).to.exist(); - Hawk.server.authenticateMessage('example.com', 8080, 'some message', auth, credentialsFunc, {}, function (err, credentials) { + Hawk.server.authenticateMessage('example.com', 8080, 'some message', auth, credentialsFunc, {}, function (err, credentials2) { expect(err).to.not.exist(); - expect(credentials.user).to.equal('steve'); + expect(credentials2.user).to.equal('steve'); done(); }); }); @@ -1429,44 +1429,50 @@ describe('Browser', function () { describe('parseUri()', function () { + it('returns empty object on invalid', function (done) { + + var uri = Browser.utils.parseUri('ftp'); + expect(uri).to.deep.equal({ host: '', port: '', resource: '' }); + done(); + }); + it('returns empty port when unknown scheme', function (done) { - var uri = Browser.utils.parseUri('ftp://domain'); + var uri = Browser.utils.parseUri('ftp://example.com'); expect(uri.port).to.equal(''); done(); }); it('returns default port when missing', function (done) { - var uri = Browser.utils.parseUri('http://'); + var uri = Browser.utils.parseUri('http://example.com'); expect(uri.port).to.equal('80'); done(); }); it('handles unusual characters correctly', function (done) { + var parts = { protocol: 'http+vnd.my-extension', - user: 'user!$&\'()*+,;=%40my-domain.com', + user: 'user!$&\'()*+,;=%40my-domain.com', password: 'pass!$&\'()*+,;=%40:word', hostname: 'foo-bar.com', - port: '99', + port: '99', pathname: '/path/%40/!$&\'()*+,;=:@/', - query: 'query%40/!$&\'()*+,;=:@/?', + query: 'query%40/!$&\'()*+,;=:@/?', fragment: 'fragm%40/!$&\'()*+,;=:@/?' }; - parts.userInfo = parts.user + ':' + parts.password; + parts.userInfo = parts.user + ':' + parts.password; parts.authority = parts.userInfo + '@' + parts.hostname + ':' + parts.port; - parts.relative = parts.pathname + '?' + parts.query; - parts.resource = parts.relative + '#' + parts.fragment; - parts.source = parts.protocol + '://' + parts.authority + parts.resource; + parts.relative = parts.pathname + '?' + parts.query; + parts.resource = parts.relative + '#' + parts.fragment; + parts.source = parts.protocol + '://' + parts.authority + parts.resource; var uri = Browser.utils.parseUri(parts.source); - - for (var part in parts) { - expect(uri[part]).to.equal(parts[part]); - } - + expect(uri.host).to.equal('foo-bar.com'); + expect(uri.port).to.equal('99'); + expect(uri.resource).to.equal(parts.pathname + '?' + parts.query); done(); }); }); diff --git a/test/index.js b/test/index.js index 39f2c5b..e67afab 100755 --- a/test/index.js +++ b/test/index.js @@ -42,15 +42,15 @@ describe('Hawk', function () { port: 8080 }; - credentialsFunc('123456', function (err, credentials) { + credentialsFunc('123456', function (err, credentials1) { - req.authorization = Hawk.client.header(Url.parse('http://example.com:8080/resource/4?filter=a'), req.method, { credentials: credentials, ext: 'some-app-data' }).field; + req.authorization = Hawk.client.header(Url.parse('http://example.com:8080/resource/4?filter=a'), req.method, { credentials: credentials1, ext: 'some-app-data' }).field; expect(req.authorization).to.exist(); - Hawk.server.authenticate(req, credentialsFunc, {}, function (err, credentials, artifacts) { + Hawk.server.authenticate(req, credentialsFunc, {}, function (err, credentials2, artifacts) { expect(err).to.not.exist(); - expect(credentials.user).to.equal('steve'); + expect(credentials2.user).to.equal('steve'); expect(artifacts.ext).to.equal('some-app-data'); done(); }); @@ -70,17 +70,17 @@ describe('Hawk', function () { var payload = 'some not so random text'; - credentialsFunc('123456', function (err, credentials) { + credentialsFunc('123456', function (err, credentials1) { - var reqHeader = Hawk.client.header('http://example.com:8080/resource/4?filter=a', req.method, { credentials: credentials, ext: 'some-app-data', payload: payload, contentType: req.headers['content-type'] }); + var reqHeader = Hawk.client.header('http://example.com:8080/resource/4?filter=a', req.method, { credentials: credentials1, ext: 'some-app-data', payload: payload, contentType: req.headers['content-type'] }); req.headers.authorization = reqHeader.field; - Hawk.server.authenticate(req, credentialsFunc, {}, function (err, credentials, artifacts) { + Hawk.server.authenticate(req, credentialsFunc, {}, function (err, credentials2, artifacts) { expect(err).to.not.exist(); - expect(credentials.user).to.equal('steve'); + expect(credentials2.user).to.equal('steve'); expect(artifacts.ext).to.equal('some-app-data'); - expect(Hawk.server.authenticatePayload(payload, credentials, artifacts, req.headers['content-type'])).to.equal(true); + expect(Hawk.server.authenticatePayload(payload, credentials2, artifacts, req.headers['content-type'])).to.equal(true); var res = { headers: { @@ -88,10 +88,10 @@ describe('Hawk', function () { } }; - res.headers['server-authorization'] = Hawk.server.header(credentials, artifacts, { payload: 'some reply', contentType: 'text/plain', ext: 'response-specific' }); + res.headers['server-authorization'] = Hawk.server.header(credentials2, artifacts, { payload: 'some reply', contentType: 'text/plain', ext: 'response-specific' }); expect(res.headers['server-authorization']).to.exist(); - expect(Hawk.client.authenticate(res, credentials, artifacts, { payload: 'some reply' })).to.equal(true); + expect(Hawk.client.authenticate(res, credentials2, artifacts, { payload: 'some reply' })).to.equal(true); done(); }); }); @@ -110,17 +110,17 @@ describe('Hawk', function () { var payload = 'some not so random text'; - credentialsFunc('123456', function (err, credentials) { + credentialsFunc('123456', function (err, credentials1) { - var reqHeader = Hawk.client.header('http://example.com:8080/resource/4?filter=a', req.method, { credentials: credentials, ext: 'some-app-data', payload: payload, contentType: req.headers['content-type'] }); + var reqHeader = Hawk.client.header('http://example.com:8080/resource/4?filter=a', req.method, { credentials: credentials1, ext: 'some-app-data', payload: payload, contentType: req.headers['content-type'] }); req.headers.authorization = reqHeader.field; - Hawk.server.authenticate(req, credentialsFunc, {}, function (err, credentials, artifacts) { + Hawk.server.authenticate(req, credentialsFunc, {}, function (err, credentials2, artifacts) { expect(err).to.not.exist(); - expect(credentials.user).to.equal('steve'); + expect(credentials2.user).to.equal('steve'); expect(artifacts.ext).to.equal('some-app-data'); - expect(Hawk.server.authenticatePayload(payload, credentials, artifacts, req.headers['content-type'])).to.equal(true); + expect(Hawk.server.authenticatePayload(payload, credentials2, artifacts, req.headers['content-type'])).to.equal(true); var res = { headers: { @@ -128,10 +128,10 @@ describe('Hawk', function () { } }; - res.headers['server-authorization'] = Hawk.server.header(credentials, artifacts, { payload: 'some reply', contentType: 'text/plain', ext: 'response-specific' }); + res.headers['server-authorization'] = Hawk.server.header(credentials2, artifacts, { payload: 'some reply', contentType: 'text/plain', ext: 'response-specific' }); expect(res.headers['server-authorization']).to.exist(); - expect(Hawk.client.authenticate(res, credentials, artifacts, { payload: 'some reply' })).to.equal(true); + expect(Hawk.client.authenticate(res, credentials2, artifacts, { payload: 'some reply' })).to.equal(true); done(); }); }); @@ -150,17 +150,17 @@ describe('Hawk', function () { var payload = 'some not so random text'; - credentialsFunc('123456', function (err, credentials) { + credentialsFunc('123456', function (err, credentials1) { - var reqHeader = Hawk.client.header('http://example.com:8080/resource/4?filter=a', req.method, { credentials: credentials, ext: 'some-app-data', payload: payload, contentType: req.headers['content-type'] }); + var reqHeader = Hawk.client.header('http://example.com:8080/resource/4?filter=a', req.method, { credentials: credentials1, ext: 'some-app-data', payload: payload, contentType: req.headers['content-type'] }); req.headers.authorization = reqHeader.field; - Hawk.server.authenticate(req, credentialsFunc, {}, function (err, credentials, artifacts) { + Hawk.server.authenticate(req, credentialsFunc, {}, function (err, credentials2, artifacts) { expect(err).to.not.exist(); - expect(credentials.user).to.equal('steve'); + expect(credentials2.user).to.equal('steve'); expect(artifacts.ext).to.equal('some-app-data'); - expect(Hawk.server.authenticatePayload(payload, credentials, artifacts, req.headers['content-type'])).to.equal(true); + expect(Hawk.server.authenticatePayload(payload, credentials2, artifacts, req.headers['content-type'])).to.equal(true); var res = { headers: { @@ -168,10 +168,10 @@ describe('Hawk', function () { } }; - res.headers['server-authorization'] = Hawk.server.header(credentials, artifacts); + res.headers['server-authorization'] = Hawk.server.header(credentials2, artifacts); expect(res.headers['server-authorization']).to.exist(); - expect(Hawk.client.authenticate(res, credentials, artifacts)).to.equal(true); + expect(Hawk.client.authenticate(res, credentials2, artifacts)).to.equal(true); done(); }); }); @@ -190,17 +190,17 @@ describe('Hawk', function () { var payload = 'some not so random text'; - credentialsFunc('123456', function (err, credentials) { + credentialsFunc('123456', function (err, credentials1) { - var reqHeader = Hawk.client.header('http://example.com:8080/resource/4?filter=a', req.method, { credentials: credentials, ext: 'some-app-data', payload: payload, contentType: req.headers['content-type'] }); + var reqHeader = Hawk.client.header('http://example.com:8080/resource/4?filter=a', req.method, { credentials: credentials1, ext: 'some-app-data', payload: payload, contentType: req.headers['content-type'] }); req.headers.authorization = reqHeader.field; - Hawk.server.authenticate(req, credentialsFunc, {}, function (err, credentials, artifacts) { + Hawk.server.authenticate(req, credentialsFunc, {}, function (err, credentials2, artifacts) { expect(err).to.not.exist(); - expect(credentials.user).to.equal('steve'); + expect(credentials2.user).to.equal('steve'); expect(artifacts.ext).to.equal('some-app-data'); - expect(Hawk.server.authenticatePayload(payload, credentials, artifacts, req.headers['content-type'])).to.equal(true); + expect(Hawk.server.authenticatePayload(payload, credentials2, artifacts, req.headers['content-type'])).to.equal(true); var res = { headers: { @@ -208,10 +208,10 @@ describe('Hawk', function () { } }; - res.headers['server-authorization'] = Hawk.server.header(credentials, artifacts); + res.headers['server-authorization'] = Hawk.server.header(credentials2, artifacts); expect(res.headers['server-authorization']).to.exist(); - expect(Hawk.client.authenticate(res, credentials, artifacts, { payload: 'some reply' })).to.equal(false); + expect(Hawk.client.authenticate(res, credentials2, artifacts, { payload: 'some reply' })).to.equal(false); done(); }); }); @@ -226,13 +226,13 @@ describe('Hawk', function () { port: 8080 }; - credentialsFunc('123456', function (err, credentials) { + credentialsFunc('123456', function (err, credentials1) { - req.authorization = Hawk.client.header('http://example.com:8080/resource/4?filter=a', req.method, { credentials: credentials, payload: 'hola!', ext: 'some-app-data' }).field; - Hawk.server.authenticate(req, credentialsFunc, {}, function (err, credentials, artifacts) { + req.authorization = Hawk.client.header('http://example.com:8080/resource/4?filter=a', req.method, { credentials: credentials1, payload: 'hola!', ext: 'some-app-data' }).field; + Hawk.server.authenticate(req, credentialsFunc, {}, function (err, credentials2, artifacts) { expect(err).to.not.exist(); - expect(credentials.user).to.equal('steve'); + expect(credentials2.user).to.equal('steve'); expect(artifacts.ext).to.equal('some-app-data'); done(); }); @@ -248,16 +248,16 @@ describe('Hawk', function () { port: 8080 }; - credentialsFunc('123456', function (err, credentials) { + credentialsFunc('123456', function (err, credentials1) { - req.authorization = Hawk.client.header('http://example.com:8080/resource/4?filter=a', req.method, { credentials: credentials, payload: 'hola!', ext: 'some-app-data' }).field; - Hawk.server.authenticate(req, credentialsFunc, {}, function (err, credentials, artifacts) { + req.authorization = Hawk.client.header('http://example.com:8080/resource/4?filter=a', req.method, { credentials: credentials1, payload: 'hola!', ext: 'some-app-data' }).field; + Hawk.server.authenticate(req, credentialsFunc, {}, function (err, credentials2, artifacts) { expect(err).to.not.exist(); - expect(credentials.user).to.equal('steve'); + expect(credentials2.user).to.equal('steve'); expect(artifacts.ext).to.equal('some-app-data'); - expect(Hawk.server.authenticatePayload('hola!', credentials, artifacts)).to.be.true(); - expect(Hawk.server.authenticatePayload('hello!', credentials, artifacts)).to.be.false(); + expect(Hawk.server.authenticatePayload('hola!', credentials2, artifacts)).to.be.true(); + expect(Hawk.server.authenticatePayload('hello!', credentials2, artifacts)).to.be.false(); done(); }); }); @@ -272,13 +272,13 @@ describe('Hawk', function () { port: 8080 }; - credentialsFunc('123456', function (err, credentials) { + credentialsFunc('123456', function (err, credentials1) { - req.authorization = Hawk.client.header('http://example.com:8080/resource/4?filter=a', req.method, { credentials: credentials, payload: 'hola!', ext: 'some-app-data' }).field; - Hawk.server.authenticate(req, credentialsFunc, { payload: 'hola!' }, function (err, credentials, artifacts) { + req.authorization = Hawk.client.header('http://example.com:8080/resource/4?filter=a', req.method, { credentials: credentials1, payload: 'hola!', ext: 'some-app-data' }).field; + Hawk.server.authenticate(req, credentialsFunc, { payload: 'hola!' }, function (err, credentials2, artifacts) { expect(err).to.not.exist(); - expect(credentials.user).to.equal('steve'); + expect(credentials2.user).to.equal('steve'); expect(artifacts.ext).to.equal('some-app-data'); done(); }); @@ -294,13 +294,13 @@ describe('Hawk', function () { port: 8080 }; - credentialsFunc('123456', function (err, credentials) { + credentialsFunc('123456', function (err, credentials1) { - req.authorization = Hawk.client.header('http://example.com:8080/resource/4?filter=a', req.method, { credentials: credentials, ext: 'some-app-data', app: 'asd23ased' }).field; - Hawk.server.authenticate(req, credentialsFunc, {}, function (err, credentials, artifacts) { + req.authorization = Hawk.client.header('http://example.com:8080/resource/4?filter=a', req.method, { credentials: credentials1, ext: 'some-app-data', app: 'asd23ased' }).field; + Hawk.server.authenticate(req, credentialsFunc, {}, function (err, credentials2, artifacts) { expect(err).to.not.exist(); - expect(credentials.user).to.equal('steve'); + expect(credentials2.user).to.equal('steve'); expect(artifacts.ext).to.equal('some-app-data'); expect(artifacts.app).to.equal('asd23ased'); done(); @@ -317,13 +317,13 @@ describe('Hawk', function () { port: 8080 }; - credentialsFunc('123456', function (err, credentials) { + credentialsFunc('123456', function (err, credentials1) { - req.authorization = Hawk.client.header('http://example.com:8080/resource/4?filter=a', req.method, { credentials: credentials, ext: 'some-app-data', app: 'asd23ased', dlg: '23434szr3q4d' }).field; - Hawk.server.authenticate(req, credentialsFunc, {}, function (err, credentials, artifacts) { + req.authorization = Hawk.client.header('http://example.com:8080/resource/4?filter=a', req.method, { credentials: credentials1, ext: 'some-app-data', app: 'asd23ased', dlg: '23434szr3q4d' }).field; + Hawk.server.authenticate(req, credentialsFunc, {}, function (err, credentials2, artifacts) { expect(err).to.not.exist(); - expect(credentials.user).to.equal('steve'); + expect(credentials2.user).to.equal('steve'); expect(artifacts.ext).to.equal('some-app-data'); expect(artifacts.app).to.equal('asd23ased'); expect(artifacts.dlg).to.equal('23434szr3q4d'); @@ -341,10 +341,10 @@ describe('Hawk', function () { port: 8080 }; - credentialsFunc('123456', function (err, credentials) { + credentialsFunc('123456', function (err, credentials1) { - req.authorization = Hawk.client.header('http://example.com:8080/resource/4?filter=a', req.method, { credentials: credentials, payload: 'hola!', ext: 'some-app-data' }).field; - Hawk.server.authenticate(req, credentialsFunc, { payload: 'byebye!' }, function (err, credentials, artifacts) { + req.authorization = Hawk.client.header('http://example.com:8080/resource/4?filter=a', req.method, { credentials: credentials1, payload: 'hola!', ext: 'some-app-data' }).field; + Hawk.server.authenticate(req, credentialsFunc, { payload: 'byebye!' }, function (err, credentials2, artifacts) { expect(err).to.exist(); expect(err.output.payload.message).to.equal('Bad payload hash'); @@ -362,15 +362,15 @@ describe('Hawk', function () { port: 8080 }; - credentialsFunc('123456', function (err, credentials) { + credentialsFunc('123456', function (err, credentials1) { - req.authorization = Hawk.client.header('http://example.com:8080/resource/4?filter=a', req.method, { credentials: credentials, ext: 'some-app-data' }).field; + req.authorization = Hawk.client.header('http://example.com:8080/resource/4?filter=a', req.method, { credentials: credentials1, ext: 'some-app-data' }).field; req.url = '/something/else'; - Hawk.server.authenticate(req, credentialsFunc, {}, function (err, credentials, artifacts) { + Hawk.server.authenticate(req, credentialsFunc, {}, function (err, credentials2, artifacts) { expect(err).to.exist(); - expect(credentials).to.exist(); + expect(credentials2).to.exist(); done(); }); }); diff --git a/test/server.js b/test/server.js index b95b7cd..66ce36c 100755 --- a/test/server.js +++ b/test/server.js @@ -200,12 +200,12 @@ describe('Server', function () { } }; - Hawk.server.authenticate(req, credentialsFunc, options, function (err, credentials, artifacts) { + Hawk.server.authenticate(req, credentialsFunc, options, function (err, credentials1, artifacts1) { expect(err).to.not.exist(); - expect(credentials.user).to.equal('steve'); + expect(credentials1.user).to.equal('steve'); - Hawk.server.authenticate(req, credentialsFunc, options, function (err, credentials, artifacts) { + Hawk.server.authenticate(req, credentialsFunc, options, function (err, credentials2, artifacts2) { expect(err).to.exist(); expect(err.output.payload.message).to.equal('Invalid nonce'); @@ -232,7 +232,7 @@ describe('Server', function () { authorization: 'Hawk id="456", ts="1353788437", nonce="k3j4h2", mac="LXfmTnRzrLd9TD7yfH+4se46Bx6AHyhpM94hLCiNia4=", ext="hello"' }; - var credentialsFunc = function (id, callback) { + var credentialsFuncion = function (id, callback) { var credentials = { '123': { @@ -266,15 +266,15 @@ describe('Server', function () { } }; - Hawk.server.authenticate(reqSteve, credentialsFunc, options, function (err, credentials, artifacts) { + Hawk.server.authenticate(reqSteve, credentialsFuncion, options, function (err, credentials1, artifacts1) { expect(err).to.not.exist(); - expect(credentials.user).to.equal('steve'); + expect(credentials1.user).to.equal('steve'); - Hawk.server.authenticate(reqBob, credentialsFunc, options, function (err, credentials, artifacts) { + Hawk.server.authenticate(reqBob, credentialsFuncion, options, function (err, credentials2, artifacts2) { expect(err).to.not.exist(); - expect(credentials.user).to.equal('bob'); + expect(credentials2.user).to.equal('bob'); done(); }); }); @@ -579,12 +579,12 @@ describe('Server', function () { authorization: 'Hawk id="123", ts="1353788437", nonce="k3j4h2", mac="/qwS4UjfVWMcUyW6EEgUH4jlr7T/wuKe3dKijvTvSos=", ext="hello"' }; - var credentialsFunc = function (id, callback) { + var credentialsFuncion = function (id, callback) { return callback(new Error('Unknown user')); }; - Hawk.server.authenticate(req, credentialsFunc, { localtimeOffsetMsec: 1353788437000 - Hawk.utils.now() }, function (err, credentials, artifacts) { + Hawk.server.authenticate(req, credentialsFuncion, { localtimeOffsetMsec: 1353788437000 - Hawk.utils.now() }, function (err, credentials, artifacts) { expect(err).to.exist(); expect(err.message).to.equal('Unknown user'); @@ -602,12 +602,12 @@ describe('Server', function () { authorization: 'Hawk id="123", ts="1353788437", nonce="k3j4h2", mac="/qwS4UjfVWMcUyW6EEgUH4jlr7T/wuKe3dKijvTvSos=", ext="hello"' }; - var credentialsFunc = function (id, callback) { + var credentialsFuncion = function (id, callback) { return callback(new Error('Unknown user'), { some: 'value' }); }; - Hawk.server.authenticate(req, credentialsFunc, { localtimeOffsetMsec: 1353788437000 - Hawk.utils.now() }, function (err, credentials, artifacts) { + Hawk.server.authenticate(req, credentialsFuncion, { localtimeOffsetMsec: 1353788437000 - Hawk.utils.now() }, function (err, credentials, artifacts) { expect(err).to.exist(); expect(err.message).to.equal('Unknown user'); @@ -626,12 +626,12 @@ describe('Server', function () { authorization: 'Hawk id="123", ts="1353788437", nonce="k3j4h2", mac="/qwS4UjfVWMcUyW6EEgUH4jlr7T/wuKe3dKijvTvSos=", ext="hello"' }; - var credentialsFunc = function (id, callback) { + var credentialsFuncion = function (id, callback) { return callback(null, null); }; - Hawk.server.authenticate(req, credentialsFunc, { localtimeOffsetMsec: 1353788437000 - Hawk.utils.now() }, function (err, credentials, artifacts) { + Hawk.server.authenticate(req, credentialsFuncion, { localtimeOffsetMsec: 1353788437000 - Hawk.utils.now() }, function (err, credentials, artifacts) { expect(err).to.exist(); expect(err.output.payload.message).to.equal('Unknown credentials'); @@ -649,7 +649,7 @@ describe('Server', function () { authorization: 'Hawk id="123", ts="1353788437", nonce="k3j4h2", mac="/qwS4UjfVWMcUyW6EEgUH4jlr7T/wuKe3dKijvTvSos=", ext="hello"' }; - var credentialsFunc = function (id, callback) { + var credentialsFuncion = function (id, callback) { var credentials = { key: 'werxhqb98rpaxn39848xrunpaw3489ruxnpa98w4rxn', @@ -659,7 +659,7 @@ describe('Server', function () { return callback(null, credentials); }; - Hawk.server.authenticate(req, credentialsFunc, { localtimeOffsetMsec: 1353788437000 - Hawk.utils.now() }, function (err, credentials, artifacts) { + Hawk.server.authenticate(req, credentialsFuncion, { localtimeOffsetMsec: 1353788437000 - Hawk.utils.now() }, function (err, credentials, artifacts) { expect(err).to.exist(); expect(err.message).to.equal('Invalid credentials'); @@ -678,7 +678,7 @@ describe('Server', function () { authorization: 'Hawk id="123", ts="1353788437", nonce="k3j4h2", mac="/qwS4UjfVWMcUyW6EEgUH4jlr7T/wuKe3dKijvTvSos=", ext="hello"' }; - var credentialsFunc = function (id, callback) { + var credentialsFuncion = function (id, callback) { var credentials = { id: '23434d3q4d5345d', @@ -688,7 +688,7 @@ describe('Server', function () { return callback(null, credentials); }; - Hawk.server.authenticate(req, credentialsFunc, { localtimeOffsetMsec: 1353788437000 - Hawk.utils.now() }, function (err, credentials, artifacts) { + Hawk.server.authenticate(req, credentialsFuncion, { localtimeOffsetMsec: 1353788437000 - Hawk.utils.now() }, function (err, credentials, artifacts) { expect(err).to.exist(); expect(err.message).to.equal('Invalid credentials'); @@ -707,7 +707,7 @@ describe('Server', function () { authorization: 'Hawk id="123", ts="1353788437", nonce="k3j4h2", mac="/qwS4UjfVWMcUyW6EEgUH4jlr7T/wuKe3dKijvTvSos=", ext="hello"' }; - var credentialsFunc = function (id, callback) { + var credentialsFuncion = function (id, callback) { var credentials = { key: 'werxhqb98rpaxn39848xrunpaw3489ruxnpa98w4rxn', @@ -718,7 +718,7 @@ describe('Server', function () { return callback(null, credentials); }; - Hawk.server.authenticate(req, credentialsFunc, { localtimeOffsetMsec: 1353788437000 - Hawk.utils.now() }, function (err, credentials, artifacts) { + Hawk.server.authenticate(req, credentialsFuncion, { localtimeOffsetMsec: 1353788437000 - Hawk.utils.now() }, function (err, credentials, artifacts) { expect(err).to.exist(); expect(err.message).to.equal('Unknown algorithm'); @@ -737,7 +737,7 @@ describe('Server', function () { authorization: 'Hawk id="123", ts="1353788437", nonce="k3j4h2", mac="/qwS4UjfVWMcU4jlr7T/wuKe3dKijvTvSos=", ext="hello"' }; - var credentialsFunc = function (id, callback) { + var credentialsFuncion = function (id, callback) { var credentials = { key: 'werxhqb98rpaxn39848xrunpaw3489ruxnpa98w4rxn', @@ -748,7 +748,7 @@ describe('Server', function () { return callback(null, credentials); }; - Hawk.server.authenticate(req, credentialsFunc, { localtimeOffsetMsec: 1353788437000 - Hawk.utils.now() }, function (err, credentials, artifacts) { + Hawk.server.authenticate(req, credentialsFuncion, { localtimeOffsetMsec: 1353788437000 - Hawk.utils.now() }, function (err, credentials, artifacts) { expect(err).to.exist(); expect(err.output.payload.message).to.equal('Bad mac'); @@ -974,12 +974,12 @@ describe('Server', function () { it('errors on invalid authorization (ts)', function (done) { - credentialsFunc('123456', function (err, credentials) { + credentialsFunc('123456', function (err, credentials1) { - var auth = Hawk.client.message('example.com', 8080, 'some message', { credentials: credentials }); + var auth = Hawk.client.message('example.com', 8080, 'some message', { credentials: credentials1 }); delete auth.ts; - Hawk.server.authenticateMessage('example.com', 8080, 'some message', auth, credentialsFunc, {}, function (err, credentials) { + Hawk.server.authenticateMessage('example.com', 8080, 'some message', auth, credentialsFunc, {}, function (err, credentials2) { expect(err).to.exist(); expect(err.message).to.equal('Invalid authorization'); @@ -990,12 +990,12 @@ describe('Server', function () { it('errors on invalid authorization (nonce)', function (done) { - credentialsFunc('123456', function (err, credentials) { + credentialsFunc('123456', function (err, credentials1) { - var auth = Hawk.client.message('example.com', 8080, 'some message', { credentials: credentials }); + var auth = Hawk.client.message('example.com', 8080, 'some message', { credentials: credentials1 }); delete auth.nonce; - Hawk.server.authenticateMessage('example.com', 8080, 'some message', auth, credentialsFunc, {}, function (err, credentials) { + Hawk.server.authenticateMessage('example.com', 8080, 'some message', auth, credentialsFunc, {}, function (err, credentials2) { expect(err).to.exist(); expect(err.message).to.equal('Invalid authorization'); @@ -1006,12 +1006,12 @@ describe('Server', function () { it('errors on invalid authorization (hash)', function (done) { - credentialsFunc('123456', function (err, credentials) { + credentialsFunc('123456', function (err, credentials1) { - var auth = Hawk.client.message('example.com', 8080, 'some message', { credentials: credentials }); + var auth = Hawk.client.message('example.com', 8080, 'some message', { credentials: credentials1 }); delete auth.hash; - Hawk.server.authenticateMessage('example.com', 8080, 'some message', auth, credentialsFunc, {}, function (err, credentials) { + Hawk.server.authenticateMessage('example.com', 8080, 'some message', auth, credentialsFunc, {}, function (err, credentials2) { expect(err).to.exist(); expect(err.message).to.equal('Invalid authorization'); @@ -1022,18 +1022,18 @@ describe('Server', function () { it('errors with credentials', function (done) { - credentialsFunc('123456', function (err, credentials) { + credentialsFunc('123456', function (err, credentials1) { - var auth = Hawk.client.message('example.com', 8080, 'some message', { credentials: credentials }); + var auth = Hawk.client.message('example.com', 8080, 'some message', { credentials: credentials1 }); Hawk.server.authenticateMessage('example.com', 8080, 'some message', auth, function (id, callback) { callback(new Error('something'), { some: 'value' }); - }, {}, function (err, credentials) { + }, {}, function (err, credentials2) { expect(err).to.exist(); expect(err.message).to.equal('something'); - expect(credentials.some).to.equal('value'); + expect(credentials2.some).to.equal('value'); done(); }); }); @@ -1041,15 +1041,15 @@ describe('Server', function () { it('errors on nonce collision', function (done) { - credentialsFunc('123456', function (err, credentials) { + credentialsFunc('123456', function (err, credentials1) { - var auth = Hawk.client.message('example.com', 8080, 'some message', { credentials: credentials }); + var auth = Hawk.client.message('example.com', 8080, 'some message', { credentials: credentials1 }); Hawk.server.authenticateMessage('example.com', 8080, 'some message', auth, credentialsFunc, { nonceFunc: function (key, nonce, ts, nonceCallback) { nonceCallback(true); } - }, function (err, credentials) { + }, function (err, credentials2) { expect(err).to.exist(); expect(err.message).to.equal('Invalid nonce'); @@ -1058,29 +1058,17 @@ describe('Server', function () { }); }); - var credentialsFunc = function (id, callback) { - - var credentials = { - id: id, - key: 'werxhqb98rpaxn39848xrunpaw3489ruxnpa98w4rxn', - algorithm: (id === '1' ? 'sha1' : 'sha256'), - user: 'steve' - }; - - return callback(null, credentials); - }; - it('should generate an authorization then successfully parse it', function (done) { - credentialsFunc('123456', function (err, credentials) { + credentialsFunc('123456', function (err, credentials1) { - var auth = Hawk.client.message('example.com', 8080, 'some message', { credentials: credentials }); + var auth = Hawk.client.message('example.com', 8080, 'some message', { credentials: credentials1 }); expect(auth).to.exist(); - Hawk.server.authenticateMessage('example.com', 8080, 'some message', auth, credentialsFunc, {}, function (err, credentials) { + Hawk.server.authenticateMessage('example.com', 8080, 'some message', auth, credentialsFunc, {}, function (err, credentials2) { expect(err).to.not.exist(); - expect(credentials.user).to.equal('steve'); + expect(credentials2.user).to.equal('steve'); done(); }); }); @@ -1088,12 +1076,12 @@ describe('Server', function () { it('should fail authorization on mismatching host', function (done) { - credentialsFunc('123456', function (err, credentials) { + credentialsFunc('123456', function (err, credentials1) { - var auth = Hawk.client.message('example.com', 8080, 'some message', { credentials: credentials }); + var auth = Hawk.client.message('example.com', 8080, 'some message', { credentials: credentials1 }); expect(auth).to.exist(); - Hawk.server.authenticateMessage('example1.com', 8080, 'some message', auth, credentialsFunc, {}, function (err, credentials) { + Hawk.server.authenticateMessage('example1.com', 8080, 'some message', auth, credentialsFunc, {}, function (err, credentials2) { expect(err).to.exist(); expect(err.message).to.equal('Bad mac'); @@ -1104,12 +1092,12 @@ describe('Server', function () { it('should fail authorization on stale timestamp', function (done) { - credentialsFunc('123456', function (err, credentials) { + credentialsFunc('123456', function (err, credentials1) { - var auth = Hawk.client.message('example.com', 8080, 'some message', { credentials: credentials }); + var auth = Hawk.client.message('example.com', 8080, 'some message', { credentials: credentials1 }); expect(auth).to.exist(); - Hawk.server.authenticateMessage('example.com', 8080, 'some message', auth, credentialsFunc, { localtimeOffsetMsec: 100000 }, function (err, credentials) { + Hawk.server.authenticateMessage('example.com', 8080, 'some message', auth, credentialsFunc, { localtimeOffsetMsec: 100000 }, function (err, credentials2) { expect(err).to.exist(); expect(err.message).to.equal('Stale timestamp'); @@ -1120,12 +1108,12 @@ describe('Server', function () { it('overrides timestampSkewSec', function (done) { - credentialsFunc('123456', function (err, credentials) { + credentialsFunc('123456', function (err, credentials1) { - var auth = Hawk.client.message('example.com', 8080, 'some message', { credentials: credentials, localtimeOffsetMsec: 100000 }); + var auth = Hawk.client.message('example.com', 8080, 'some message', { credentials: credentials1, localtimeOffsetMsec: 100000 }); expect(auth).to.exist(); - Hawk.server.authenticateMessage('example.com', 8080, 'some message', auth, credentialsFunc, { timestampSkewSec: 500 }, function (err, credentials) { + Hawk.server.authenticateMessage('example.com', 8080, 'some message', auth, credentialsFunc, { timestampSkewSec: 500 }, function (err, credentials2) { expect(err).to.not.exist(); done(); @@ -1135,13 +1123,13 @@ describe('Server', function () { it('should fail authorization on invalid authorization', function (done) { - credentialsFunc('123456', function (err, credentials) { + credentialsFunc('123456', function (err, credentials1) { - var auth = Hawk.client.message('example.com', 8080, 'some message', { credentials: credentials }); + var auth = Hawk.client.message('example.com', 8080, 'some message', { credentials: credentials1 }); expect(auth).to.exist(); delete auth.id; - Hawk.server.authenticateMessage('example.com', 8080, 'some message', auth, credentialsFunc, {}, function (err, credentials) { + Hawk.server.authenticateMessage('example.com', 8080, 'some message', auth, credentialsFunc, {}, function (err, credentials2) { expect(err).to.exist(); expect(err.message).to.equal('Invalid authorization'); @@ -1152,12 +1140,12 @@ describe('Server', function () { it('should fail authorization on bad hash', function (done) { - credentialsFunc('123456', function (err, credentials) { + credentialsFunc('123456', function (err, credentials1) { - var auth = Hawk.client.message('example.com', 8080, 'some message', { credentials: credentials }); + var auth = Hawk.client.message('example.com', 8080, 'some message', { credentials: credentials1 }); expect(auth).to.exist(); - Hawk.server.authenticateMessage('example.com', 8080, 'some message1', auth, credentialsFunc, {}, function (err, credentials) { + Hawk.server.authenticateMessage('example.com', 8080, 'some message1', auth, credentialsFunc, {}, function (err, credentials2) { expect(err).to.exist(); expect(err.message).to.equal('Bad message hash'); @@ -1168,9 +1156,9 @@ describe('Server', function () { it('should fail authorization on nonce error', function (done) { - credentialsFunc('123456', function (err, credentials) { + credentialsFunc('123456', function (err, credentials1) { - var auth = Hawk.client.message('example.com', 8080, 'some message', { credentials: credentials }); + var auth = Hawk.client.message('example.com', 8080, 'some message', { credentials: credentials1 }); expect(auth).to.exist(); Hawk.server.authenticateMessage('example.com', 8080, 'some message', auth, credentialsFunc, { @@ -1178,7 +1166,7 @@ describe('Server', function () { callback(new Error('kaboom')); } - }, function (err, credentials) { + }, function (err, credentials2) { expect(err).to.exist(); expect(err.message).to.equal('Invalid nonce'); @@ -1189,9 +1177,9 @@ describe('Server', function () { it('should fail authorization on credentials error', function (done) { - credentialsFunc('123456', function (err, credentials) { + credentialsFunc('123456', function (err, credentials1) { - var auth = Hawk.client.message('example.com', 8080, 'some message', { credentials: credentials }); + var auth = Hawk.client.message('example.com', 8080, 'some message', { credentials: credentials1 }); expect(auth).to.exist(); var errFunc = function (id, callback) { @@ -1199,7 +1187,7 @@ describe('Server', function () { callback(new Error('kablooey')); }; - Hawk.server.authenticateMessage('example.com', 8080, 'some message', auth, errFunc, {}, function (err, credentials) { + Hawk.server.authenticateMessage('example.com', 8080, 'some message', auth, errFunc, {}, function (err, credentials2) { expect(err).to.exist(); expect(err.message).to.equal('kablooey'); @@ -1210,9 +1198,9 @@ describe('Server', function () { it('should fail authorization on missing credentials', function (done) { - credentialsFunc('123456', function (err, credentials) { + credentialsFunc('123456', function (err, credentials1) { - var auth = Hawk.client.message('example.com', 8080, 'some message', { credentials: credentials }); + var auth = Hawk.client.message('example.com', 8080, 'some message', { credentials: credentials1 }); expect(auth).to.exist(); var errFunc = function (id, callback) { @@ -1220,7 +1208,7 @@ describe('Server', function () { callback(); }; - Hawk.server.authenticateMessage('example.com', 8080, 'some message', auth, errFunc, {}, function (err, credentials) { + Hawk.server.authenticateMessage('example.com', 8080, 'some message', auth, errFunc, {}, function (err, credentials2) { expect(err).to.exist(); expect(err.message).to.equal('Unknown credentials'); @@ -1231,9 +1219,9 @@ describe('Server', function () { it('should fail authorization on invalid credentials', function (done) { - credentialsFunc('123456', function (err, credentials) { + credentialsFunc('123456', function (err, credentials1) { - var auth = Hawk.client.message('example.com', 8080, 'some message', { credentials: credentials }); + var auth = Hawk.client.message('example.com', 8080, 'some message', { credentials: credentials1 }); expect(auth).to.exist(); var errFunc = function (id, callback) { @@ -1241,7 +1229,7 @@ describe('Server', function () { callback(null, {}); }; - Hawk.server.authenticateMessage('example.com', 8080, 'some message', auth, errFunc, {}, function (err, credentials) { + Hawk.server.authenticateMessage('example.com', 8080, 'some message', auth, errFunc, {}, function (err, credentials2) { expect(err).to.exist(); expect(err.message).to.equal('Invalid credentials'); @@ -1252,9 +1240,9 @@ describe('Server', function () { it('should fail authorization on invalid credentials algorithm', function (done) { - credentialsFunc('123456', function (err, credentials) { + credentialsFunc('123456', function (err, credentials1) { - var auth = Hawk.client.message('example.com', 8080, 'some message', { credentials: credentials }); + var auth = Hawk.client.message('example.com', 8080, 'some message', { credentials: credentials1 }); expect(auth).to.exist(); var errFunc = function (id, callback) { @@ -1262,7 +1250,7 @@ describe('Server', function () { callback(null, { key: '123', algorithm: '456' }); }; - Hawk.server.authenticateMessage('example.com', 8080, 'some message', auth, errFunc, {}, function (err, credentials) { + Hawk.server.authenticateMessage('example.com', 8080, 'some message', auth, errFunc, {}, function (err, credentials2) { expect(err).to.exist(); expect(err.message).to.equal('Unknown algorithm'); diff --git a/test/uri.js b/test/uri.js index 1b623c0..f3c6ba2 100755 --- a/test/uri.js +++ b/test/uri.js @@ -28,7 +28,7 @@ describe('Uri', function () { var credentials = { id: id, key: 'werxhqb98rpaxn39848xrunpaw3489ruxnpa98w4rxn', - algorithm: 'sha256', + algorithm: (id === '1' ? 'sha1' : 'sha256'), user: 'steve' }; @@ -44,15 +44,15 @@ describe('Uri', function () { port: 80 }; - credentialsFunc('123456', function (err, credentials) { + credentialsFunc('123456', function (err, credentials1) { - var bewit = Hawk.uri.getBewit('http://example.com/resource/4?a=1&b=2', { credentials: credentials, ttlSec: 60 * 60 * 24 * 365 * 100, ext: 'some-app-data' }); + var bewit = Hawk.uri.getBewit('http://example.com/resource/4?a=1&b=2', { credentials: credentials1, ttlSec: 60 * 60 * 24 * 365 * 100, ext: 'some-app-data' }); req.url += '&bewit=' + bewit; - Hawk.uri.authenticate(req, credentialsFunc, {}, function (err, credentials, attributes) { + Hawk.uri.authenticate(req, credentialsFunc, {}, function (err, credentials2, attributes) { expect(err).to.not.exist(); - expect(credentials.user).to.equal('steve'); + expect(credentials2.user).to.equal('steve'); expect(attributes.ext).to.equal('some-app-data'); done(); }); @@ -68,15 +68,15 @@ describe('Uri', function () { port: 80 }; - credentialsFunc('123456', function (err, credentials) { + credentialsFunc('123456', function (err, credentials1) { - var bewit = Hawk.uri.getBewit('http://example.com/resource/4?a=1&b=2', { credentials: credentials, ttlSec: 60 * 60 * 24 * 365 * 100 }); + var bewit = Hawk.uri.getBewit('http://example.com/resource/4?a=1&b=2', { credentials: credentials1, ttlSec: 60 * 60 * 24 * 365 * 100 }); req.url += '&bewit=' + bewit; - Hawk.uri.authenticate(req, credentialsFunc, {}, function (err, credentials, attributes) { + Hawk.uri.authenticate(req, credentialsFunc, {}, function (err, credentials2, attributes) { expect(err).to.not.exist(); - expect(credentials.user).to.equal('steve'); + expect(credentials2.user).to.equal('steve'); done(); }); }); @@ -156,7 +156,7 @@ describe('Uri', function () { it('should fail on method other than GET', function (done) { - credentialsFunc('123456', function (err, credentials) { + credentialsFunc('123456', function (err, credentials1) { var req = { method: 'POST', @@ -167,7 +167,7 @@ describe('Uri', function () { var exp = Math.floor(Hawk.utils.now() / 1000) + 60; var ext = 'some-app-data'; - var mac = Hawk.crypto.calculateMac('bewit', credentials, { + var mac = Hawk.crypto.calculateMac('bewit', credentials1, { timestamp: exp, nonce: '', method: req.method, @@ -177,11 +177,11 @@ describe('Uri', function () { ext: ext }); - var bewit = credentials.id + '\\' + exp + '\\' + mac + '\\' + ext; + var bewit = credentials1.id + '\\' + exp + '\\' + mac + '\\' + ext; req.url += '&bewit=' + Hoek.base64urlEncode(bewit); - Hawk.uri.authenticate(req, credentialsFunc, {}, function (err, credentials, attributes) { + Hawk.uri.authenticate(req, credentialsFunc, {}, function (err, credentials2, attributes) { expect(err).to.exist(); expect(err.output.payload.message).to.equal('Invalid method'); @@ -601,31 +601,20 @@ describe('Uri', function () { done(); }); }); - describe('authenticateMessage()', function () { - - var credentialsFunc = function (id, callback) { - var credentials = { - id: id, - key: 'werxhqb98rpaxn39848xrunpaw3489ruxnpa98w4rxn', - algorithm: (id === '1' ? 'sha1' : 'sha256'), - user: 'steve' - }; - - return callback(null, credentials); - }; + describe('authenticateMessage()', function () { it('should generate an authorization then successfully parse it', function (done) { - credentialsFunc('123456', function (err, credentials) { + credentialsFunc('123456', function (err, credentials1) { - var auth = Hawk.client.message('example.com', 8080, 'some message', { credentials: credentials }); + var auth = Hawk.client.message('example.com', 8080, 'some message', { credentials: credentials1 }); expect(auth).to.exist(); - Hawk.server.authenticateMessage('example.com', 8080, 'some message', auth, credentialsFunc, {}, function (err, credentials) { + Hawk.server.authenticateMessage('example.com', 8080, 'some message', auth, credentialsFunc, {}, function (err, credentials2) { expect(err).to.not.exist(); - expect(credentials.user).to.equal('steve'); + expect(credentials2.user).to.equal('steve'); done(); }); }); @@ -633,12 +622,12 @@ describe('Uri', function () { it('should fail authorization on mismatching host', function (done) { - credentialsFunc('123456', function (err, credentials) { + credentialsFunc('123456', function (err, credentials1) { - var auth = Hawk.client.message('example.com', 8080, 'some message', { credentials: credentials }); + var auth = Hawk.client.message('example.com', 8080, 'some message', { credentials: credentials1 }); expect(auth).to.exist(); - Hawk.server.authenticateMessage('example1.com', 8080, 'some message', auth, credentialsFunc, {}, function (err, credentials) { + Hawk.server.authenticateMessage('example1.com', 8080, 'some message', auth, credentialsFunc, {}, function (err, credentials2) { expect(err).to.exist(); expect(err.message).to.equal('Bad mac'); @@ -649,12 +638,12 @@ describe('Uri', function () { it('should fail authorization on stale timestamp', function (done) { - credentialsFunc('123456', function (err, credentials) { + credentialsFunc('123456', function (err, credentials1) { - var auth = Hawk.client.message('example.com', 8080, 'some message', { credentials: credentials }); + var auth = Hawk.client.message('example.com', 8080, 'some message', { credentials: credentials1 }); expect(auth).to.exist(); - Hawk.server.authenticateMessage('example.com', 8080, 'some message', auth, credentialsFunc, { localtimeOffsetMsec: 100000 }, function (err, credentials) { + Hawk.server.authenticateMessage('example.com', 8080, 'some message', auth, credentialsFunc, { localtimeOffsetMsec: 100000 }, function (err, credentials2) { expect(err).to.exist(); expect(err.message).to.equal('Stale timestamp'); @@ -665,12 +654,12 @@ describe('Uri', function () { it('overrides timestampSkewSec', function (done) { - credentialsFunc('123456', function (err, credentials) { + credentialsFunc('123456', function (err, credentials1) { - var auth = Hawk.client.message('example.com', 8080, 'some message', { credentials: credentials, localtimeOffsetMsec: 100000 }); + var auth = Hawk.client.message('example.com', 8080, 'some message', { credentials: credentials1, localtimeOffsetMsec: 100000 }); expect(auth).to.exist(); - Hawk.server.authenticateMessage('example.com', 8080, 'some message', auth, credentialsFunc, { timestampSkewSec: 500 }, function (err, credentials) { + Hawk.server.authenticateMessage('example.com', 8080, 'some message', auth, credentialsFunc, { timestampSkewSec: 500 }, function (err, credentials2) { expect(err).to.not.exist(); done(); @@ -680,13 +669,13 @@ describe('Uri', function () { it('should fail authorization on invalid authorization', function (done) { - credentialsFunc('123456', function (err, credentials) { + credentialsFunc('123456', function (err, credentials1) { - var auth = Hawk.client.message('example.com', 8080, 'some message', { credentials: credentials }); + var auth = Hawk.client.message('example.com', 8080, 'some message', { credentials: credentials1 }); expect(auth).to.exist(); delete auth.id; - Hawk.server.authenticateMessage('example.com', 8080, 'some message', auth, credentialsFunc, {}, function (err, credentials) { + Hawk.server.authenticateMessage('example.com', 8080, 'some message', auth, credentialsFunc, {}, function (err, credentials2) { expect(err).to.exist(); expect(err.message).to.equal('Invalid authorization'); @@ -697,12 +686,12 @@ describe('Uri', function () { it('should fail authorization on bad hash', function (done) { - credentialsFunc('123456', function (err, credentials) { + credentialsFunc('123456', function (err, credentials1) { - var auth = Hawk.client.message('example.com', 8080, 'some message', { credentials: credentials }); + var auth = Hawk.client.message('example.com', 8080, 'some message', { credentials: credentials1 }); expect(auth).to.exist(); - Hawk.server.authenticateMessage('example.com', 8080, 'some message1', auth, credentialsFunc, {}, function (err, credentials) { + Hawk.server.authenticateMessage('example.com', 8080, 'some message1', auth, credentialsFunc, {}, function (err, credentials2) { expect(err).to.exist(); expect(err.message).to.equal('Bad message hash'); @@ -713,9 +702,9 @@ describe('Uri', function () { it('should fail authorization on nonce error', function (done) { - credentialsFunc('123456', function (err, credentials) { + credentialsFunc('123456', function (err, credentials1) { - var auth = Hawk.client.message('example.com', 8080, 'some message', { credentials: credentials }); + var auth = Hawk.client.message('example.com', 8080, 'some message', { credentials: credentials1 }); expect(auth).to.exist(); Hawk.server.authenticateMessage('example.com', 8080, 'some message', auth, credentialsFunc, { @@ -723,7 +712,7 @@ describe('Uri', function () { callback(new Error('kaboom')); } - }, function (err, credentials) { + }, function (err, credentials2) { expect(err).to.exist(); expect(err.message).to.equal('Invalid nonce'); @@ -734,9 +723,9 @@ describe('Uri', function () { it('should fail authorization on credentials error', function (done) { - credentialsFunc('123456', function (err, credentials) { + credentialsFunc('123456', function (err, credentials1) { - var auth = Hawk.client.message('example.com', 8080, 'some message', { credentials: credentials }); + var auth = Hawk.client.message('example.com', 8080, 'some message', { credentials: credentials1 }); expect(auth).to.exist(); var errFunc = function (id, callback) { @@ -744,7 +733,7 @@ describe('Uri', function () { callback(new Error('kablooey')); }; - Hawk.server.authenticateMessage('example.com', 8080, 'some message', auth, errFunc, {}, function (err, credentials) { + Hawk.server.authenticateMessage('example.com', 8080, 'some message', auth, errFunc, {}, function (err, credentials2) { expect(err).to.exist(); expect(err.message).to.equal('kablooey'); @@ -755,9 +744,9 @@ describe('Uri', function () { it('should fail authorization on missing credentials', function (done) { - credentialsFunc('123456', function (err, credentials) { + credentialsFunc('123456', function (err, credentials1) { - var auth = Hawk.client.message('example.com', 8080, 'some message', { credentials: credentials }); + var auth = Hawk.client.message('example.com', 8080, 'some message', { credentials: credentials1 }); expect(auth).to.exist(); var errFunc = function (id, callback) { @@ -765,7 +754,7 @@ describe('Uri', function () { callback(); }; - Hawk.server.authenticateMessage('example.com', 8080, 'some message', auth, errFunc, {}, function (err, credentials) { + Hawk.server.authenticateMessage('example.com', 8080, 'some message', auth, errFunc, {}, function (err, credentials2) { expect(err).to.exist(); expect(err.message).to.equal('Unknown credentials'); @@ -776,9 +765,9 @@ describe('Uri', function () { it('should fail authorization on invalid credentials', function (done) { - credentialsFunc('123456', function (err, credentials) { + credentialsFunc('123456', function (err, credentials1) { - var auth = Hawk.client.message('example.com', 8080, 'some message', { credentials: credentials }); + var auth = Hawk.client.message('example.com', 8080, 'some message', { credentials: credentials1 }); expect(auth).to.exist(); var errFunc = function (id, callback) { @@ -786,7 +775,7 @@ describe('Uri', function () { callback(null, {}); }; - Hawk.server.authenticateMessage('example.com', 8080, 'some message', auth, errFunc, {}, function (err, credentials) { + Hawk.server.authenticateMessage('example.com', 8080, 'some message', auth, errFunc, {}, function (err, credentials2) { expect(err).to.exist(); expect(err.message).to.equal('Invalid credentials'); @@ -797,9 +786,9 @@ describe('Uri', function () { it('should fail authorization on invalid credentials algorithm', function (done) { - credentialsFunc('123456', function (err, credentials) { + credentialsFunc('123456', function (err, credentials1) { - var auth = Hawk.client.message('example.com', 8080, 'some message', { credentials: credentials }); + var auth = Hawk.client.message('example.com', 8080, 'some message', { credentials: credentials1 }); expect(auth).to.exist(); var errFunc = function (id, callback) { @@ -807,7 +796,7 @@ describe('Uri', function () { callback(null, { key: '123', algorithm: '456' }); }; - Hawk.server.authenticateMessage('example.com', 8080, 'some message', auth, errFunc, {}, function (err, credentials) { + Hawk.server.authenticateMessage('example.com', 8080, 'some message', auth, errFunc, {}, function (err, credentials2) { expect(err).to.exist(); expect(err.message).to.equal('Unknown algorithm'); @@ -818,9 +807,9 @@ describe('Uri', function () { it('should fail on missing host', function (done) { - credentialsFunc('123456', function (err, credentials) { + credentialsFunc('123456', function (err, credentials1) { - var auth = Hawk.client.message(null, 8080, 'some message', { credentials: credentials }); + var auth = Hawk.client.message(null, 8080, 'some message', { credentials: credentials1 }); expect(auth).to.not.exist(); done(); }); @@ -835,9 +824,9 @@ describe('Uri', function () { it('should fail on invalid algorithm', function (done) { - credentialsFunc('123456', function (err, credentials) { + credentialsFunc('123456', function (err, credentials1) { - var creds = Hoek.clone(credentials); + var creds = Hoek.clone(credentials1); creds.algorithm = 'blah'; var auth = Hawk.client.message('example.com', 8080, 'some message', { credentials: creds }); expect(auth).to.not.exist();