build: enable JS semicolons (#22783)

This commit is contained in:
Samuel Attard 2020-03-20 13:28:31 -07:00 committed by GitHub
parent 24e21467b9
commit 5d657dece4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
354 changed files with 21512 additions and 21510 deletions

View file

@ -1,76 +1,76 @@
import { expect } from 'chai'
import * as http from 'http'
import * as fs from 'fs'
import * as path from 'path'
import * as url from 'url'
import { expect } from 'chai';
import * as http from 'http';
import * as fs from 'fs';
import * as path from 'path';
import * as url from 'url';
import { BrowserWindow, WebPreferences } from 'electron'
import { BrowserWindow, WebPreferences } from 'electron';
import { closeWindow } from './window-helpers'
import { AddressInfo } from 'net'
import { emittedUntil } from './events-helpers'
import { closeWindow } from './window-helpers';
import { AddressInfo } from 'net';
import { emittedUntil } from './events-helpers';
const messageContainsSecurityWarning = (event: Event, level: number, message: string) => {
return message.indexOf('Electron Security Warning') > -1
}
return message.indexOf('Electron Security Warning') > -1;
};
const isLoaded = (event: Event, level: number, message: string) => {
return (message === 'loaded')
}
return (message === 'loaded');
};
describe('security warnings', () => {
let server: http.Server
let w: BrowserWindow
let useCsp = true
let serverUrl: string
let server: http.Server;
let w: BrowserWindow;
let useCsp = true;
let serverUrl: string;
before((done) => {
// Create HTTP Server
server = http.createServer((request, response) => {
const uri = url.parse(request.url!).pathname!
let filename = path.join(__dirname, '..', 'spec', 'fixtures', 'pages', uri)
const uri = url.parse(request.url!).pathname!;
let filename = path.join(__dirname, '..', 'spec', 'fixtures', 'pages', uri);
fs.stat(filename, (error, stats) => {
if (error) {
response.writeHead(404, { 'Content-Type': 'text/plain' })
response.end()
return
response.writeHead(404, { 'Content-Type': 'text/plain' });
response.end();
return;
}
if (stats.isDirectory()) {
filename += '/index.html'
filename += '/index.html';
}
fs.readFile(filename, 'binary', (err, file) => {
if (err) {
response.writeHead(404, { 'Content-Type': 'text/plain' })
response.end()
return
response.writeHead(404, { 'Content-Type': 'text/plain' });
response.end();
return;
}
const cspHeaders = { 'Content-Security-Policy': 'script-src \'self\' \'unsafe-inline\'' }
response.writeHead(200, useCsp ? cspHeaders : undefined)
response.write(file, 'binary')
response.end()
})
})
const cspHeaders = { 'Content-Security-Policy': 'script-src \'self\' \'unsafe-inline\'' };
response.writeHead(200, useCsp ? cspHeaders : undefined);
response.write(file, 'binary');
response.end();
});
});
}).listen(0, '127.0.0.1', () => {
serverUrl = `http://127.0.0.1:${(server.address() as AddressInfo).port}`
done()
})
})
serverUrl = `http://127.0.0.1:${(server.address() as AddressInfo).port}`;
done();
});
});
after(() => {
// Close server
server.close()
server = null as unknown as any
})
server.close();
server = null as unknown as any;
});
afterEach(async () => {
useCsp = true
await closeWindow(w)
w = null as unknown as any
})
useCsp = true;
await closeWindow(w);
w = null as unknown as any;
});
it('should warn about Node.js integration with remote content', async () => {
w = new BrowserWindow({
@ -78,12 +78,12 @@ describe('security warnings', () => {
webPreferences: {
nodeIntegration: true
}
})
});
w.loadURL(`${serverUrl}/base-page-security.html`)
const [,, message] = await emittedUntil(w.webContents, 'console-message', messageContainsSecurityWarning)
expect(message).to.include('Node.js Integration with Remote Content')
})
w.loadURL(`${serverUrl}/base-page-security.html`);
const [,, message] = await emittedUntil(w.webContents, 'console-message', messageContainsSecurityWarning);
expect(message).to.include('Node.js Integration with Remote Content');
});
it('should not warn about Node.js integration with remote content from localhost', async () => {
w = new BrowserWindow({
@ -91,12 +91,12 @@ describe('security warnings', () => {
webPreferences: {
nodeIntegration: true
}
})
});
w.loadURL(`${serverUrl}/base-page-security-onload-message.html`)
const [,, message] = await emittedUntil(w.webContents, 'console-message', isLoaded)
expect(message).to.not.include('Node.js Integration with Remote Content')
})
w.loadURL(`${serverUrl}/base-page-security-onload-message.html`);
const [,, message] = await emittedUntil(w.webContents, 'console-message', isLoaded);
expect(message).to.not.include('Node.js Integration with Remote Content');
});
const generateSpecs = (description: string, webPreferences: WebPreferences) => {
describe(description, () => {
@ -107,12 +107,12 @@ describe('security warnings', () => {
webSecurity: false,
...webPreferences
}
})
});
w.loadURL(`${serverUrl}/base-page-security.html`)
const [,, message] = await emittedUntil(w.webContents, 'console-message', messageContainsSecurityWarning)
expect(message).to.include('Disabled webSecurity')
})
w.loadURL(`${serverUrl}/base-page-security.html`);
const [,, message] = await emittedUntil(w.webContents, 'console-message', messageContainsSecurityWarning);
expect(message).to.include('Disabled webSecurity');
});
it('should warn about insecure Content-Security-Policy', async () => {
w = new BrowserWindow({
@ -121,13 +121,13 @@ describe('security warnings', () => {
enableRemoteModule: false,
...webPreferences
}
})
});
useCsp = false
w.loadURL(`${serverUrl}/base-page-security.html`)
const [,, message] = await emittedUntil(w.webContents, 'console-message', messageContainsSecurityWarning)
expect(message).to.include('Insecure Content-Security-Policy')
})
useCsp = false;
w.loadURL(`${serverUrl}/base-page-security.html`);
const [,, message] = await emittedUntil(w.webContents, 'console-message', messageContainsSecurityWarning);
expect(message).to.include('Insecure Content-Security-Policy');
});
it('should warn about allowRunningInsecureContent', async () => {
w = new BrowserWindow({
@ -136,12 +136,12 @@ describe('security warnings', () => {
allowRunningInsecureContent: true,
...webPreferences
}
})
});
w.loadURL(`${serverUrl}/base-page-security.html`)
const [,, message] = await emittedUntil(w.webContents, 'console-message', messageContainsSecurityWarning)
expect(message).to.include('allowRunningInsecureContent')
})
w.loadURL(`${serverUrl}/base-page-security.html`);
const [,, message] = await emittedUntil(w.webContents, 'console-message', messageContainsSecurityWarning);
expect(message).to.include('allowRunningInsecureContent');
});
it('should warn about experimentalFeatures', async () => {
w = new BrowserWindow({
@ -150,12 +150,12 @@ describe('security warnings', () => {
experimentalFeatures: true,
...webPreferences
}
})
});
w.loadURL(`${serverUrl}/base-page-security.html`)
const [,, message] = await emittedUntil(w.webContents, 'console-message', messageContainsSecurityWarning)
expect(message).to.include('experimentalFeatures')
})
w.loadURL(`${serverUrl}/base-page-security.html`);
const [,, message] = await emittedUntil(w.webContents, 'console-message', messageContainsSecurityWarning);
expect(message).to.include('experimentalFeatures');
});
it('should warn about enableBlinkFeatures', async () => {
w = new BrowserWindow({
@ -164,69 +164,69 @@ describe('security warnings', () => {
enableBlinkFeatures: 'my-cool-feature',
...webPreferences
}
})
});
w.loadURL(`${serverUrl}/base-page-security.html`)
const [,, message] = await emittedUntil(w.webContents, 'console-message', messageContainsSecurityWarning)
expect(message).to.include('enableBlinkFeatures')
})
w.loadURL(`${serverUrl}/base-page-security.html`);
const [,, message] = await emittedUntil(w.webContents, 'console-message', messageContainsSecurityWarning);
expect(message).to.include('enableBlinkFeatures');
});
it('should warn about allowpopups', async () => {
w = new BrowserWindow({
show: false,
webPreferences
})
});
w.loadURL(`${serverUrl}/webview-allowpopups.html`)
const [,, message] = await emittedUntil(w.webContents, 'console-message', messageContainsSecurityWarning)
expect(message).to.include('allowpopups')
})
w.loadURL(`${serverUrl}/webview-allowpopups.html`);
const [,, message] = await emittedUntil(w.webContents, 'console-message', messageContainsSecurityWarning);
expect(message).to.include('allowpopups');
});
it('should warn about insecure resources', async () => {
w = new BrowserWindow({
show: false,
webPreferences: { ...webPreferences }
})
});
w.loadURL(`${serverUrl}/insecure-resources.html`)
const [,, message] = await emittedUntil(w.webContents, 'console-message', messageContainsSecurityWarning)
expect(message).to.include('Insecure Resources')
})
w.loadURL(`${serverUrl}/insecure-resources.html`);
const [,, message] = await emittedUntil(w.webContents, 'console-message', messageContainsSecurityWarning);
expect(message).to.include('Insecure Resources');
});
it('should not warn about loading insecure-resources.html from localhost', async () => {
w = new BrowserWindow({
show: false,
webPreferences
})
});
w.loadURL(`${serverUrl}/insecure-resources.html`)
const [,, message] = await emittedUntil(w.webContents, 'console-message', messageContainsSecurityWarning)
expect(message).to.not.include('insecure-resources.html')
})
w.loadURL(`${serverUrl}/insecure-resources.html`);
const [,, message] = await emittedUntil(w.webContents, 'console-message', messageContainsSecurityWarning);
expect(message).to.not.include('insecure-resources.html');
});
it('should warn about enabled remote module with remote content', async () => {
w = new BrowserWindow({
show: false,
webPreferences
})
});
w.loadURL(`${serverUrl}/base-page-security.html`)
const [,, message] = await emittedUntil(w.webContents, 'console-message', messageContainsSecurityWarning)
expect(message).to.include('enableRemoteModule')
})
w.loadURL(`${serverUrl}/base-page-security.html`);
const [,, message] = await emittedUntil(w.webContents, 'console-message', messageContainsSecurityWarning);
expect(message).to.include('enableRemoteModule');
});
it('should not warn about enabled remote module with remote content from localhost', async () => {
w = new BrowserWindow({
show: false,
webPreferences
})
w.loadURL(`${serverUrl}/base-page-security-onload-message.html`)
const [,, message] = await emittedUntil(w.webContents, 'console-message', isLoaded)
expect(message).to.not.include('enableRemoteModule')
})
})
}
});
w.loadURL(`${serverUrl}/base-page-security-onload-message.html`);
const [,, message] = await emittedUntil(w.webContents, 'console-message', isLoaded);
expect(message).to.not.include('enableRemoteModule');
});
});
};
generateSpecs('without sandbox', {})
generateSpecs('with sandbox', { sandbox: true })
})
generateSpecs('without sandbox', {});
generateSpecs('with sandbox', { sandbox: true });
});