Skip to content

Commit 0198d5c

Browse files
committed
Add Autobahn testing non-SSL and SSL
1 parent ba73b88 commit 0198d5c

3 files changed

Lines changed: 93 additions & 0 deletions

File tree

‎tests/Autobahn.js‎

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
/* Test server for autobahn, run with ASAN. /exit route shuts down. */
2+
3+
const uWS = require('../dist/uws.js');
4+
let listenSocket, listenSocketSSL;
5+
6+
/* todo: A good idea is to test compression 1 for non-SSL and 2 for SSL */
7+
/* or really just test more than twice */
8+
9+
/* Shared, among SSL and non-SSL, behavior of WebSockets */
10+
const wsBehavior = {
11+
/* Options */
12+
compression: 2,
13+
maxPayloadLength: 16 * 1024 * 1024,
14+
idleTimeout: 60,
15+
/* Handlers */
16+
open: (ws, req) => {
17+
console.log('A WebSocket connected via URL: ' + req.getUrl() + '!');
18+
},
19+
message: (ws, message, isBinary) => {
20+
ws.send(message, isBinary);
21+
},
22+
drain: (ws) => {
23+
console.log('WebSocket backpressure: ' + ws.getBufferedAmount());
24+
},
25+
close: (ws, code, message) => {
26+
console.log('WebSocket closed');
27+
}
28+
};
29+
30+
/* The SSL test server is on port 9002 */
31+
const sslApp = uWS.SSLApp({
32+
key_file_name: 'misc/key.pem',
33+
cert_file_name: 'misc/cert.pem',
34+
passphrase: '1234'
35+
}).ws('/*', wsBehavior).any('/exit', (res, req) => {
36+
/* Stop listening on both SSL and non-SSL */
37+
if (listenSocket) {
38+
uWS.us_listen_socket_close(listenSocket);
39+
uWS.us_listen_socket_close(listenSocketSSL);
40+
listenSocket = null;
41+
}
42+
43+
/* Close this connection */
44+
res.close();
45+
}).listen(9002, (token) => {
46+
if (token) {
47+
listenSocketSSL = token;
48+
console.log('SSL test server is up...');
49+
}
50+
});
51+
52+
/* The non-SSL test server is on port 9001 */
53+
const app = uWS.App().ws('/*', wsBehavior).any('/exit', (res, req) => {
54+
/* Stop listening on both SSL and non-SSL */
55+
if (listenSocket) {
56+
uWS.us_listen_socket_close(listenSocket);
57+
uWS.us_listen_socket_close(listenSocketSSL);
58+
listenSocket = null;
59+
}
60+
61+
/* Close this connection */
62+
res.close();
63+
}).listen(9001, (token) => {
64+
if (token) {
65+
listenSocket = token;
66+
console.log('Non-SSL test server is up...');
67+
}
68+
});
69+
70+
/* This is required to check for memory leaks */
71+
process.on('beforeExit', () => {
72+
app.forcefully_free();
73+
sslApp.forcefully_free();
74+
});

‎tests/Makefile‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
default:
2+
wstest -m fuzzingclient

‎tests/fuzzingclient.json‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
2+
{
3+
"outdir": "./reports/servers",
4+
"servers": [
5+
{
6+
"url": "ws://localhost:9001",
7+
"agent": "uWebSockets.js non-SSL, compression 2"
8+
},
9+
{
10+
"url": "wss://localhost:9002",
11+
"agent": "uWebSockets.js SSL, compression 2"
12+
}
13+
],
14+
"cases": ["*.*"],
15+
"exclude-cases": [],
16+
"exclude-agent-cases": {}
17+
}

0 commit comments

Comments
 (0)