MCPcopy
hub / github.com/ampproject/amphtml / testSuite

Function testSuite

test/unit/test-crypto.js:27–104  ·  view source on GitHub ↗
(description, win, expectedError)

Source from the content-addressed store, hash-verified

25 }
26
27 function testSuite(description, win, expectedError) {
28 describe(description, () => {
29 beforeEach(() => {
30 crypto = createCrypto(win || env.win);
31 });
32
33 it('should hash "abc" in sha384', () => {
34 if (expectedError) {
35 expectAsyncConsoleError(expectedError);
36 }
37 return crypto.sha384('abc').then((buffer) => {
38 expect(buffer.length).to.equal(48);
39 expect(buffer[0]).to.equal(203);
40 expect(buffer[1]).to.equal(0);
41 expect(buffer[47]).to.equal(167);
42 });
43 });
44
45 it('should hash [1,2,3] in sha384', () => {
46 if (expectedError) {
47 expectAsyncConsoleError(expectedError);
48 }
49 return crypto.sha384(uint8Array([1, 2, 3])).then((buffer) => {
50 expect(buffer.length).to.equal(48);
51 expect(buffer[0]).to.equal(134);
52 expect(buffer[1]).to.equal(34);
53 expect(buffer[47]).to.equal(246);
54 });
55 });
56
57 it('should hash "abc" in sha384Base64', () => {
58 if (expectedError) {
59 expectAsyncConsoleError(expectedError);
60 }
61 return expect(crypto.sha384Base64('abc')).to.eventually.equal(
62 'ywB1P0WjXou1oD1pmsZQBycsMqsO3tFjGotgWkP_W-2AhgcroefMI1i67KE0yCWn'
63 );
64 });
65
66 it('should hash "foobar" in sha384Base64', () => {
67 if (expectedError) {
68 expectAsyncConsoleError(expectedError);
69 }
70 return expect(crypto.sha384Base64('foobar')).to.eventually.equal(
71 'PJww2fZl501RXIQpYNSkUcg6ASX9Pec5LXs3IxrxDHLqWK7fzfiaV2W_kCr5Ps8G'
72 );
73 });
74
75 it('should hash [1,2,3] in sha384', () => {
76 if (expectedError) {
77 expectAsyncConsoleError(expectedError);
78 }
79 return expect(
80 crypto.sha384Base64(uint8Array([1, 2, 3]))
81 ).to.eventually.equal(
82 'hiKdxtL_vqxzgHRBVKpwApHAZDUqDb3H' +
83 'e57T8sjh2sTcMlhn053f8dJim3o5PUf2'
84 );

Callers 1

test-crypto.jsFile · 0.70

Calls 9

beforeEachFunction · 0.85
createCryptoFunction · 0.85
expectFunction · 0.85
uint8ArrayFunction · 0.85
sha384Method · 0.80
sha384Base64Method · 0.80
uniformMethod · 0.80
itFunction · 0.50
thenMethod · 0.45

Tested by

no test coverage detected