Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add unit test for integrity #729

Closed
wants to merge 3 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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() => {
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]) => {
vendor.minified = vendor.file || '';
const { cdnjs } = getVendors(vendor);
// fetch content and check sha256
return await fetch(cdnjs)
.then(response => response.text())
.then(body => {
const integrity = Buffer.from(createHash('sha256').update(body, 'utf8').digest()).toString('base64');
return !vendor.integrity || 'sha256-' + integrity === vendor.integrity;
});
})))[0].should.all.equal(true);
});

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