Skip to content

Commit

Permalink
Add unit test for integrity
Browse files Browse the repository at this point in the history
Signed-off-by: Jinzhe Zeng <[email protected]>
  • Loading branch information
njzjz committed Dec 3, 2023
1 parent c0f48c4 commit 9858396
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions test/validate/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,21 @@ describe('Validate', () => {
});
});

it('vendors', () => {
it('vendors', async () => {

Check failure on line 16 in test/validate/index.js

View workflow job for this annotation

GitHub Actions / linter

Unexpected space before function parentheses
const { createHash } = require('crypto');
const { getVendors } = require('../../scripts/events/lib/utils');
const vendorsFile = fs.readFileSync(path.join(__dirname, '../../_vendors.yml'));
should.not.throw(() => {
yaml.load(vendorsFile);
});
(await Promise.all(Object.entries(yaml.load(vendorsFile)).map(async ([key, vendor]) => {

Check failure on line 20 in test/validate/index.js

View workflow job for this annotation

GitHub Actions / linter

Unexpected space before function parentheses
vendor.minified = vendor.file || '';
const { cdnjs } = getVendors(vendor);
// fetch content and check sha256
return await fetch(cdnjs)
.then((response) => response.text())

Check failure on line 25 in test/validate/index.js

View workflow job for this annotation

GitHub Actions / linter

Unexpected parentheses around single function argument
.then((body) => {

Check failure on line 26 in test/validate/index.js

View workflow job for this annotation

GitHub Actions / linter

Unexpected parentheses around single function argument
const integrity = Buffer.from(createHash('sha256').update(body, 'utf8').digest()).toString('base64');
return !vendor.integrity || "sha256-" + integrity == vendor.integrity;

Check failure on line 28 in test/validate/index.js

View workflow job for this annotation

GitHub Actions / linter

Strings must use singlequote

Check failure on line 28 in test/validate/index.js

View workflow job for this annotation

GitHub Actions / linter

Expected '===' and instead saw '=='
});
}))).should.all.equal(true);
});

it('language', () => {
Expand Down

0 comments on commit 9858396

Please sign in to comment.