Permalink
Browse files

add tests

  • Loading branch information...
1 parent 6797bd6 commit 350bb4c9028330fbda3d0b41ad087b6611cff429 @tj committed Jun 27, 2012
Showing with 45 additions and 2 deletions.
  1. +4 −1 Makefile
  2. +2 −0 index.js
  3. +1 −1 package.json
  4. +38 −0 test/pwd.js
View
@@ -1,5 +1,8 @@
test:
- @echo "populate me"
+ @./node_modules/.bin/mocha \
+ --require should \
+ --slow 2000 \
+ --reporter spec
.PHONY: test
View
@@ -25,6 +25,7 @@ var iterations = 12000;
*/
exports.length = function(n){
+ if (0 == arguments.length) return len;
len = n;
};
@@ -36,6 +37,7 @@ exports.length = function(n){
*/
exports.iterations = function(n){
+ if (0 == arguments.length) return iterations;
iterations = n;
};
View
@@ -1,7 +1,7 @@
{
"name": "pwd",
"version": "0.0.1",
- "description": "Hash and compare password with pbkdf2",
+ "description": "Hash and compare passwords with pbkdf2",
"keywords": ["pass", "auth", "password", "authentication"],
"author": "TJ Holowaychuk <tj@vision-media.ca>",
"dependencies": {},
View
@@ -0,0 +1,38 @@
+
+var pass = require('..');
+
+describe('.hash(pass, fn)', function(){
+ it('should generate a salt and hash', function(done){
+ pass.hash('foobar', function(err, salt, hash){
+ if (err) return done(err);
+ salt.should.be.a('string');
+ hash.should.be.a('string');
+ done();
+ })
+ })
+})
+
+describe('.hash(pass, salt, fn)', function(){
+ it('should generate a hash', function(done){
+ pass.hash('foobar', function(err, salt, hash){
+ pass.hash('foobar', salt, function(err, cpm){
+ cpm.should.equal(hash);
+ done();
+ })
+ })
+ })
+})
+
+describe('.iterations(n)', function(){
+ it('should set iterations', function(){
+ pass.iterations(1000);
+ pass.iterations().should.equal(1000);
+ })
+})
+
+describe('.length(n)', function(){
+ it('should set length', function(){
+ pass.length(256);
+ pass.length().should.equal(256);
+ })
+})

0 comments on commit 350bb4c

Please sign in to comment.