New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.
Already on GitHub? Sign in to your account
Complete code coverage #23
Merged
Merged
Changes from 3 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
6de3428
test(validate-session): Increase unit coverage to 100%
minrwhite 2491975
test(utils/hash-password): Increase coverage of unit/repo to 100%
minrwhite 0d763aa
test(integration): Cover branch preinitializing admins in config
minrwhite 2d80876
test(integration): Insert pregenerated admin key
minrwhite File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,6 @@ | ||
require('./unit/set-test') | ||
require('./unit/validate-password-test') | ||
require('./unit/validate-session-test') | ||
require('./unit/utils/admin-hash-to-doc-test') | ||
require('./unit/utils/hash-password-test') | ||
require('./integration/factory-test') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
var simple = require('simple-mock') | ||
var test = require('tape') | ||
var proxyquire = require('proxyquire').noCallThru().noPreserveCache() | ||
|
||
test('hash-password', function (group) { | ||
group.test('when pbkdf2 errors', function(t) { | ||
var pbkdf2Stub = simple.stub() | ||
var callbackStub = simple.stub() | ||
|
||
var hashPassword = proxyquire('../../../lib/utils/hash-password', { | ||
crypto: { | ||
pbkdf2: pbkdf2Stub | ||
} | ||
}) | ||
|
||
t.plan(3) | ||
|
||
var error = new Error('pbkdf2 error') | ||
pbkdf2Stub.callbackAtIndex(4, error) | ||
|
||
t.doesNotThrow(function () { | ||
hashPassword('password', 'salt', 10, callbackStub) | ||
}, error, "does not throw the pbkdf2 error") | ||
|
||
t.equal(callbackStub.callCount, 1, "calls the callback once only") | ||
t.equal(callbackStub.lastCall.args[0], error, "with the error returned from pbkdf2") | ||
}) | ||
|
||
group.end() | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
var simple = require('simple-mock') | ||
var test = require('tape') | ||
var proxyquire = require('proxyquire').noCallThru().noPreserveCache() | ||
|
||
test('validate-session', function (group) { | ||
group.test('when session does not validate', function(t) { | ||
var getAdminStub = simple.stub() | ||
var calculateSessionIdStub = simple.stub() | ||
var decodeSessionIdStub = simple.stub() | ||
|
||
var unauthorized = new Error("Invalid Session") | ||
var validateSession = proxyquire('../../lib/validate-session', { | ||
'./get': getAdminStub, | ||
'couchdb-calculate-session-id': calculateSessionIdStub, | ||
'./utils/couchdb-decode-session-id': decodeSessionIdStub, | ||
'pouchdb-errors': {UNAUTHORIZED: unauthorized} | ||
}) | ||
|
||
t.plan(1) | ||
|
||
getAdminStub.resolveWith({ | ||
salt: 'im-salty' | ||
}) | ||
|
||
decodeSessionIdStub.returnWith({ | ||
username: 'a-user', | ||
timestamp: 987654321 | ||
}) | ||
|
||
calculateSessionIdStub.returnWith('validSessionId') | ||
|
||
validateSession({}, 'invalidSessionId') | ||
.then(function () { | ||
t.fail("should not resolve") | ||
}) | ||
.catch(function (caughtError) { | ||
t.equal(caughtError, unauthorized, "should reject the returned promise with pouchdb's UNAUTHORIZED error") | ||
}) | ||
}) | ||
|
||
group.end() | ||
}) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do we need to dynamically generate
userEntry
here or can we directly use a pre-generated key?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we need to run
generateSalt
orhashPassword
for code coverage, I鈥檇 rather make unit testsThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, no need to run
generateSalt
orhashPassword
, it was just for convenience rather than hardcoding in a pre-generated key at the time; but it probably makes sense to pregenerate it. Changing now.