Add test to confirm Node.js is disabled in a new window

This commit is contained in:
Yuya Ochiai 2016-06-25 18:45:33 +09:00
parent b22c1eb2aa
commit 7fc963125a
2 changed files with 52 additions and 2 deletions

15
test/modules/test.html Normal file
View file

@ -0,0 +1,15 @@
<html>
<body>
<h1>window.open() test</h1>
<p>
<input type="button" value="window.open()" onclick="open_window()">
</p>
<script>
function open_window() {
window.open('./test.html');
}
</script>
</body>
</html>

View file

@ -2,21 +2,33 @@
const path = require('path'); const path = require('path');
const fs = require('fs'); const fs = require('fs');
const http = require('http');
const env = require('../modules/environment'); const env = require('../modules/environment');
describe('application', function() { describe('application', function() {
const serverPort = 8181;
const config = { const config = {
version: 1, version: 1,
teams: [{ teams: [{
name: 'example_1', name: 'example_1',
url: env.mattermostURL url: `http://localhost:${serverPort}`
}, { }, {
name: 'example_2', name: 'example_2',
url: env.mattermostURL url: `http://localhost:${serverPort}`
}] }]
}; };
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');
});
beforeEach(function() { beforeEach(function() {
fs.writeFileSync(env.configFilePath, JSON.stringify(config)); fs.writeFileSync(env.configFilePath, JSON.stringify(config));
this.app = env.getSpectronApp(); this.app = env.getSpectronApp();
@ -29,6 +41,10 @@ describe('application', function() {
} }
}); });
after(function(done) {
this.server.close(done);
})
it('should NOT be able to call Node.js API in webview', function() { it('should NOT be able to call Node.js API in webview', function() {
return this.app.client return this.app.client
// Ideally, need to confirm actual behavior in webview by executing require('electron'); // Ideally, need to confirm actual behavior in webview by executing require('electron');
@ -39,4 +55,23 @@ describe('application', function() {
}); });
}); });
}); });
it('should NOT be able to call Node.js API in a new window', function() {
return this.app.client
.execute(function() {
const webview = document.querySelector('webview');
webview.executeJavaScript('open_window();');
})
.windowByIndex(1)
.execute(function() {
try {
return require('fs') ? true : false;
}
catch (e) {
return false;
}
}).then((require_fs_result) => {
require_fs_result.value.should.be.false;
});
})
}); });