Skip to content

Commit 72d1b0f

Browse files
committed
update tests
1 parent 96e812d commit 72d1b0f

File tree

6 files changed

+59
-12
lines changed

6 files changed

+59
-12
lines changed

autobahn/config/functional.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{
22
"url": "ws://127.0.0.1:9001",
3+
"servers": [{"agent": "ws_server.zig", "url": "ws://localhost:9002", "options": {"version": 18}}],
34
"outdir": "./reports/clients",
45
"cases": [
56
"*"
@@ -11,4 +12,4 @@
1112
"13.*"
1213
],
1314
"exclude-agent-cases": {}
14-
}
15+
}
+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"servers": [{"agent": "ws_server.zig", "url": "ws://localhost:9002", "options": {"version": 18}}],
3+
"outdir": "./reports/servers",
4+
"cases": [
5+
"*"
6+
],
7+
"exclude-cases": [
8+
"6.4.*",
9+
"9.*",
10+
"12.*",
11+
"13.*"
12+
],
13+
"exclude-agent-cases": {}
14+
}

autobahn/start.sh

+9-1
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,22 @@
11
#!/bin/bash -e
22

33
podman stop fuzzingserver || true
4+
podman stop fuzzingclient || true
45

56
mkdir -p reports/clients
67

7-
podman run -it --rm \
8+
podman run -d --rm \
89
-v "${PWD}/config:/config" \
910
-v "${PWD}/reports:/reports" \
1011
--name fuzzingserver \
1112
-p 9001:9001 \
1213
-p 8080:8080 \
1314
crossbario/autobahn-testsuite:0.8.2 \
1415
wstest --mode fuzzingserver --spec /config/functional.json
16+
17+
podman run -d --rm --network=host \
18+
-v "${PWD}/config:/config" \
19+
-v "${PWD}/reports:/reports" \
20+
--name fuzzingclient \
21+
crossbario/autobahn-testsuite:0.8.2 \
22+
wstest --mode fuzzingclient --spec /config/functional_server.json

run_iox_tests.sh

+13
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,23 @@ cd ../iox/
44
zig build #-freference-trace #-Doptimize=ReleaseFast
55
cd -
66

7+
killall ws_echo_server || true
8+
../iox/zig-out/bin/ws_echo_server &
9+
server_pid=$!
10+
11+
cd autobahn/
12+
./start.sh
13+
cd -
14+
15+
sleep 1
16+
717
url=ws://localhost:9001
818
msgs=$(websocat "$url/getCaseCount" -E --jsonrpc)
919

1020
../iox/zig-out/bin/ws_autobahn_client "$msgs"
1121
websocat "$url/updateReports?agent=dummy" -E
1222

1323
open $(pwd)/autobahn/reports/clients/index.html
24+
open $(pwd)/autobahn/reports/servers/index.html
25+
26+
kill $server_pid

src/async.zig

+10-8
Original file line numberDiff line numberDiff line change
@@ -291,26 +291,28 @@ pub fn Conn(comptime Handler: type) type {
291291
test "async" {
292292
const Handler = struct {
293293
const Self = @This();
294-
control_frames: usize = 0,
294+
sent_frames: usize = 0,
295295
messages: usize = 0,
296-
pub fn onControlFrame(self: *Self, frm: Frame) !void {
297-
_ = frm;
298-
self.control_frames += 1;
299-
}
296+
300297
pub fn onRecv(self: *Self, msg: Msg) void {
301298
testing.expectEqual(msg.encoding, .text) catch unreachable;
302299
testing.expectEqualSlices(u8, &[_]u8{ 10, 11, 12, 13, 14, 15 }, msg.data) catch unreachable;
303300
self.messages += 1;
304301
}
305-
pub fn sendZc(_: *Self, _: []const u8) !void {}
302+
pub fn sendZc(self: *Self, buf: []const u8) !void {
303+
const pong_frame = [_]u8{ 0x8a, 0x80, 0xdf, 0x23, 0xb, 0x49 };
304+
self.sent_frames += 1;
305+
testing.expectEqualSlices(u8, &pong_frame, buf) catch unreachable;
306+
testing.allocator.free(buf);
307+
}
306308
};
307309
var handler: Handler = .{};
308310

309-
var conn = Conn(Handler).init(testing.allocator, &handler);
311+
var conn = Conn(Handler){ .allocator = testing.allocator, .handler = &handler, .mask = 1 };
310312
defer conn.deinit();
311313
const n = try conn.recv(@constCast(&fixture_fragmented_message));
312314
try testing.expectEqual(16, n);
313-
try testing.expectEqual(2, handler.control_frames);
315+
try testing.expectEqual(1, handler.sent_frames);
314316
try testing.expectEqual(1, handler.messages);
315317
}
316318

src/handshake.zig

+11-2
Original file line numberDiff line numberDiff line change
@@ -423,6 +423,10 @@ pub const Rsp = struct {
423423
try testing.expect(!r.options.client_no_context_takeover);
424424
try testing.expectEqual(12, r.options.server_max_window_bits);
425425
try testing.expectEqual(13, r.options.client_max_window_bits);
426+
427+
for (0..bytes.len - 10) |i| {
428+
try testing.expectError(error.SplitBuffer, Rsp.parse(bytes[0..i]));
429+
}
426430
}
427431
};
428432

@@ -539,13 +543,18 @@ pub const Req = struct {
539543
"Connection: Upgrade\r\n" ++
540544
"Sec-WebSocket-Key: 3yMLSWFdF1MH1YDDPW/aYQ==\r\n" ++
541545
"Sec-WebSocket-Version: 13\r\n" ++
542-
"Sec-WebSocket-Extensions: permessage-deflate\r\n\r\n";
543-
const r = try Req.parse(bytes);
546+
"Sec-WebSocket-Extensions: permessage-deflate\r\n\r\n" ++ "0123456789";
547+
const r, const n = try Req.parse(bytes);
548+
try testing.expectEqual(bytes.len - 10, n);
544549
try testing.expectEqualStrings("ws.example.com", r.host);
545550
try testing.expectEqualStrings("ws://ws.example.com/ws", r.target);
546551
try testing.expectEqualStrings("3yMLSWFdF1MH1YDDPW/aYQ==", r.key);
547552
try testing.expectEqualStrings("13", r.version);
548553
try testing.expectEqualStrings("permessage-deflate", r.extensions);
554+
555+
for (0..bytes.len - 10) |i| {
556+
try testing.expectError(error.SplitBuffer, Req.parse(bytes[0..i]));
557+
}
549558
}
550559
};
551560

0 commit comments

Comments
 (0)