Skip to content

Commit

Permalink
update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
sereneblue committed Apr 6, 2019
1 parent 0915bbf commit b7ac837
Show file tree
Hide file tree
Showing 6 changed files with 85 additions and 21 deletions.
19 changes: 16 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,8 @@
"mocha": "^5.2.0",
"moment-timezone": "^0.5.23",
"selenium-webdriver": "^4.0.0-alpha.1"
},
"dependencies": {
"ws": "^6.2.1"
}
}
11 changes: 11 additions & 0 deletions test/injection/index.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
<body>
<a id="link" href="/">Click me!</a>
<a id="link2" href="#" onclick="windowTest();">Window Name Test</a>
<p id="websocket"></p>
<p id="offset"><script>document.write(new Date().getTimezoneOffset());</script></p>
<h1 id="client_rect">Lorem ipsum.</h1>
<h3>Fingerprint using DynamicsCompressor (sum of buffer values):</h3>
Expand Down Expand Up @@ -148,5 +149,15 @@
run_cc_fp();
run_hybrid_fp();
}
function wss() {
const socket = new WebSocket('ws://localhost:3002');
// Connection opened
socket.addEventListener('open', function (event) {
document.querySelector('#websocket').innerHTML = "OPEN";
});
}
wss();
</script>
</html>
41 changes: 32 additions & 9 deletions test/injection/scriptInjectionTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@ const { Builder, By } = require('selenium-webdriver');
const firefox = require('selenium-webdriver/firefox');

const expect = require('chai').expect
const express = require('express')
const path = require('path')
const express = require('express');
const path = require('path');
const moment = require('moment-timezone');
const app = express()
const app = express();
const WebSocket = require('ws');

const wss = new WebSocket.Server({ port: 3002 });

const screenResolutions = [
"1366x768",
Expand Down Expand Up @@ -159,22 +162,42 @@ describe('Script Injection', () => {
await driver.quit();
server.close();
cors_server.close();
wss.close();
});

it('should enable script injection', async () => {
await selectOption('input[name="enableScriptInjection"]');
});

it('should disable websockets', async () => {
selectOption('input[name="disableWebSockets"]');

it('should disable websockets - block all', async () => {
await driver.executeScript(`
var el = document.querySelector('select[name="webSockets"]');
el.value = "allow_all";
el.dispatchEvent(new Event('change'));
`);
await wait(SLEEP_TIME);

await driver.get(LOCALSERVER);
await wait(SLEEP_TIME * 2);
let socketStatus = await driver.executeScript(`
return document.querySelector('#websocket').innerHTML;
`);

expect(socketStatus).to.equal("OPEN");

await driver.get(EXTENSION_URI);
await driver.executeScript(`
var el = document.querySelector('select[name="webSockets"]');
el.value = "block_all";
el.dispatchEvent(new Event('change'));
`);
await driver.get(LOCALSERVER);
hasWebsocket = await driver.executeScript(`
return WebSocket ? true : false;
await wait(SLEEP_TIME * 2);
socketStatus = await driver.executeScript(`
return document.querySelector('#websocket').innerHTML;
`);

expect(hasWebsocket).to.equal(false);
expect(socketStatus).to.equal("");
});

it('should limit tab history', async () => {
Expand Down
11 changes: 11 additions & 0 deletions test/whitelist/index.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,21 @@
<a id="link" href="/">Referer test - Click me!</a>
<a id="link2" onclick="windowTest();">Window Name Test</a>
<p id="offset"><script>document.write(new Date().getTimezoneOffset());</script></p>
<p id="websocket"></p>
</body>
<script>
function windowTest() {
window.open('/whitelist_test', 'unique_name');
}
function wss() {
const socket = new WebSocket('ws://localhost:3002');
// Connection opened
socket.addEventListener('open', function (event) {
document.querySelector('#websocket').innerHTML = "OPEN";
});
}
wss();
</script>
</html>
21 changes: 12 additions & 9 deletions test/whitelist/whitelistTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@ const { Builder, By } = require('selenium-webdriver');
const firefox = require('selenium-webdriver/firefox');

const expect = require('chai').expect
const express = require('express')
const path = require('path')
const app = express()
const auth = require('http-auth')
const browserData = require('../../src/js/data.js')
const express = require('express');
const path = require('path');
const app = express();
const WebSocket = require('ws');
const wss = new WebSocket.Server({ port: 3002 });
const auth = require('http-auth');
const browserData = require('../../src/js/data.js');

var authMiddleware = auth.connect(auth.basic({ realm: 'SECRET LAIR'}, (username, password, callback) => {
callback(username == 'username' && password == 'password');
Expand Down Expand Up @@ -106,6 +108,7 @@ describe('Whitelist', () => {
after(async () => {
await driver.quit();
server.close();
wss.close();
});

it('should enable whitelist', async () => {
Expand Down Expand Up @@ -282,13 +285,13 @@ describe('Whitelist', () => {
document.querySelectorAll('.card-header button')[1].click();
`);

await wait(SLEEP_TIME);
await driver.get(LOCALSERVER + "/whitelist_test");
hasWebsocket = await driver.executeScript(`
return WebSocket ? true : false;
await wait(SLEEP_TIME);
socketStatus = await driver.executeScript(`
return document.querySelector('#websocket').innerHTML;
`);

expect(hasWebsocket).to.equal(false);
expect(socketStatus).to.equal("");
});

it('should test whitelist option - protect window name', async () => {
Expand Down

0 comments on commit b7ac837

Please sign in to comment.