Skip to content
This repository has been archived by the owner on Apr 5, 2024. It is now read-only.

Commit

Permalink
Fix new Boom. Closes #221
Browse files Browse the repository at this point in the history
  • Loading branch information
hueniverse committed Nov 3, 2017
1 parent 05e35d7 commit a0f60c0
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 25 deletions.
30 changes: 15 additions & 15 deletions lib/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ exports.header = function (uri, method, options) {
!method || typeof method !== 'string' ||
!options || typeof options !== 'object') {

throw Boom('Invalid argument type');
throw new Boom('Invalid argument type');
}

// Application time
Expand All @@ -69,11 +69,11 @@ exports.header = function (uri, method, options) {
!credentials.key ||
!credentials.algorithm) {

throw Boom('Invalid credentials');
throw new Boom('Invalid credentials');
}

if (Crypto.algorithms.indexOf(credentials.algorithm) === -1) {
throw Boom('Unknown algorithm');
throw new Boom('Unknown algorithm');
}

// Parse URI
Expand Down Expand Up @@ -153,7 +153,7 @@ exports.authenticate = function (res, credentials, artifacts, options) {
var wwwAttributes = Utils.parseAuthorizationHeader(res.headers['www-authenticate'], ['ts', 'tsm', 'error']);
}
catch (err) {
throw Boom('Invalid WWW-Authenticate header');
throw new Boom('Invalid WWW-Authenticate header');
}

result.headers['www-authenticate'] = wwwAttributes;
Expand All @@ -163,7 +163,7 @@ exports.authenticate = function (res, credentials, artifacts, options) {
if (wwwAttributes.ts) {
const tsm = Crypto.calculateTsMac(wwwAttributes.ts, credentials);
if (tsm !== wwwAttributes.tsm) {
throw Boom('Invalid server timestamp hash', { decorate: result });
throw new Boom('Invalid server timestamp hash', { decorate: result });
}
}
}
Expand All @@ -180,7 +180,7 @@ exports.authenticate = function (res, credentials, artifacts, options) {
var serverAuthAttributes = Utils.parseAuthorizationHeader(res.headers['server-authorization'], ['mac', 'ext', 'hash']);
}
catch (err) {
throw Boom('Invalid Server-Authorization header', { decorate: result });
throw new Boom('Invalid Server-Authorization header', { decorate: result });
}

result.headers['server-authorization'] = serverAuthAttributes;
Expand All @@ -190,7 +190,7 @@ exports.authenticate = function (res, credentials, artifacts, options) {

const mac = Crypto.calculateMac('response', credentials, artifacts);
if (mac !== serverAuthAttributes.mac) {
throw Boom('Bad response mac', { decorate: result });
throw new Boom('Bad response mac', { decorate: result });
}

if (!options.payload &&
Expand All @@ -200,12 +200,12 @@ exports.authenticate = function (res, credentials, artifacts, options) {
}

if (!serverAuthAttributes.hash) {
throw Boom('Missing response hash attribute', { decorate: result });
throw new Boom('Missing response hash attribute', { decorate: result });
}

const calculatedHash = Crypto.calculatePayloadHash(options.payload, credentials.algorithm, res.headers['content-type']);
if (calculatedHash !== serverAuthAttributes.hash) {
throw Boom('Bad response payload mac', { decorate: result });
throw new Boom('Bad response payload mac', { decorate: result });
}

return result;
Expand Down Expand Up @@ -244,7 +244,7 @@ exports.getBewit = function (uri, options) {
typeof options !== 'object' ||
!options.ttlSec) {

throw Boom('Invalid inputs');
throw new Boom('Invalid inputs');
}

const ext = (options.ext === null || options.ext === undefined ? '' : options.ext); // Zero is valid value
Expand All @@ -261,11 +261,11 @@ exports.getBewit = function (uri, options) {
!credentials.key ||
!credentials.algorithm) {

throw Boom('Invalid credentials');
throw new Boom('Invalid credentials');
}

if (Crypto.algorithms.indexOf(credentials.algorithm) === -1) {
throw Boom('Unknown algorithm');
throw new Boom('Unknown algorithm');
}

// Parse URI
Expand Down Expand Up @@ -329,7 +329,7 @@ exports.message = function (host, port, message, options) {
message === null || message === undefined || typeof message !== 'string' ||
typeof options !== 'object') {

throw Boom('Invalid inputs');
throw new Boom('Invalid inputs');
}

// Application time
Expand All @@ -344,11 +344,11 @@ exports.message = function (host, port, message, options) {
!credentials.key ||
!credentials.algorithm) {

throw Boom('Invalid credentials');
throw new Boom('Invalid credentials');
}

if (Crypto.algorithms.indexOf(credentials.algorithm) === -1) {
throw Boom('Unknown algorithm');
throw new Boom('Unknown algorithm');
}

// Calculate signature
Expand Down
20 changes: 10 additions & 10 deletions lib/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,11 +148,11 @@ exports.authenticate = async function (req, credentialsFunc, options) {
if (!credentials.key ||
!credentials.algorithm) {

throw Boom('Invalid credentials', { decorate: result });
throw new Boom('Invalid credentials', { decorate: result });
}

if (Crypto.algorithms.indexOf(credentials.algorithm) === -1) {
throw Boom('Unknown algorithm', { decorate: result });
throw new Boom('Unknown algorithm', { decorate: result });
}

// Calculate MAC
Expand Down Expand Up @@ -261,7 +261,7 @@ exports.header = function (credentials, artifacts, options) {
typeof artifacts !== 'object' ||
typeof options !== 'object') {

throw Boom('Invalid inputs');
throw new Boom('Invalid inputs');
}

artifacts = Hoek.clone(artifacts);
Expand All @@ -275,11 +275,11 @@ exports.header = function (credentials, artifacts, options) {
!credentials.key ||
!credentials.algorithm) {

throw Boom('Invalid credentials');
throw new Boom('Invalid credentials');
}

if (Crypto.algorithms.indexOf(credentials.algorithm) === -1) {
throw Boom('Unknown algorithm');
throw new Boom('Unknown algorithm');
}

// Calculate payload hash
Expand Down Expand Up @@ -410,7 +410,7 @@ exports.authenticateBewit = async function (req, credentialsFunc, options) {
var credentials = await credentialsFunc(bewit.id);
}
catch (err) {
throw Boom(err, { decorate: { bewit } });
throw new Boom(err, { decorate: { bewit } });
}

if (!credentials) {
Expand All @@ -422,11 +422,11 @@ exports.authenticateBewit = async function (req, credentialsFunc, options) {
if (!credentials.key ||
!credentials.algorithm) {

throw Boom('Invalid credentials', { decorate: result });
throw new Boom('Invalid credentials', { decorate: result });
}

if (Crypto.algorithms.indexOf(credentials.algorithm) === -1) {
throw Boom('Unknown algorithm', { decorate: result });
throw new Boom('Unknown algorithm', { decorate: result });
}

// Calculate MAC
Expand Down Expand Up @@ -491,11 +491,11 @@ exports.authenticateMessage = async function (host, port, message, authorization
if (!credentials.key ||
!credentials.algorithm) {

throw Boom('Invalid credentials', { decorate: result });
throw new Boom('Invalid credentials', { decorate: result });
}

if (Crypto.algorithms.indexOf(credentials.algorithm) === -1) {
throw Boom('Unknown algorithm', { decorate: result });
throw new Boom('Unknown algorithm', { decorate: result });
}

// Construct artifacts container
Expand Down

0 comments on commit a0f60c0

Please sign in to comment.