-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathmd5.test.js
75 lines (65 loc) · 2.25 KB
/
md5.test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
import C from '../src/index';
const VECTOR_TEST_CONFIG = [
[1, '', 'd41d8cd98f00b204e9800998ecf8427e'],
[2, 'a', '0cc175b9c0f1b6a831c399e269772661'],
[3, 'abc', '900150983cd24fb0d6963f7d28e17f72'],
[4, 'message digest', 'f96b697d7cb7938d525a2f31aaf161d0'],
[5, 'abcdefghijklmnopqrstuvwxyz', 'c3fcd3d76192e4007dfb496cca67e13b'],
[6, 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789', 'd174ab98d277d9f5a5611c2c9f419d9f'],
[7, '12345678901234567890123456789012345678901234567890123456789012345678901234567890', '57edf4a22be3c955ac49da2e2107b67a']
];
beforeAll(async () => {
await C.MD5.loadWasm();
});
const CLONE_TEST_CONFIG = [
['a', 'a'],
['b', 'ab'],
['c', 'abc']
];
describe('algo-md5-test', () => {
test.each(VECTOR_TEST_CONFIG)(
'testVector%i',
(a,b, expected) => {
expect(C.MD5(b).toString()).toBe(expected);
}
);
describe('testClone', () => {
const md5 = new C.algo.MD5();
test.each(CLONE_TEST_CONFIG)(
'return %s, %s',
(a, expected) => {
expect(md5.update(a).clone().finalize().toString()).toBe(C.MD5(expected).toString());
}
);
});
test('testUpdateAndLongMessage', () => {
let i = 0;
const md5 = new C.algo.MD5();
while (i < 100) {
md5.update('12345678901234567890123456789012345678901234567890');
i++;
}
expect(md5.finalize().toString()).toBe('7d017545e0268a6a12f2b507871d0429');
});
test('testCreate', () => {
let i = 0;
const md5 = C.algo.MD5.create();
while (i < 100) {
md5.update('12345678901234567890123456789012345678901234567890');
i++;
}
expect(md5.finalize().toString()).toBe('7d017545e0268a6a12f2b507871d0429');
});
test('testInputIntegrity', () => {
const message = new C.lib.WordArray([0x12345678]);
const expected = message.toString();
C.MD5(message);
expect(message.toString()).toBe(expected);
});
test('testHelper', () => {
expect(C.MD5('').toString()).toBe(new C.algo.MD5().finalize('').toString());
});
test('testHmacHelper', () => {
expect(C.HmacMD5('Hi There', C.enc.Hex.parse('0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b')).toString()).toBe(new C.algo.HMAC(C.algo.MD5, C.enc.Hex.parse('0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b')).finalize('Hi There').toString());
});
});