UNPKG

1.21 kBJavaScriptView Raw
1var md5 = require('./md5.js');
2var assert = require('assert');
3
4describe('MD5', function () {
5 it('should return the expected MD5 hash for "message"', function () {
6 assert.equal('78e731027d8fd50ed642340b7c9a63b3', md5('message'));
7 });
8
9 it('should not return the same hash for random numbers twice', function () {
10 var msg1 = Math.floor((Math.random() * 100000) + 1) + (new Date).getTime();
11 var msg2 = Math.floor((Math.random() * 100000) + 1) + (new Date).getTime();
12
13 if (msg1 !== msg2)
14 assert.notEqual(md5(msg1), md5(msg2));
15 else
16 assert.equal(md5(msg1), md5(msg1));
17 });
18
19 it('should support Node.js Buffers', function() {
20 var buffer = new Buffer('message áßäöü', 'utf8');
21
22 assert.equal(md5(buffer), md5('message áßäöü'));
23 })
24
25 it('should be able to use a binary encoded string', function () {
26 var hash1 = md5('abc', { asString: true });
27 var hash2 = md5(hash1 + 'a', { asString: true, encoding : 'binary' });
28 var hash3 = md5(hash1 + 'a', { encoding : 'binary' });
29 // console.log('hash1', hash1);
30 // console.log('hash2', hash2);
31 // console.log('hash3', hash3);
32 assert.equal(hash3, '131f0ac52813044f5110e4aec638c169');
33 });
34});