|
9 | 9 | * http://www.opensource.org/licenses/MIT |
10 | 10 | */ |
11 | 11 |
|
12 | | -/*global require */ |
| 12 | +/*global describe, it, expect, require */ |
13 | 13 |
|
14 | | -(function ($) { |
| 14 | +(function (expect, md5) { |
15 | 15 | 'use strict'; |
16 | 16 |
|
17 | | - var lifecycle = { |
18 | | - setup: function () {}, |
19 | | - teardown: function () {} |
20 | | - }, |
21 | | - nodeQunit = { |
22 | | - setup: function () {}, |
23 | | - teardown: function () {} |
24 | | - }; |
25 | | - |
26 | | - if (!$.module) { |
27 | | - // Node.js QUnit compatible Testrunner: |
28 | | - nodeQunit = require('node-qunit'); |
29 | | - $.module = nodeQunit.module; |
30 | | - $.test = nodeQunit.test; |
31 | | - $.strictEqual = nodeQunit.assert.strictEqual; |
32 | | - $.md5 = require('../md5').md5; |
33 | | - } |
34 | | - |
35 | | - nodeQunit.setup(); |
36 | | - |
37 | | - $.module('Hex-encoded MD5', lifecycle); |
38 | | - |
39 | | - $.test('Creating hex-encoded MD5 hash of an ASCII value', function () { |
40 | | - $.strictEqual( |
41 | | - $.md5('value'), |
42 | | - '2063c1608d6e0baf80249c42e2be5804' |
43 | | - ); |
44 | | - }); |
| 17 | + describe('MD5 Hex-encoding', function () { |
45 | 18 |
|
46 | | - $.test('Creating hex-encoded MD5 hash of an UTF-8 value', function () { |
47 | | - $.strictEqual( |
48 | | - $.md5('日本'), |
49 | | - '4dbed2e657457884e67137d3514119b3' |
50 | | - ); |
51 | | - }); |
| 19 | + it('should create a hex-encoded MD5 hash of an ASCII value', function () { |
| 20 | + expect( |
| 21 | + md5('value') |
| 22 | + ).to.be( |
| 23 | + '2063c1608d6e0baf80249c42e2be5804' |
| 24 | + ); |
| 25 | + }); |
52 | 26 |
|
53 | | - $.module('Hex-encoded HMAC-MD5', lifecycle); |
| 27 | + it('should create a hex-encoded MD5 hash of an UTF-8 value', function () { |
| 28 | + expect( |
| 29 | + md5('日本') |
| 30 | + ).to.be( |
| 31 | + '4dbed2e657457884e67137d3514119b3' |
| 32 | + ); |
| 33 | + }); |
54 | 34 |
|
55 | | - $.test('Creating hex-encoded HMAC-MD5 hash of an ASCII value and key', function () { |
56 | | - $.strictEqual( |
57 | | - $.md5('value', 'key'), |
58 | | - '01433efd5f16327ea4b31144572c67f6' |
59 | | - ); |
60 | 35 | }); |
61 | 36 |
|
62 | | - $.test('Creating hex-encoded HMAC-MD5 hash of an UTF-8 value and key', function () { |
63 | | - $.strictEqual( |
64 | | - $.md5('日本', '日本'), |
65 | | - 'c78b8c7357926981cc04740bd3e9d015' |
66 | | - ); |
67 | | - }); |
| 37 | + describe('HMAC-MD5 Hex-encoding', function () { |
68 | 38 |
|
69 | | - $.module('Raw MD5', lifecycle); |
| 39 | + it('should create a hex-encoded HMAC-MD5 hash of an ASCII value and key', function () { |
| 40 | + expect( |
| 41 | + md5('value', 'key') |
| 42 | + ).to.be( |
| 43 | + '01433efd5f16327ea4b31144572c67f6' |
| 44 | + ); |
| 45 | + }); |
70 | 46 |
|
71 | | - $.test('Creating raw MD5 hash of an ASCII value', function () { |
72 | | - $.strictEqual( |
73 | | - $.md5('value', null, true), |
74 | | - ' c\xc1`\x8dn\x0b\xaf\x80$\x9cB\xe2\xbeX\x04' |
75 | | - ); |
76 | | - }); |
| 47 | + it('should create a hex-encoded HMAC-MD5 hash of an UTF-8 value and key', function () { |
| 48 | + expect( |
| 49 | + md5('日本', '日本') |
| 50 | + ).to.be( |
| 51 | + 'c78b8c7357926981cc04740bd3e9d015' |
| 52 | + ); |
| 53 | + }); |
77 | 54 |
|
78 | | - $.test('Creating raw MD5 hash of an UTF-8 value', function () { |
79 | | - $.strictEqual( |
80 | | - $.md5('日本', null, true), |
81 | | - 'M\xbe\xd2\xe6WEx\x84\xe6q7\xd3QA\x19\xb3' |
82 | | - ); |
83 | 55 | }); |
84 | 56 |
|
85 | | - $.module('Raw HMAC-MD5', lifecycle); |
| 57 | + describe('MD5 raw encoding', function () { |
86 | 58 |
|
87 | | - $.test('Creating raw HMAC-MD5 hash of an ASCII value and key', function () { |
88 | | - $.strictEqual( |
89 | | - $.md5('value', 'key', true), |
90 | | - '\x01C>\xfd_\x162~\xa4\xb3\x11DW,g\xf6' |
91 | | - ); |
92 | | - }); |
| 59 | + it('should create a raw MD5 hash of an ASCII value', function () { |
| 60 | + expect( |
| 61 | + md5('value', null, true) |
| 62 | + ).to.be( |
| 63 | + ' c\xc1`\x8dn\x0b\xaf\x80$\x9cB\xe2\xbeX\x04' |
| 64 | + ); |
| 65 | + }); |
| 66 | + |
| 67 | + it('should create a raw MD5 hash of an UTF-8 value', function () { |
| 68 | + expect( |
| 69 | + md5('日本', null, true) |
| 70 | + ).to.be( |
| 71 | + 'M\xbe\xd2\xe6WEx\x84\xe6q7\xd3QA\x19\xb3' |
| 72 | + ); |
| 73 | + }); |
93 | 74 |
|
94 | | - $.test('Creating raw HMAC-MD5 hash of an UTF-8 value and key', function () { |
95 | | - $.strictEqual( |
96 | | - $.md5('日本', '日本', true), |
97 | | - '\xc7\x8b\x8csW\x92i\x81\xcc\x04t\x0b\xd3\xe9\xd0\x15' |
98 | | - ); |
99 | 75 | }); |
100 | 76 |
|
101 | | - nodeQunit.teardown(); |
| 77 | + describe('HMAC-MD5 raw encoding', function () { |
| 78 | + |
| 79 | + it('should create a raw HMAC-MD5 hash of an ASCII value and key', function () { |
| 80 | + expect( |
| 81 | + md5('value', 'key', true) |
| 82 | + ).to.be( |
| 83 | + '\x01C>\xfd_\x162~\xa4\xb3\x11DW,g\xf6' |
| 84 | + ); |
| 85 | + }); |
| 86 | + |
| 87 | + it('should create a raw HMAC-MD5 hash of an UTF-8 value and key', function () { |
| 88 | + expect( |
| 89 | + md5('日本', '日本', true) |
| 90 | + ).to.be( |
| 91 | + '\xc7\x8b\x8csW\x92i\x81\xcc\x04t\x0b\xd3\xe9\xd0\x15' |
| 92 | + ); |
| 93 | + }); |
| 94 | + |
| 95 | + }); |
102 | 96 |
|
103 | | -}(this)); |
| 97 | +}( |
| 98 | + this.expect || require('expect.js'), |
| 99 | + this.md5 || require('../md5').md5 |
| 100 | +)); |
0 commit comments