2016-06-25 01:53:02 -07:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
const path = require('path');
|
|
|
|
const fs = require('fs');
|
2016-06-25 02:45:33 -07:00
|
|
|
const http = require('http');
|
2016-06-25 01:53:02 -07:00
|
|
|
|
|
|
|
const env = require('../modules/environment');
|
|
|
|
|
|
|
|
describe('application', function() {
|
2016-06-25 05:21:10 -07:00
|
|
|
this.timeout(10000);
|
|
|
|
|
2016-06-25 02:45:33 -07:00
|
|
|
const serverPort = 8181;
|
2016-06-25 05:21:10 -07:00
|
|
|
const testURL = `http://localhost:${serverPort}`
|
2016-06-25 02:45:33 -07:00
|
|
|
|
2016-06-25 01:53:02 -07:00
|
|
|
const config = {
|
|
|
|
version: 1,
|
|
|
|
teams: [{
|
|
|
|
name: 'example_1',
|
2016-06-25 05:21:10 -07:00
|
|
|
url: testURL
|
2016-06-25 01:53:02 -07:00
|
|
|
}, {
|
|
|
|
name: 'example_2',
|
2016-06-25 05:21:10 -07:00
|
|
|
url: testURL
|
2016-06-25 01:53:02 -07:00
|
|
|
}]
|
|
|
|
};
|
|
|
|
|
2016-06-25 02:45:33 -07:00
|
|
|
before(function() {
|
|
|
|
this.server = http.createServer(function(req, res) {
|
|
|
|
res.writeHead(200, {
|
|
|
|
'Content-Type': 'text/html'
|
|
|
|
});
|
|
|
|
res.end(fs.readFileSync(path.resolve(env.sourceRootDir, 'test/modules/test.html'), 'utf-8'));
|
|
|
|
}).listen(serverPort, '127.0.0.1');
|
|
|
|
});
|
|
|
|
|
2016-06-25 01:53:02 -07:00
|
|
|
beforeEach(function() {
|
|
|
|
fs.writeFileSync(env.configFilePath, JSON.stringify(config));
|
|
|
|
this.app = env.getSpectronApp();
|
|
|
|
return this.app.start();
|
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(function() {
|
|
|
|
if (this.app && this.app.isRunning()) {
|
|
|
|
return this.app.stop()
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2016-06-25 02:45:33 -07:00
|
|
|
after(function(done) {
|
|
|
|
this.server.close(done);
|
|
|
|
})
|
|
|
|
|
2016-06-25 01:53:02 -07:00
|
|
|
it('should NOT be able to call Node.js API in webview', function() {
|
2016-06-25 05:21:10 -07:00
|
|
|
env.addClientCommands(this.app.client);
|
2016-06-25 01:53:02 -07:00
|
|
|
return this.app.client
|
|
|
|
.getAttribute('webview', 'nodeintegration').then((nodeintegration) => {
|
|
|
|
// nodeintegration is an array of string
|
|
|
|
nodeintegration.forEach((n) => {
|
|
|
|
n.should.equal('false');
|
|
|
|
});
|
2016-06-25 05:21:10 -07:00
|
|
|
})
|
|
|
|
// webview is handled as a window by chromedriver.
|
|
|
|
.windowByIndex(1).isNodeEnabled().should.eventually.be.false
|
|
|
|
.windowByIndex(2).isNodeEnabled().should.eventually.be.false;
|
2016-06-25 01:53:02 -07:00
|
|
|
});
|
2016-06-25 02:45:33 -07:00
|
|
|
|
|
|
|
it('should NOT be able to call Node.js API in a new window', function() {
|
2016-06-25 05:21:10 -07:00
|
|
|
env.addClientCommands(this.app.client);
|
2016-06-25 06:09:37 -07:00
|
|
|
const client = this.app.client;
|
2016-06-25 02:45:33 -07:00
|
|
|
return this.app.client
|
2016-06-25 06:46:07 -07:00
|
|
|
.windowByIndex(1) // in the first webview
|
2016-06-25 02:45:33 -07:00
|
|
|
.execute(function() {
|
2016-06-25 06:46:07 -07:00
|
|
|
open_window();
|
2016-06-25 02:45:33 -07:00
|
|
|
})
|
2016-06-25 06:09:37 -07:00
|
|
|
.waitUntil(function async() {
|
|
|
|
return client.windowHandles().then((handles) => {
|
|
|
|
return handles.value.length === 4;
|
|
|
|
});
|
|
|
|
}, 5000, 'expected a new window')
|
2016-06-25 05:21:10 -07:00
|
|
|
.windowByIndex(3).isNodeEnabled().should.eventually.be.false;
|
2016-07-22 14:03:03 -07:00
|
|
|
});
|
|
|
|
|
2016-08-08 07:56:21 -07:00
|
|
|
it('should NOT be able to call eval() in any window', function() {
|
2016-07-22 14:03:03 -07:00
|
|
|
env.addClientCommands(this.app.client);
|
2016-08-08 07:56:21 -07:00
|
|
|
const tryEval = (index) => {
|
|
|
|
return this.app.client
|
|
|
|
.windowByIndex(index)
|
|
|
|
.execute(function() {
|
|
|
|
return eval('1 + 1');
|
|
|
|
}).should.eventually.be.rejected;
|
|
|
|
};
|
|
|
|
const tryEvalInSettingsPage = () => {
|
|
|
|
return this.app.client
|
|
|
|
.windowByIndex(0)
|
|
|
|
.loadSettingsPage()
|
|
|
|
.execute(function() {
|
|
|
|
return eval('1 + 1');
|
|
|
|
}).should.eventually.be.rejected;
|
|
|
|
};
|
|
|
|
return Promise.all([
|
|
|
|
tryEval(0),
|
|
|
|
tryEval(1),
|
|
|
|
tryEval(2),
|
|
|
|
tryEvalInSettingsPage()
|
|
|
|
]);
|
2016-07-22 14:03:03 -07:00
|
|
|
});
|
2016-06-25 01:53:02 -07:00
|
|
|
});
|