From c1fa798ae64085887a6e9c4578c3bd3381f1c9d1 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Wed, 14 Oct 2020 19:02:48 +0200 Subject: net.websocket.frames: Add small test covering xor-masking This is basically a recording of current behavior, to detect changes. --- spec/net_websocket_frames_spec.lua | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'spec/net_websocket_frames_spec.lua') diff --git a/spec/net_websocket_frames_spec.lua b/spec/net_websocket_frames_spec.lua index d4df3a54..9499cee7 100644 --- a/spec/net_websocket_frames_spec.lua +++ b/spec/net_websocket_frames_spec.lua @@ -32,6 +32,17 @@ describe("net.websocket.frames", function () ["RSV2"] = false; ["RSV3"] = false; }; + with_mask = { + ["opcode"] = 0; + ["length"] = 5; + ["data"] = "hello"; + ["key"] = { 32, 0, 32, 0, }; + ["FIN"] = true; + ["MASK"] = true; + ["RSV1"] = false; + ["RSV2"] = false; + ["RSV3"] = false; + }; } describe("build", function () @@ -40,6 +51,7 @@ describe("net.websocket.frames", function () assert.equal("\0\0", build(test_frames.simple_empty)); assert.equal("\0\5hello", build(test_frames.simple_data)); assert.equal("\128\0", build(test_frames.simple_fin)); + assert.equal("\128\133 \0 \0HeLlO", build(test_frames.with_mask)) end); end); @@ -49,6 +61,7 @@ describe("net.websocket.frames", function () assert.same(test_frames.simple_empty, parse("\0\0")); assert.same(test_frames.simple_data, parse("\0\5hello")); assert.same(test_frames.simple_fin, parse("\128\0")); + assert.same(test_frames.with_mask, parse("\128\133 \0 \0HeLlO")); end); end); -- cgit v1.2.3 From ca36c38a51401217183c8be4735b5566d14f3826 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Wed, 14 Oct 2020 19:41:42 +0200 Subject: net.websocket.frames: Use C string XOR implementation --- spec/net_websocket_frames_spec.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'spec/net_websocket_frames_spec.lua') diff --git a/spec/net_websocket_frames_spec.lua b/spec/net_websocket_frames_spec.lua index 9499cee7..244afa3b 100644 --- a/spec/net_websocket_frames_spec.lua +++ b/spec/net_websocket_frames_spec.lua @@ -36,7 +36,7 @@ describe("net.websocket.frames", function () ["opcode"] = 0; ["length"] = 5; ["data"] = "hello"; - ["key"] = { 32, 0, 32, 0, }; + ["key"] = " \0 \0"; ["FIN"] = true; ["MASK"] = true; ["RSV1"] = false; -- cgit v1.2.3 From 9a25dc6d776fb7e01d53036d353fa12c874a64c4 Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Thu, 15 Oct 2020 14:01:22 +0100 Subject: net.websocket.frames: Add test for empty frame with MASK and key set --- spec/net_websocket_frames_spec.lua | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'spec/net_websocket_frames_spec.lua') diff --git a/spec/net_websocket_frames_spec.lua b/spec/net_websocket_frames_spec.lua index 244afa3b..519be7b9 100644 --- a/spec/net_websocket_frames_spec.lua +++ b/spec/net_websocket_frames_spec.lua @@ -43,6 +43,15 @@ describe("net.websocket.frames", function () ["RSV2"] = false; ["RSV3"] = false; }; + empty_with_mask = { + ["opcode"] = 0; + ["key"] = " \0 \0"; + ["FIN"] = true; + ["MASK"] = true; + ["RSV1"] = false; + ["RSV2"] = false; + ["RSV3"] = false; + }; } describe("build", function () @@ -52,6 +61,7 @@ describe("net.websocket.frames", function () assert.equal("\0\5hello", build(test_frames.simple_data)); assert.equal("\128\0", build(test_frames.simple_fin)); assert.equal("\128\133 \0 \0HeLlO", build(test_frames.with_mask)) + assert.equal("\128\128 \0 \0", build(test_frames.empty_with_mask)) end); end); -- cgit v1.2.3