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

Commit

Permalink
dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
Eran Hammer committed May 27, 2014
1 parent 5161ee0 commit 191699b
Show file tree
Hide file tree
Showing 9 changed files with 113 additions and 29 deletions.
2 changes: 1 addition & 1 deletion Makefile
@@ -1,7 +1,7 @@
test:
@./node_modules/.bin/lab
test-cov:
@./node_modules/.bin/lab -r threshold -t 100
@./node_modules/.bin/lab -t 100
test-cov-html:
@./node_modules/.bin/lab -r html -o coverage.html

Expand Down
4 changes: 2 additions & 2 deletions lib/endpoints.js
Expand Up @@ -53,7 +53,7 @@ exports.reissue = function (req, payload, options, callback) {
scope: Joi.array().includes(Joi.string())
};

var error = Joi.validate(payload, schema);
var error = Joi.validate(payload, schema).error;
if (error) {
return callback(Boom.badRequest(error.message));
}
Expand Down Expand Up @@ -133,7 +133,7 @@ exports.rsvp = function (req, payload, options, callback) {
rsvp: Joi.string().required()
};

var error = Joi.validate(payload, schema);
var error = Joi.validate(payload, schema).error;
if (error) {
return callback(Boom.badRequest(error.message));
}
Expand Down
2 changes: 1 addition & 1 deletion lib/scope.js
Expand Up @@ -38,7 +38,7 @@ exports.validate = function (scope) {
hash[scope[i]] = true;
}

return true;
return null;
};


Expand Down
3 changes: 2 additions & 1 deletion lib/server.js
@@ -1,6 +1,7 @@
// Load modules

var Boom = require('boom');
var Hoek = require('hoek');
var Hawk = require('hawk');
var Ticket = require('./ticket');

Expand Down Expand Up @@ -43,7 +44,7 @@ exports.authenticate = function (req, encryptionPassword, options, callback) {

exports.credentialsFunc = function (encryptionPassword, options) {

Hawk.utils.assert(encryptionPassword, 'Invalid encryption password');
Hoek.assert(encryptionPassword, 'Invalid encryption password');

return function (id, callback) {

Expand Down
76 changes: 60 additions & 16 deletions lib/ticket.js
Expand Up @@ -50,13 +50,27 @@ internals.defaults = {

exports.issue = function (app, grant, encryptionPassword, options, callback) {

Hoek.toss(app && app.id, Boom.internal('Invalid application object'), callback);
Hoek.toss(!grant || (grant.id && grant.user && grant.exp), Boom.internal('Invalid grant object'), callback);
Hoek.toss(encryptionPassword, Boom.internal('Invalid encryption password'), callback);
Hoek.toss(options, Boom.internal('Invalid options object'), callback);
if (!app || !app.id) {
return callback(Boom.internal('Invalid application object'));
}

if (grant && (!grant.id || !grant.user || !grant.exp)) {
return callback(Boom.internal('Invalid grant object'));
}

if (!encryptionPassword) {
return callback(Boom.internal('Invalid encryption password'));
}

if (!options) {
return callback(Boom.internal('Invalid options object'));
}

var scope = options.scope || (grant ? grant.scope : null) || app.scope || [];
Hoek.toss(Scope.validate(scope), callback);
var error = Scope.validate(scope);
if (error) {
return callback(error);
}

// Construct ticket

Expand Down Expand Up @@ -104,11 +118,25 @@ exports.issue = function (app, grant, encryptionPassword, options, callback) {

exports.reissue = function (parentTicket, encryptionPassword, options, callback) {

Hoek.toss(parentTicket, Boom.internal('Invalid parent ticket object'), callback);
Hoek.toss(encryptionPassword, Boom.internal('Invalid encryption password'), callback);
Hoek.toss(options, Boom.internal('Invalid options object'), callback);
Hoek.toss(!options.scope || Scope.isSubset(parentTicket.scope, options.scope), Boom.forbidden('New scope is not a subset of the parent ticket scope'), callback);
Hoek.toss(!options.issueTo || !parentTicket.dlg, Boom.badRequest('Cannot re-delegate'), callback);
if (!parentTicket) {
return callback(Boom.internal('Invalid parent ticket object'));
}

if (!encryptionPassword) {
return callback(Boom.internal('Invalid encryption password'));
}

if (!options) {
return callback(Boom.internal('Invalid options object'));
}

if (options.scope && !Scope.isSubset(parentTicket.scope, options.scope)) {
return callback(Boom.forbidden('New scope is not a subset of the parent ticket scope'));
}

if (options.issueTo && parentTicket.dlg) {
return callback(Boom.badRequest('Cannot re-delegate'));
}

// Construct ticket

Expand Down Expand Up @@ -164,10 +192,21 @@ exports.reissue = function (parentTicket, encryptionPassword, options, callback)

exports.rsvp = function (app, grant, encryptionPassword, options, callback) {

Hoek.toss(app && app.id, Boom.internal('Invalid application object'), callback);
Hoek.toss(grant && grant.id, Boom.internal('Invalid grant object'), callback);
Hoek.toss(encryptionPassword, Boom.internal('Invalid encryption password'), callback);
Hoek.toss(options, Boom.internal('Invalid options object'), callback);
if (!app || !app.id) {
return callback(Boom.internal('Invalid application object'));
}

if (!grant || !grant.id) {
return callback(Boom.internal('Invalid grant object'));
}

if (!encryptionPassword) {
return callback(Boom.internal('Invalid encryption password'));
}

if (!options) {
return callback(Boom.internal('Invalid options object'));
}

options.ttl = options.ttl || internals.defaults.rsvpTTL;

Expand Down Expand Up @@ -265,8 +304,13 @@ exports.generate = function (ticket, encryptionPassword, options, callback) {

exports.parse = function (id, encryptionPassword, options, callback) {

Hoek.toss(encryptionPassword, Boom.internal('Invalid encryption password'), callback);
Hoek.toss(options, Boom.internal('Invalid options object'), callback);
if (!encryptionPassword) {
return callback(Boom.internal('Invalid encryption password'));
}

if (!options) {
return callback(Boom.internal('Invalid options object'));
}

Iron.unseal(id, encryptionPassword, options.iron || Iron.defaults, function (err, object) {

Expand Down
8 changes: 4 additions & 4 deletions package.json
Expand Up @@ -2,7 +2,7 @@
"name": "oz",
"description": "Web Authorization Protocol",
"version": "0.4.1",
"author": "Eran Hammer <eran@hueniverse.com> (http://hueniverse.com)",
"author": "Eran Hammer <eran@hammer.io> (http://hueniverse.com)",
"contributors":[
"Wyatt Preul <wpreul@gmail.com>",
"Adam Barth <github@adambarth.com>"
Expand All @@ -18,15 +18,15 @@
"node": ">=0.10.22"
},
"dependencies": {
"joi": "2.x.x",
"hoek": "1.x.x",
"joi": "4.x.x",
"hoek": "2.x.x",
"boom": "2.x.x",
"iron": "2.x.x",
"cryptiles": "2.x.x",
"hawk": "2.x.x"
},
"devDependencies": {
"lab": "1.x.x"
"lab": "3.x.x"
},
"scripts": {
"test": "make test-cov"
Expand Down
39 changes: 39 additions & 0 deletions test/client.js
@@ -0,0 +1,39 @@
// Load modules

var Lab = require('lab');
var Oz = require('../lib');


// Declare internals

var internals = {};


// Test shortcuts

var expect = Lab.expect;
var before = Lab.before;
var after = Lab.after;
var describe = Lab.experiment;
var it = Lab.test;


describe('Client', function () {

describe('#header', function () {

it('', function (done) {

var app = {
id: 'social',
scope: ['a', 'b', 'c'],
key: 'werxhqb98rpaxn39848xrunpaw3489ruxnpa98w4rxn',
algorithm: 'sha256'
};

var header = Oz.client.header('http://example.com/oz/app', 'POST', app, {}).field;
expect(header).to.exist;
done();
});
});
});
4 changes: 2 additions & 2 deletions test/endpoints.js
Expand Up @@ -118,7 +118,7 @@ describe('Endpoints', function () {
Oz.endpoints.reissue(req, payload, options, function (err, delegatedTicket) {

expect(err).to.exist;
expect(err.message).to.equal('the value of issueTo is not allowed to be null');
expect(err.message).to.equal('issueTo must be a string');
done();
});
});
Expand Down Expand Up @@ -288,7 +288,7 @@ describe('Endpoints', function () {
Oz.endpoints.rsvp(req, payload, options, function (err, ticket) {

expect(err).to.exist;
expect(err.message).to.equal('the value of rsvp is not allowed to be empty');
expect(err.message).to.equal('rsvp is not allowed to be empty');
done();
});
});
Expand Down
4 changes: 2 additions & 2 deletions test/scope.js
Expand Up @@ -22,11 +22,11 @@ describe('Scope', function () {

describe('#validate', function () {

it('should return true for valid scope', function (done) {
it('should return null for valid scope', function (done) {

var scope = ['a', 'b', 'c'];
var err = Oz.scope.validate(scope);
expect(err).to.equal(true);
expect(err).to.equal(null);
done();
});

Expand Down

0 comments on commit 191699b

Please sign in to comment.