This repository has been archived by the owner on Jul 21, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 52
Catch error when unmarshaling instead of crashing #113
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
a49cd36
test: Add failing tests
mkg20001 1023cb2
fix: Fix some failing tests
mkg20001 5d21bff
fix: various fixes on garbage error handling and respective tests
pgte a0996cd
tests: increased timeout for test timing out in CI
pgte 5355abc
tests: increasing test timeout to please the CI gods
pgte 3919cb8
tests: increasing test timeout to please the CI gods
pgte deb6ec1
fix: for when unMarshallPrivateKey is called with null or undefined key
pgte File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
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
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
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,46 @@ | ||
/* eslint-env mocha */ | ||
'use strict' | ||
|
||
const chai = require('chai') | ||
const dirtyChai = require('dirty-chai') | ||
const expect = chai.expect | ||
chai.use(dirtyChai) | ||
|
||
const util = require('util') | ||
const garbage = [Buffer.from('00010203040506070809', 'hex'), {}, null, false, undefined, true, 1, 0, Buffer.from(''), 'aGVsbG93b3JsZA==', 'helloworld', ''] | ||
|
||
function doTests (fncName, fnc, num, skipBuffersAndStrings) { | ||
if (!num) { | ||
num = 1 | ||
} | ||
|
||
garbage.forEach((garbage) => { | ||
if (skipBuffersAndStrings && (Buffer.isBuffer(garbage) || (typeof garbage) === 'string')) { | ||
// skip this garbage because it's a buffer or a string and we were told do do that | ||
return | ||
} | ||
let args = [] | ||
for (let i = 0; i < num; i++) { | ||
args.push(garbage) | ||
} | ||
it(fncName + '(' + args.map(garbage => util.inspect(garbage)).join(', ') + ')', cb => { | ||
args.push((err, res) => { | ||
expect(err).to.exist() | ||
expect(res).to.not.exist() | ||
cb() | ||
}) | ||
|
||
fnc.apply(null, args) | ||
}) | ||
}) | ||
} | ||
|
||
module.exports = (obj, fncs, num) => { | ||
describe('returns error via cb instead of crashing', () => { | ||
fncs.forEach(fnc => { | ||
doTests(fnc, obj[fnc], num) | ||
}) | ||
}) | ||
} | ||
|
||
module.exports.doTests = doTests |
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
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
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.
Where would an exception be thrown in this operation?
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.
Never underestimate the power of undefined:
TypeError: Cannot read property 'e' of undefined
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.
True, but in this case, it would never through that error, only if you did something like
key.e.something
. As long as ifkey
exists and it is an object,key.e
will never throwThere 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.
reverted this, but now inside a
setImmediate
.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.
And what about
unmarshalPrivateKey(undefined, (err, res) => {})
??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.
@mkg20001 good point, fixing.