Skip to content

Commit dc39a04

Browse files
authored
Merge pull request #35 from crypto-browserify/tape
use tape instead of mocha
2 parents 18319dd + 59f6577 commit dc39a04

File tree

3 files changed

+89
-104
lines changed

3 files changed

+89
-104
lines changed

.travis.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@ node_js:
1010
- "6"
1111
matrix:
1212
include:
13+
- node_js: "6"
14+
env: TEST_SUITE=coverage
1315
- node_js: "4"
14-
env: TEST_SUITE=coveralls
15-
- node_js: "4"
16-
env: TEST_SUITE=standard
16+
env: TEST_SUITE=lint
1717
env:
1818
- TEST_SUITE=test
1919
script: npm run-script $TEST_SUITE

package.json

Lines changed: 23 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2,44 +2,42 @@
22
"name": "pbkdf2",
33
"version": "3.0.4",
44
"description": "This library provides the functionality of PBKDF2 with the ability to use any supported hashing algorithm returned from crypto.getHashes()",
5-
"main": "./index.js",
6-
"files": [
7-
"browser.js",
8-
"index.js",
9-
"node-shim-async.js",
10-
"node-shim.js",
11-
"precondition.js"
12-
],
13-
"browser": "./browser.js",
145
"keywords": [
156
"pbkdf2",
167
"kdf",
178
"salt",
189
"hash"
1910
],
20-
"scripts": {
21-
"coverage": "istanbul cover _mocha -- -t 20000 test/index.js",
22-
"coveralls": "npm run coverage && coveralls < coverage/lcov.info",
23-
"standard": "standard",
24-
"test": "mocha --reporter list -t 20000 test/index.js",
25-
"bundle-test": "browserify test/index.js > test/bundle.js"
11+
"homepage": "https://github.com/crypto-browserify/pbkdf2",
12+
"bugs": {
13+
"url": "https://github.com/crypto-browserify/pbkdf2/issues"
2614
},
15+
"license": "MIT",
16+
"author": "Daniel Cousens",
17+
"files": [
18+
"browser.js",
19+
"index.js",
20+
"node-shim-async.js",
21+
"node-shim.js",
22+
"precondition.js"
23+
],
24+
"main": "index.js",
2725
"repository": {
2826
"type": "git",
2927
"url": "https://github.com/crypto-browserify/pbkdf2.git"
3028
},
31-
"author": "Daniel Cousens",
32-
"license": "MIT",
33-
"bugs": {
34-
"url": "https://github.com/crypto-browserify/pbkdf2/issues"
29+
"scripts": {
30+
"prepublish": "npm run test",
31+
"coverage": "nyc --check-coverage --branches 100 --functions 100 tape test/*.js",
32+
"lint": "standard",
33+
"test": "npm run lint && npm run unit",
34+
"bundle-test": "browserify test/index.js > test/bundle.js",
35+
"unit": "tape test/*.js"
3536
},
36-
"homepage": "https://github.com/crypto-browserify/pbkdf2",
3737
"devDependencies": {
38-
"browserify": "^8.1.1",
39-
"coveralls": "^2.11.2",
40-
"istanbul": "^0.3.5",
41-
"mocha": "^2.1.0",
42-
"standard": "^6.0.7"
38+
"nyc": "^6.4.0",
39+
"standard": "*",
40+
"tape": "^4.5.1"
4341
},
4442
"dependencies": {
4543
"create-hmac": "^1.1.2"

test/index.js

Lines changed: 63 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1-
/* global describe, it */
2-
3-
var assert = require('assert')
1+
// SHA-1 vectors generated by Node.js
2+
// SHA-256/SHA-512 test vectors from:
3+
// https://stackoverflow.com/questions/5130513/pbkdf2-hmac-sha2-test-vectors
4+
// https://stackoverflow.com/questions/15593184/pbkdf2-hmac-sha-512-test-vectors
45
var fixtures = require('./fixtures')
6+
var tape = require('tape')
57

68
var pVersionMajor = parseInt(process.version.split('.')[0].slice(1), 10)
79
if (pVersionMajor !== 4 || process.browser) {
@@ -70,91 +72,76 @@ if (pVersionMajor >= 6 || process.browser) {
7072
})
7173
}
7274

73-
// SHA-1 vectors generated by Node.js
74-
// SHA-256/SHA-512 test vectors from:
75-
// https://stackoverflow.com/questions/5130513/pbkdf2-hmac-sha2-test-vectors
76-
// https://stackoverflow.com/questions/15593184/pbkdf2-hmac-sha-512-test-vectors
7775
function runTests (name, compat) {
78-
describe(name, function () {
79-
var algos = ['sha1', 'sha224', 'sha256', 'sha384', 'sha512']
80-
describe('pbkdf2-compat', function () {
81-
it('defaults to sha1 and handles buffers', function (done) {
82-
compat.pbkdf2(new Buffer('password'), new Buffer('salt'), 1, 32, function (err, result) {
83-
assert.equal(err, null)
84-
assert.equal(result.toString('hex'), '0c60c80f961f0e71f3a9b524af6012062fe037a6e0f0eb94fe8fc46bdc637164')
85-
done()
76+
tape(name + ' defaults to sha1 and handles buffers', function (t) {
77+
t.plan(2)
78+
79+
compat.pbkdf2(new Buffer('password'), new Buffer('salt'), 1, 32, function (err, result) {
80+
t.error(err)
81+
t.equal(result.toString('hex'), '0c60c80f961f0e71f3a9b524af6012062fe037a6e0f0eb94fe8fc46bdc637164')
82+
})
83+
})
84+
85+
tape(name + ' should throw if no callback is provided', function (t) {
86+
t.plan(1)
87+
88+
t.throws(function () {
89+
compat.pbkdf2('password', 'salt', 1, 32, 'sha1')
90+
}, /No callback provided to pbkdf2/)
91+
})
92+
93+
var algos = ['sha1', 'sha224', 'sha256', 'sha384', 'sha512']
94+
algos.forEach(function (algorithm) {
95+
fixtures.valid.forEach(function (f) {
96+
var key = f.key || new Buffer(f.keyHex, 'hex')
97+
var salt = f.salt || new Buffer(f.saltHex, 'hex')
98+
var expected = f.results[algorithm]
99+
var description = algorithm + ' encodes ' + key + ' (' + f.salt + ') with ' + algorithm + ' to ' + expected
100+
101+
tape(name + ' async w/ ' + description, function (t) {
102+
t.plan(2)
103+
104+
compat.pbkdf2(key, salt, f.iterations, f.dkLen, algorithm, function (err, result) {
105+
t.error(err)
106+
t.equal(result.toString('hex'), expected)
86107
})
87108
})
88109

89-
describe('pbkdf2', function () {
90-
algos.forEach(function (algorithm) {
91-
describe(algorithm, function () {
92-
fixtures.valid.forEach(function (f) {
93-
var key = f.key || new Buffer(f.keyHex, 'hex')
94-
var salt = f.salt || new Buffer(f.saltHex, 'hex')
95-
var expected = f.results[algorithm]
96-
var description = f.description || ('encodes ' + key + '(' + f.salt + ') with ' + algorithm + ' to ' + expected)
97-
98-
it(description, function (done) {
99-
compat.pbkdf2(key, salt, f.iterations, f.dkLen, algorithm, function (err, result) {
100-
assert.equal(err, null)
101-
assert.equal(result.toString('hex'), expected)
102-
done()
103-
})
104-
})
105-
})
106-
107-
fixtures.invalid.forEach(function (f) {
108-
it('should throw ' + f.exception, function () {
109-
assert.throws(function () {
110-
compat.pbkdf2(f.key, f.salt, f.iterations, f.dkLen, f.algo, function () {})
111-
}, new RegExp(f.exception))
112-
})
113-
})
114-
})
115-
})
110+
tape(name + 'sync w/ ' + description, function (t) {
111+
t.plan(1)
116112

117-
it('should throw if no callback is provided', function () {
118-
assert.throws(function () {
119-
compat.pbkdf2('password', 'salt', 1, 32, 'sha1')
120-
}, /No callback provided to pbkdf2/)
121-
})
113+
var result = compat.pbkdf2Sync(key, salt, f.iterations, f.dkLen, algorithm)
114+
t.equal(result.toString('hex'), expected)
122115
})
116+
})
123117

124-
describe('pbkdf2Sync', function () {
125-
it('defaults to sha1', function () {
126-
var result = compat.pbkdf2Sync('password', 'salt', 1, 32)
118+
fixtures.invalid.forEach(function (f) {
119+
var description = algorithm + ' should throw ' + f.exception
127120

128-
assert.equal(result.toString('hex'), '0c60c80f961f0e71f3a9b524af6012062fe037a6e0f0eb94fe8fc46bdc637164')
129-
})
121+
tape(name + ' async w/ ' + description, function (t) {
122+
t.plan(1)
130123

131-
algos.forEach(function (algorithm) {
132-
describe(algorithm, function () {
133-
fixtures.valid.forEach(function (f) {
134-
var key = f.key || new Buffer(f.keyHex, 'hex')
135-
var salt = f.salt || new Buffer(f.saltHex, 'hex')
136-
var expected = f.results[algorithm]
137-
var description = f.description || ('encodes ' + key + '(' + f.salt + ') with ' + algorithm + ' to ' + expected)
138-
139-
it(description, function () {
140-
var result = compat.pbkdf2Sync(key, salt, f.iterations, f.dkLen, algorithm)
141-
142-
assert.equal(result.toString('hex'), expected)
143-
})
144-
})
145-
146-
fixtures.invalid.forEach(function (f) {
147-
it('should throw ' + f.exception, function () {
148-
assert.throws(function () {
149-
compat.pbkdf2Sync(f.key, f.salt, f.iterations, f.dkLen, f.algo)
150-
}, new RegExp(f.exception))
151-
})
152-
})
153-
})
154-
})
124+
t.throws(function () {
125+
compat.pbkdf2(f.key, f.salt, f.iterations, f.dkLen, f.algo, function () {})
126+
}, new RegExp(f.exception))
127+
})
128+
129+
tape(name + ' sync w/' + description, function (t) {
130+
t.plan(1)
131+
132+
t.throws(function () {
133+
compat.pbkdf2Sync(f.key, f.salt, f.iterations, f.dkLen, f.algo)
134+
}, new RegExp(f.exception))
155135
})
156136
})
157137
})
138+
139+
tape('pbkdf2Sync defaults to sha1', function (t) {
140+
t.plan(1)
141+
142+
var result = compat.pbkdf2Sync('password', 'salt', 1, 32)
143+
t.equal(result.toString('hex'), '0c60c80f961f0e71f3a9b524af6012062fe037a6e0f0eb94fe8fc46bdc637164')
144+
})
158145
}
159146

160147
runTests('JavaScript pbkdf2', require('../browser'))

0 commit comments

Comments
 (0)