Permalink
Browse files

Move lib/hawk to lib/index

  • Loading branch information...
1 parent a7318c0 commit 331cc7cfae35d94320916ea878313a0d00c41e4d @hueniverse committed Dec 5, 2012
Showing with 53 additions and 44 deletions.
  1. +1 −1 LICENSE
  2. +1 −1 index.js
  3. 0 lib/{hawk.js → index.js}
  4. +51 −42 test/hawk.js
View
@@ -8,7 +8,7 @@ modification, are permitted provided that the following conditions are met:
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
- * Neither the name of Walmart nor the
+ * Neither the name of Eran Hammer nor the
names of its contributors may be used to endorse or promote products
derived from this software without specific prior written permission.
View
@@ -1 +1 @@
-module.exports = require('./lib/hawk');
+module.exports = require('./lib');
File renamed without changes.
View
@@ -1,8 +1,17 @@
// Load modules
-var expect = require('chai').expect;
-var should = require('should');
-var Hawk = process.env.TEST_COV ? require('../lib-cov/hawk') : require('../lib/hawk');
+var Chai = require('chai');
+var Hawk = process.env.TEST_COV ? require('../lib-cov') : require('../lib');
+
+
+// Declare internals
+
+var internals = {};
+
+
+// Test shortcuts
+
+var expect = Chai.expect;
describe('Hawk', function () {
@@ -35,9 +44,9 @@ describe('Hawk', function () {
Hawk.authenticate(req, credentialsFunc, {}, function (err, credentials, ext) {
- should.not.exist(err);
- credentials.user.should.equal('steve');
- ext.should.equal('some-app-data');
+ expect(err).to.not.exist;
+ expect(credentials.user).to.equal('steve');
+ expect(ext).to.equal('some-app-data');
done();
});
});
@@ -60,8 +69,8 @@ describe('Hawk', function () {
Hawk.authenticate(req, credentialsFunc, {}, function (err, credentials, ext) {
- should.exist(err);
- should.exist(credentials);
+ expect(err).to.exist;
+ expect(credentials).to.exist;
done();
});
});
@@ -82,8 +91,8 @@ describe('Hawk', function () {
Hawk.authenticate(req, credentialsFunc, {}, function (err, credentials, ext) {
- should.not.exist(err);
- credentials.user.should.equal('steve');
+ expect(err).to.not.exist;
+ expect(credentials.user).to.equal('steve');
done();
});
});
@@ -101,8 +110,8 @@ describe('Hawk', function () {
Hawk.authenticate(req, credentialsFunc, {}, function (err, credentials, ext) {
- should.not.exist(err);
- credentials.user.should.equal('steve');
+ expect(err).to.not.exist;
+ expect(credentials.user).to.equal('steve');
done();
});
});
@@ -120,8 +129,8 @@ describe('Hawk', function () {
Hawk.authenticate(req, credentialsFunc, {}, function (err, credentials, ext) {
- should.exist(err);
- err.toResponse().payload.message.should.equal('Incorrect scheme');
+ expect(err).to.exist;
+ expect(err.toResponse().payload.message).to.equal('Incorrect scheme');
done();
});
});
@@ -138,8 +147,8 @@ describe('Hawk', function () {
Hawk.authenticate(req, credentialsFunc, {}, function (err, credentials, ext) {
- should.exist(err);
- err.toResponse().payload.message.should.equal('Missing Authorization header');
+ expect(err).to.exist;
+ expect(err.toResponse().payload.message).to.equal('Missing Authorization header');
done();
});
});
@@ -156,8 +165,8 @@ describe('Hawk', function () {
Hawk.authenticate(req, credentialsFunc, {}, function (err, credentials, ext) {
- should.exist(err);
- err.toResponse().payload.message.should.equal('Missing Host header');
+ expect(err).to.exist;
+ expect(err.toResponse().payload.message).to.equal('Missing Host header');
done();
});
});
@@ -175,8 +184,8 @@ describe('Hawk', function () {
Hawk.authenticate(req, credentialsFunc, {}, function (err, credentials, ext) {
- should.exist(err);
- err.toResponse().payload.message.should.equal('Missing attributes');
+ expect(err).to.exist;
+ expect(err.toResponse().payload.message).to.equal('Missing attributes');
done();
});
});
@@ -194,8 +203,8 @@ describe('Hawk', function () {
Hawk.authenticate(req, credentialsFunc, {}, function (err, credentials, ext) {
- should.exist(err);
- err.toResponse().payload.message.should.equal('Unknown attributes');
+ expect(err).to.exist;
+ expect(err.toResponse().payload.message).to.equal('Unknown attributes');
done();
});
});
@@ -213,8 +222,8 @@ describe('Hawk', function () {
Hawk.authenticate(req, credentialsFunc, {}, function (err, credentials, ext) {
- should.exist(err);
- err.toResponse().payload.message.should.equal('Invalid header format');
+ expect(err).to.exist;
+ expect(err.toResponse().payload.message).to.equal('Invalid header format');
done();
});
});
@@ -232,8 +241,8 @@ describe('Hawk', function () {
Hawk.authenticate(req, credentialsFunc, {}, function (err, credentials, ext) {
- should.exist(err);
- err.toResponse().payload.message.should.equal('Bad Host header');
+ expect(err).to.exist;
+ expect(err.toResponse().payload.message).to.equal('Bad Host header');
done();
});
});
@@ -256,8 +265,8 @@ describe('Hawk', function () {
Hawk.authenticate(req, credentialsFunc, {}, function (err, credentials, ext) {
- should.exist(err);
- err.message.should.equal('Unknown user');
+ expect(err).to.exist;
+ expect(err.message).to.equal('Unknown user');
done();
});
});
@@ -280,8 +289,8 @@ describe('Hawk', function () {
Hawk.authenticate(req, credentialsFunc, {}, function (err, credentials, ext) {
- should.exist(err);
- err.toResponse().payload.message.should.equal('Missing credentials');
+ expect(err).to.exist;
+ expect(err.toResponse().payload.message).to.equal('Missing credentials');
done();
});
});
@@ -309,9 +318,9 @@ describe('Hawk', function () {
Hawk.authenticate(req, credentialsFunc, {}, function (err, credentials, ext) {
- should.exist(err);
- err.message.should.equal('Invalid credentials');
- err.toResponse().payload.message.should.equal('An internal server error occurred');
+ expect(err).to.exist;
+ expect(err.message).to.equal('Invalid credentials');
+ expect(err.toResponse().payload.message).to.equal('An internal server error occurred');
done();
});
});
@@ -340,9 +349,9 @@ describe('Hawk', function () {
Hawk.authenticate(req, credentialsFunc, {}, function (err, credentials, ext) {
- should.exist(err);
- err.message.should.equal('Unknown algorithm');
- err.toResponse().payload.message.should.equal('An internal server error occurred');
+ expect(err).to.exist;
+ expect(err.message).to.equal('Unknown algorithm');
+ expect(err.toResponse().payload.message).to.equal('An internal server error occurred');
done();
});
});
@@ -371,8 +380,8 @@ describe('Hawk', function () {
Hawk.authenticate(req, credentialsFunc, {}, function (err, credentials, ext) {
- should.exist(err);
- err.toResponse().payload.message.should.equal('Bad mac');
+ expect(err).to.exist;
+ expect(err.toResponse().payload.message).to.equal('Bad mac');
done();
});
});
@@ -382,7 +391,7 @@ describe('Hawk', function () {
it('should return an empty value on unknown algorithm', function (done) {
- Hawk.calculateMAC('dasdfasdf', 'hmac-sha-0', Date.now() / 1000, 'GET', '/resource/something', 'example.com', 8080).should.equal('');
+ expect(Hawk.calculateMAC('dasdfasdf', 'hmac-sha-0', Date.now() / 1000, 'GET', '/resource/something', 'example.com', 8080)).to.equal('');
done();
});
});
@@ -398,7 +407,7 @@ describe('Hawk', function () {
};
var header = Hawk.getAuthorizationHeader(credentials, 'POST', '/somewhere/over/the/rainbow', 'example.net', 443, 'Bazinga!', 1353809207);
- header.should.equal('Hawk id="123456", ts="1353809207", ext="Bazinga!", mac="LYUkYKYkQsQstqNQHcnAzDXce0oHsmS049rv4EalMb8="');
+ expect(header).to.equal('Hawk id="123456", ts="1353809207", ext="Bazinga!", mac="LYUkYKYkQsQstqNQHcnAzDXce0oHsmS049rv4EalMb8="');
done();
});
@@ -410,7 +419,7 @@ describe('Hawk', function () {
};
var header = Hawk.getAuthorizationHeader(credentials, 'POST', '/somewhere/over/the/rainbow', 'example.net', 443, 'Bazinga!', 1353809207);
- header.should.equal('');
+ expect(header).to.equal('');
done();
});
@@ -423,7 +432,7 @@ describe('Hawk', function () {
};
var header = Hawk.getAuthorizationHeader(credentials, 'POST', '/somewhere/over/the/rainbow', 'example.net', 443, 'Bazinga!', 1353809207);
- header.should.equal('');
+ expect(header).to.equal('');
done();
});
});

0 comments on commit 331cc7c

Please sign in to comment.