diff --git a/test/subresource-integrity/apply-algorith-to-bytes.js b/test/subresource-integrity/apply-algorithm-to-bytes.js similarity index 76% rename from test/subresource-integrity/apply-algorith-to-bytes.js rename to test/subresource-integrity/apply-algorithm-to-bytes.js index 4cc2d3922df..7cae1828f06 100644 --- a/test/subresource-integrity/apply-algorith-to-bytes.js +++ b/test/subresource-integrity/apply-algorithm-to-bytes.js @@ -1,7 +1,6 @@ 'use strict' const { test, describe } = require('node:test') -const assert = require('node:assert') const { applyAlgorithmToBytes } = require('../../lib/web/subresource-integrity/subresource-integrity') const { runtimeFeatures } = require('../../lib/util/runtime-features') @@ -14,16 +13,16 @@ describe('applyAlgorithmToBytes', () => { const hash384 = 'hiVfosNuSzCWnq4X3DTHcsvr38WLWEA5AL6HYU6xo0uHgCY/JV615lypu7hkHMz+' const hash512 = '9s3ioPgZMUzd5V/CJ9jX2uPSjMVWIioKitZtkcytSq1glPUXohgjYMmqz2o9wyMWLLb9jN/+2w/gOPVehf+1tg==' - test('valid sha256', { skip }, () => { + test('valid sha256', { skip }, (t) => { const result = applyAlgorithmToBytes('sha256', Buffer.from('Hello world!')) - assert.strictEqual(result, hash256) + t.assert.strictEqual(result, hash256) }) - test('valid sha384', { skip }, () => { + test('valid sha384', { skip }, (t) => { const result = applyAlgorithmToBytes('sha384', Buffer.from('Hello world!')) - assert.strictEqual(result, hash384) + t.assert.strictEqual(result, hash384) }) - test('valid sha512', { skip }, () => { + test('valid sha512', { skip }, (t) => { const result = applyAlgorithmToBytes('sha512', Buffer.from('Hello world!')) - assert.strictEqual(result, hash512) + t.assert.strictEqual(result, hash512) }) }) diff --git a/test/subresource-integrity/bytes-match.js b/test/subresource-integrity/bytes-match.js index 2b68d43c8a7..e749e05c49b 100644 --- a/test/subresource-integrity/bytes-match.js +++ b/test/subresource-integrity/bytes-match.js @@ -1,6 +1,5 @@ 'use strict' -const assert = require('node:assert') const { test, describe } = require('node:test') const { bytesMatch } = require('../../lib/web/subresource-integrity/subresource-integrity') @@ -9,9 +8,9 @@ const { runtimeFeatures } = require('../../lib/util/runtime-features') const skip = runtimeFeatures.has('crypto') === false describe('bytesMatch', () => { - test('valid sha256 and base64', { skip }, () => { + test('valid sha256 and base64', { skip }, (t) => { const data = Buffer.from('Hello world!') const hash256 = 'sha256-wFNeS+K3n/2TKRMFQ2v4iTFOSj+uwF7P/Lt98xrZ5Ro=' - assert.ok(bytesMatch(data, hash256)) + t.assert.ok(bytesMatch(data, hash256)) }) }) diff --git a/test/subresource-integrity/case-sensitive-match.js b/test/subresource-integrity/case-sensitive-match.js index 61117b01be9..b0db8839d55 100644 --- a/test/subresource-integrity/case-sensitive-match.js +++ b/test/subresource-integrity/case-sensitive-match.js @@ -1,74 +1,73 @@ 'use strict' const { test, describe } = require('node:test') -const assert = require('node:assert') const { caseSensitiveMatch } = require('../../lib/web/subresource-integrity/subresource-integrity') describe('caseSensitiveMatch', () => { - test('identical strings', () => { + test('identical strings', (t) => { const actualValue = 'ypeBEsobvcr6wjGzmiPcTaeG7/gUfE5yuYB3ha/uSLs' const expectedValue = 'ypeBEsobvcr6wjGzmiPcTaeG7/gUfE5yuYB3ha/uSLs' - assert.ok(caseSensitiveMatch(actualValue, expectedValue)) + t.assert.ok(caseSensitiveMatch(actualValue, expectedValue)) }) - test('identical strings, actualValue has one padding char', () => { + test('identical strings, actualValue has one padding char', (t) => { const actualValue = 'ypeBEsobvcr6wjGzmiPcTaeG7/gUfE5yuYB3ha/uSLs=' const expectedValue = 'ypeBEsobvcr6wjGzmiPcTaeG7/gUfE5yuYB3ha/uSLs' - assert.ok(caseSensitiveMatch(actualValue, expectedValue)) + t.assert.ok(caseSensitiveMatch(actualValue, expectedValue)) }) - test('identical strings, expectedValue has one padding char', () => { + test('identical strings, expectedValue has one padding char', (t) => { const actualValue = 'ypeBEsobvcr6wjGzmiPcTaeG7/gUfE5yuYB3ha/uSLs' const expectedValue = 'ypeBEsobvcr6wjGzmiPcTaeG7/gUfE5yuYB3ha/uSLs=' - assert.ok(caseSensitiveMatch(actualValue, expectedValue)) + t.assert.ok(caseSensitiveMatch(actualValue, expectedValue)) }) - test('identical strings, expectedValue has two padding chars', () => { + test('identical strings, expectedValue has two padding chars', (t) => { const actualValue = 'ypeBEsobvcr6wjGzmiPcTaeG7/gUfE5yuYB3ha/uSLs' const expectedValue = 'ypeBEsobvcr6wjGzmiPcTaeG7/gUfE5yuYB3ha/uSLs==' - assert.ok(caseSensitiveMatch(actualValue, expectedValue)) + t.assert.ok(caseSensitiveMatch(actualValue, expectedValue)) }) - test('identical strings, both have one padding char', () => { + test('identical strings, both have one padding char', (t) => { const actualValue = 'ypeBEsobvcr6wjGzmiPcTaeG7/gUfE5yuYB3ha/uSLs=' const expectedValue = 'ypeBEsobvcr6wjGzmiPcTaeG7/gUfE5yuYB3ha/uSLs=' - assert.ok(caseSensitiveMatch(actualValue, expectedValue)) + t.assert.ok(caseSensitiveMatch(actualValue, expectedValue)) }) - test('identical strings, both have two padding chars', () => { + test('identical strings, both have two padding chars', (t) => { const actualValue = 'ypeBEsobvcr6wjGzmiPcTaeG7/gUfE5yuYB3ha/uSLs==' const expectedValue = 'ypeBEsobvcr6wjGzmiPcTaeG7/gUfE5yuYB3ha/uSLs==' - assert.ok(caseSensitiveMatch(actualValue, expectedValue)) + t.assert.ok(caseSensitiveMatch(actualValue, expectedValue)) }) - test('identical strings, expectedValue has invalid third padding char', () => { + test('identical strings, expectedValue has invalid third padding char', (t) => { const actualValue = 'ypeBEsobvcr6wjGzmiPcTaeG7/gUfE5yuYB3ha/uSLs==' const expectedValue = 'ypeBEsobvcr6wjGzmiPcTaeG7/gUfE5yuYB3ha/uSLs===' - assert.ok(caseSensitiveMatch(actualValue, expectedValue) === false) + t.assert.ok(caseSensitiveMatch(actualValue, expectedValue) === false) }) - test('expectedValue can be base64Url - match `_`', () => { + test('expectedValue can be base64Url - match `_`', (t) => { const actualValue = 'ypeBEsobvcr6wjGzmiPcTaeG7/gUfE5yuYB3ha/uSLs' const expectedValue = 'ypeBEsobvcr6wjGzmiPcTaeG7_gUfE5yuYB3ha/uSLs' - assert.ok(caseSensitiveMatch(actualValue, expectedValue)) + t.assert.ok(caseSensitiveMatch(actualValue, expectedValue)) }) - test('expectedValue can be base64Url - match `+`', () => { + test('expectedValue can be base64Url - match `+`', (t) => { const actualValue = 'ypeBEsobvcr6wjGzmiPcTaeG7+gUfE5yuYB3ha/uSLs' const expectedValue = 'ypeBEsobvcr6wjGzmiPcTaeG7-gUfE5yuYB3ha/uSLs' - assert.ok(caseSensitiveMatch(actualValue, expectedValue)) + t.assert.ok(caseSensitiveMatch(actualValue, expectedValue)) }) - test('should be case sensitive', () => { + test('should be case sensitive', (t) => { const actualValue = 'ypeBEsobvcr6wjGzmiPcTaeG7/gUfE5yuYB3ha/uSLs' const expectedValue = 'ypeBEsobvcr6wjGzmiPcTaeG7/gUfE5yuYB3ha/uSLS' - assert.ok(caseSensitiveMatch(actualValue, expectedValue) === false) + t.assert.ok(caseSensitiveMatch(actualValue, expectedValue) === false) }) - test('empty string should return true', () => { + test('empty string should return true', (t) => { const actualValue = '' const expectedValue = '' - assert.ok(caseSensitiveMatch(actualValue, expectedValue)) + t.assert.ok(caseSensitiveMatch(actualValue, expectedValue)) }) }) diff --git a/test/subresource-integrity/get-strongest-metadata.js b/test/subresource-integrity/get-strongest-metadata.js index 4da88db2f20..216bb1f4661 100644 --- a/test/subresource-integrity/get-strongest-metadata.js +++ b/test/subresource-integrity/get-strongest-metadata.js @@ -1,71 +1,70 @@ 'use strict' -const assert = require('node:assert') const { test, describe } = require('node:test') const { getStrongestMetadata } = require('../../lib/web/subresource-integrity/subresource-integrity') describe('getStrongestMetadata', () => { - test('should return strongest sha512 /1', () => { + test('should return strongest sha512 /1', (t) => { const result = getStrongestMetadata([ { alg: 'sha256', val: 'sha256-abc' }, { alg: 'sha384', val: 'sha384-def' }, { alg: 'sha512', val: 'sha512-ghi' } ]) - assert.deepEqual(result, [ + t.assert.deepEqual(result, [ { alg: 'sha512', val: 'sha512-ghi' } ]) }) - test('should return strongest sha512 /2', () => { + test('should return strongest sha512 /2', (t) => { const result = getStrongestMetadata([ { alg: 'sha512', val: 'sha512-ghi' }, { alg: 'sha256', val: 'sha256-abc' }, { alg: 'sha384', val: 'sha384-def' } ]) - assert.deepEqual(result, [ + t.assert.deepEqual(result, [ { alg: 'sha512', val: 'sha512-ghi' } ]) }) - test('should return strongest sha384', () => { + test('should return strongest sha384', (t) => { const result = getStrongestMetadata([ { alg: 'sha256', val: 'sha256-abc' }, { alg: 'sha384', val: 'sha384-def' } ]) - assert.deepEqual(result, [ + t.assert.deepEqual(result, [ { alg: 'sha384', val: 'sha384-def' } ]) }) - test('should return both strongest sha384', () => { + test('should return both strongest sha384', (t) => { const result = getStrongestMetadata([ { alg: 'sha384', val: 'sha384-abc' }, { alg: 'sha256', val: 'sha256-def' }, { alg: 'sha384', val: 'sha384-ghi' } ]) - assert.deepEqual(result, [ + t.assert.deepEqual(result, [ { alg: 'sha384', val: 'sha384-abc' }, { alg: 'sha384', val: 'sha384-ghi' } ]) }) - test('should return multiple metadata with the same strength', () => { + test('should return multiple metadata with the same strength', (t) => { const result = getStrongestMetadata([ { alg: 'sha256', val: 'sha256-abc' } ]) - assert.deepEqual(result, [ + t.assert.deepEqual(result, [ { alg: 'sha256', val: 'sha256-abc' } ]) }) - test('should return empty array when no metadata is provided', () => { + test('should return empty array when no metadata is provided', (t) => { const result = getStrongestMetadata([]) - assert.deepEqual(result, []) + t.assert.deepEqual(result, []) }) - test('should throw when invalid hash algorithm is provided', () => { - assert.throws(() => getStrongestMetadata([ + test('should throw when invalid hash algorithm is provided', (t) => { + t.assert.throws(() => getStrongestMetadata([ { alg: 'sha1024', val: 'sha1024-xyz' } ]), { name: 'AssertionError', diff --git a/test/subresource-integrity/is-valid-sri-hash-algorithm.js b/test/subresource-integrity/is-valid-sri-hash-algorithm.js index c08062635cb..c5c90d61020 100644 --- a/test/subresource-integrity/is-valid-sri-hash-algorithm.js +++ b/test/subresource-integrity/is-valid-sri-hash-algorithm.js @@ -1,7 +1,6 @@ 'use strict' const { test, describe } = require('node:test') -const assert = require('node:assert') const { runtimeFeatures } = require('../../lib/util/runtime-features.js') const { isValidSRIHashAlgorithm } = require('../../lib/web/subresource-integrity/subresource-integrity') @@ -9,16 +8,16 @@ const { isValidSRIHashAlgorithm } = require('../../lib/web/subresource-integrity const skip = runtimeFeatures.has('crypto') === false describe('isValidSRIHashAlgorithm', () => { - test('valid sha256', { skip }, () => { - assert.ok(isValidSRIHashAlgorithm('sha256')) + test('valid sha256', { skip }, (t) => { + t.assert.ok(isValidSRIHashAlgorithm('sha256')) }) - test('valid sha384', { skip }, () => { - assert.ok(isValidSRIHashAlgorithm('sha384')) + test('valid sha384', { skip }, (t) => { + t.assert.ok(isValidSRIHashAlgorithm('sha384')) }) - test('valid sha512', { skip }, () => { - assert.ok(isValidSRIHashAlgorithm('sha512')) + test('valid sha512', { skip }, (t) => { + t.assert.ok(isValidSRIHashAlgorithm('sha512')) }) - test('invalid sha1024', () => { - assert.ok(isValidSRIHashAlgorithm('sha1024') === false) + test('invalid sha1024', (t) => { + t.assert.ok(isValidSRIHashAlgorithm('sha1024') === false) }) }) diff --git a/test/subresource-integrity/parse-metadata.js b/test/subresource-integrity/parse-metadata.js index e9b758b41a3..2c848bb0f6e 100644 --- a/test/subresource-integrity/parse-metadata.js +++ b/test/subresource-integrity/parse-metadata.js @@ -1,6 +1,5 @@ 'use strict' -const assert = require('node:assert') const { test, describe } = require('node:test') const { parseMetadata } = require('../../lib/web/subresource-integrity/subresource-integrity') @@ -14,46 +13,46 @@ describe('parseMetadata', () => { const hash384 = 'hiVfosNuSzCWnq4X3DTHcsvr38WLWEA5AL6HYU6xo0uHgCY/JV615lypu7hkHMz+' const hash512 = '9s3ioPgZMUzd5V/CJ9jX2uPSjMVWIioKitZtkcytSq1glPUXohgjYMmqz2o9wyMWLLb9jN/+2w/gOPVehf+1tg==' - test('should parse valid metadata with option', { skip }, () => { + test('should parse valid metadata with option', { skip }, (t) => { const validMetadata = `sha256-${hash256} !@ sha384-${hash384} !@ sha512-${hash512} !@` const result = parseMetadata(validMetadata) - assert.deepEqual(result, [ + t.assert.deepEqual(result, [ { alg: 'sha256', val: hash256 }, { alg: 'sha384', val: hash384 }, { alg: 'sha512', val: hash512 } ]) }) - test('should parse valid metadata with non ASCII chars option', { skip }, () => { + test('should parse valid metadata with non ASCII chars option', { skip }, (t) => { const validMetadata = `sha256-${hash256} !© sha384-${hash384} !€ sha512-${hash512} !µ` const result = parseMetadata(validMetadata) - assert.deepEqual(result, [ + t.assert.deepEqual(result, [ { alg: 'sha256', val: hash256 }, { alg: 'sha384', val: hash384 }, { alg: 'sha512', val: hash512 } ]) }) - test('should parse valid metadata without option', { skip }, () => { + test('should parse valid metadata without option', { skip }, (t) => { const validMetadata = `sha256-${hash256} sha384-${hash384} sha512-${hash512}` const result = parseMetadata(validMetadata) - assert.deepEqual(result, [ + t.assert.deepEqual(result, [ { alg: 'sha256', val: hash256 }, { alg: 'sha384', val: hash384 }, { alg: 'sha512', val: hash512 } ]) }) - test('should not set hash as undefined when invalid base64 chars are provided', { skip }, () => { + test('should not set hash as undefined when invalid base64 chars are provided', { skip }, (t) => { const invalidHash384 = 'zifp5hE1Xl5LQQqQz[]Bq/iaq9Wb6jVb//T7EfTmbXD2aEP5c2ZdJr9YTDfcTE1ZH+' const validMetadata = `sha256-${hash256} sha384-${invalidHash384} sha512-${hash512}` const result = parseMetadata(validMetadata) - assert.deepEqual(result, [ + t.assert.deepEqual(result, [ { alg: 'sha256', val: hash256 }, { alg: 'sha384', val: invalidHash384 }, { alg: 'sha512', val: hash512 }