-
-
Notifications
You must be signed in to change notification settings - Fork 202
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d1088bf
commit bc593db
Showing
2 changed files
with
10 additions
and
7 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,29 @@ | ||
var test = require('tape') | ||
var timingSafeEqual = require('timing-safe-equal/browser') | ||
var bufferShims = require('buffer-shims') | ||
var Buffer = require('safe-buffer').Buffer | ||
test('timingSafeEqual', function (t) { | ||
t.plan(5) | ||
t.strictEqual( | ||
timingSafeEqual(bufferShims.from('foo'), bufferShims.from('foo')), | ||
timingSafeEqual(Buffer.from('foo'), Buffer.from('foo')), | ||
true, | ||
'should consider equal strings to be equal' | ||
) | ||
|
||
t.strictEqual( | ||
timingSafeEqual(bufferShims.from('foo'), bufferShims.from('bar')), | ||
timingSafeEqual(Buffer.from('foo'), Buffer.from('bar')), | ||
false, | ||
'should consider unequal strings to be unequal' | ||
) | ||
|
||
t.throws(function () { | ||
timingSafeEqual(bufferShims.from([1, 2, 3]), bufferShims.from([1, 2])) | ||
timingSafeEqual(Buffer.from([1, 2, 3]), Buffer.from([1, 2])) | ||
}, 'should throw when given buffers with different lengths') | ||
|
||
t.throws(function () { | ||
timingSafeEqual('not a buffer', bufferShims.from([1, 2])) | ||
timingSafeEqual('not a buffer', Buffer.from([1, 2])) | ||
}, 'should throw if the first argument is not a buffer') | ||
|
||
t.throws(function () { | ||
timingSafeEqual(bufferShims.from([1, 2]), 'not a buffer') | ||
timingSafeEqual(Buffer.from([1, 2]), 'not a buffer') | ||
}, 'should throw if the second argument is not a buffer') | ||
}) |