Skip to content

Commit

Permalink
this now resides in new wstest tool
Browse files Browse the repository at this point in the history
  • Loading branch information
Tobias Oberstein committed Mar 12, 2012
1 parent 714d92c commit 4bd182b
Show file tree
Hide file tree
Showing 8 changed files with 282 additions and 10 deletions.
10 changes: 5 additions & 5 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
*.pyc
*.pyo
*.dat
/lib/python/build/*
/lib/python/dist/*
/lib/python/autobahn.egg-info*/
testsuite/websockets/reports/*
doc/python/_build/*
/autobahn/build/*
/autobahn/dist/*
/autobahn/autobahn.egg-info*/
examples/fuzzing/reports/*
doc/python/_build/*
3 changes: 3 additions & 0 deletions autobahn/MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
include README
include LICENSE
include NOTICE
recursive-include autobahn *
recursive-include wstest/web *
1 change: 1 addition & 0 deletions autobahn/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
install_requires = ['setuptools', 'Twisted>=11.0'],
packages = find_packages(),
#packages = ['autobahn', 'wstest'],
include_package_data = True,
zip_safe = False,
entry_points = {
'console_scripts': [
Expand Down
20 changes: 20 additions & 0 deletions autobahn/wstest/web/fuzzingserver/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<!DOCTYPE html>
<html>
<head>
<style lang="css">
body {
font-family: Segoe UI,Tahoma,Arial,Verdana,sans-serif;
color: #333;
}
li {
padding: 0.4em;
}
</style>
</head>
<body>
<h1>Autobahn WebSockets Test Suite</h1>
<ul>
<li><a href="test_browser.html">Test your browser</a></li>
</ul>
</body>
</html>
247 changes: 247 additions & 0 deletions autobahn/wstest/web/fuzzingserver/test_browser.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,247 @@
<!DOCTYPE html>
<html>
<head>

<style lang="css">
body
{
font-family: Segoe UI,Tahoma,Arial,Verdana,sans-serif;
color: #333;
}
</style>

<script type="text/javascript">

var hostname = null;
var port = null;
var agent = null;
var ua = null;
var webSocket = null;
var currentCaseId = null;
var caseCount = null;

window.onload =
function()
{
setHostname();
setPort();
setAgent();
}

function setHostname()
{
var hn = window.location.hostname;
if (hn == null || hn == "") {
hn = "127.0.0.1";
}

hostname = document.getElementById('hostname').value;
if (hostname == null || hostname == "")
{
hostname = hn;
document.getElementById('hostname').value = hn;
}
}

function setPort()
{
port = document.getElementById('port').value;

if (port == null || port == "")
{
port = "9001";
document.getElementById('port').value = port;
}
}

function setAgent()
{
agent = document.getElementById('agent').value;
ua = navigator.userAgent;
document.getElementById('ua-detected').innerHTML = ua;

if (agent == null || agent == "")
{
console.log("user agent = " + ua);
if (ua.indexOf("Chrome") > -1)
{
i = ua.indexOf("Chrome");
j = ua.indexOf(" ", i);
agent = ua.slice(i, j);
updateStatus("Detected user agent " + agent + ".");
}
else if (ua.indexOf("Firefox") > -1)
{
i = ua.indexOf("Firefox");
j = ua.indexOf(" ", i);
if (j < i) j = ua.length;
s1 = ua.slice(i, j);
console.log(s1);
i = ua.indexOf("Gecko/");
j = ua.indexOf(" ", i);
s2 = ua.slice(i + "Gecko/".length, j).trim();
if (s2 != "") {
agent = s1 + "-" + s2;
} else {
agent = s1;
}
updateStatus("Detected user agent " + agent + ".");
}
else if (ua.indexOf("Safari") > -1)
{
i = ua.indexOf("Safari");
j = ua.indexOf(" ", i);
if (j < 0) j = ua.length;
agent = ua.slice(i, j);
updateStatus("Detected user agent " + agent + ".");
}
else if (ua.indexOf("MSIE") > -1)
{
i = ua.indexOf("MSIE");
j = ua.indexOf(";", i);
if (j < 0) j = ua.length;
agent = ua.slice(i, j);
updateStatus("Detected user agent " + agent + ".");
}
else
{
agent = "unknown";
updateStatus("Could not detect user agent .. will use '" + agent + "'.");
}

document.getElementById('agent').value = agent;
}
}

function startTestRun()
{
setHostname();
setPort();
setAgent();
updateStatus("Running test suite ..");
document.getElementById('resultlink').innerHTML = '';
currentCaseId = 1;
getCaseCount(runNextCase);
}

function updateStatus(msg)
{
console.log(msg);
document.getElementById('statusline').innerHTML = msg;
}

function openWebSocket(ws_uri)
{
if ("WebSocket" in window) {
// Chrome, IE10
webSocket = new WebSocket(ws_uri);
} else if ("MozWebSocket" in window) {
// Firefox 7-10 (currently vendor prefixed)
webSocket = new MozWebSocket(ws_uri);
} else {
throw "neither WebSocket nor MozWebSocket available";
}
return webSocket;
}

function getCaseCount(cont)
{
var ws_uri = "ws://" + hostname + ":" + port + "/getCaseCount";

webSocket = openWebSocket(ws_uri);

webSocket.onmessage =
function(e)
{
caseCount = JSON.parse(e.data);
updateStatus("Will run " + caseCount + " cases ..");
}

webSocket.onclose =
function(e)
{
cont();
}
}

function updateReports()
{
var ws_uri = "ws://" + hostname + ":" + port + "/updateReports?agent=" + agent;

webSocket = openWebSocket(ws_uri);

webSocket.onopen =
function(e)
{
updateStatus("Updating reports ..");
}

webSocket.onclose =
function(e)
{
webSocket = null;
updateStatus("Reports updated.");
updateStatus("Test suite finished!");

/*document.getElementById('resultlink').innerHTML = '<a href="../reports/clients/index.html">Check test report</a>';*/
}
}

function runNextCase()
{
var ws_uri = "ws://" + hostname + ":" + port + "/runCase?case=" + currentCaseId + "&agent=" + agent;

webSocket = openWebSocket(ws_uri);
webSocket.binaryType = "arraybuffer";

webSocket.onopen =
function(e)
{
updateStatus("Executing test case " + currentCaseId + "/" + caseCount);
}

webSocket.onclose =
function(e)
{
webSocket = null;

currentCaseId = currentCaseId + 1;
if (currentCaseId <= caseCount)
{
runNextCase();
}
else
{
updateStatus("All test cases executed.");
updateReports();
}
}

//webSocket.onerror = webSocket.onclose;

webSocket.onmessage =
function(e)
{
webSocket.send(e.data);
}
}

</script>
</head>

<body>
<h1>WebSockets Browser Testsuite</h1>
<p>Provided by <a href="http://www.tavendo.de/autobahn">Autobahn</a> WebSockets.</p><br/>
<form>
<p>Fuzzing Server Hostname<br/><input id="hostname" type="text" size="20" maxlength="40"></p>
<p>Fuzzing Server Port<br/><input id="port" type="text" size="5" maxlength="5"></p>
<p>User Agent Identifier<br/><input id="agent" type="text" size="30" maxlength="30"><br/>
<span style="font-size: 0.7em;" id="ua-detected"></span></p>
</form>
<br/>
<p><button onclick='startTestRun();'>Start Tests</button> &nbsp;&nbsp; <i>Status:</i> <span id="statusline">Ready</span></p>
<p><button onclick='updateReports();'>Update Reports (Manual)</button></p>
<br/>
<p id="resultlink"></p>
</body>
</html>
11 changes: 6 additions & 5 deletions autobahn/wstest/wstest.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
##
###############################################################################

import sys, json
import sys, os, json, pkg_resources

from twisted.python import log, usage
from twisted.internet import reactor
Expand Down Expand Up @@ -132,11 +132,12 @@ def run():
spec = str(o.opts['spec'])
spec = json.loads(open(spec).read())

webdir = File(spec.get("webdir", "."))
web = Site(webdir)
reactor.listenTCP(spec.get("webport", 9090), web)

if mode == 'fuzzingserver':

webdir = File(pkg_resources.resource_filename("wstest", "web/fuzzingserver"))
web = Site(webdir)
reactor.listenTCP(spec.get("webport", 9090), web)

factory = FuzzingServerFactory(spec)
listenWS(factory, createWssContext(o, factory))

Expand Down
File renamed without changes.
File renamed without changes.

0 comments on commit 4bd182b

Please sign in to comment.