Software /
code /
prosody
Annotate
spec/net_websocket_frames_spec.lua @ 10692:a0480ee2233a
README: Update link to web chat
At some point the web chat moved to /chat and then to this subdomain
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Sun, 15 Mar 2020 20:35:07 +0100 |
parent | 10584:0c464bb7eb03 |
child | 11166:51e5149ed0ad |
rev | line source |
---|---|
9660
7e75c348095b
net.websocket.frames: Add some brief tests
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
1 describe("net.websocket.frames", function () |
7e75c348095b
net.websocket.frames: Add some brief tests
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
2 local nwf = require "net.websocket.frames"; |
7e75c348095b
net.websocket.frames: Add some brief tests
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
3 |
7e75c348095b
net.websocket.frames: Add some brief tests
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
4 local test_frames = { |
7e75c348095b
net.websocket.frames: Add some brief tests
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
5 simple_empty = { |
7e75c348095b
net.websocket.frames: Add some brief tests
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
6 ["opcode"] = 0; |
7e75c348095b
net.websocket.frames: Add some brief tests
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
7 ["length"] = 0; |
7e75c348095b
net.websocket.frames: Add some brief tests
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
8 ["data"] = ""; |
7e75c348095b
net.websocket.frames: Add some brief tests
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
9 ["FIN"] = false; |
7e75c348095b
net.websocket.frames: Add some brief tests
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
10 ["MASK"] = false; |
7e75c348095b
net.websocket.frames: Add some brief tests
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
11 ["RSV1"] = false; |
7e75c348095b
net.websocket.frames: Add some brief tests
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
12 ["RSV2"] = false; |
7e75c348095b
net.websocket.frames: Add some brief tests
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
13 ["RSV3"] = false; |
7e75c348095b
net.websocket.frames: Add some brief tests
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
14 }; |
7e75c348095b
net.websocket.frames: Add some brief tests
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
15 simple_data = { |
7e75c348095b
net.websocket.frames: Add some brief tests
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
16 ["opcode"] = 0; |
7e75c348095b
net.websocket.frames: Add some brief tests
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
17 ["length"] = 5; |
7e75c348095b
net.websocket.frames: Add some brief tests
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
18 ["data"] = "hello"; |
7e75c348095b
net.websocket.frames: Add some brief tests
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
19 ["FIN"] = false; |
7e75c348095b
net.websocket.frames: Add some brief tests
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
20 ["MASK"] = false; |
7e75c348095b
net.websocket.frames: Add some brief tests
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
21 ["RSV1"] = false; |
7e75c348095b
net.websocket.frames: Add some brief tests
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
22 ["RSV2"] = false; |
7e75c348095b
net.websocket.frames: Add some brief tests
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
23 ["RSV3"] = false; |
7e75c348095b
net.websocket.frames: Add some brief tests
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
24 }; |
7e75c348095b
net.websocket.frames: Add some brief tests
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
25 simple_fin = { |
7e75c348095b
net.websocket.frames: Add some brief tests
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
26 ["opcode"] = 0; |
7e75c348095b
net.websocket.frames: Add some brief tests
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
27 ["length"] = 0; |
7e75c348095b
net.websocket.frames: Add some brief tests
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
28 ["data"] = ""; |
7e75c348095b
net.websocket.frames: Add some brief tests
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
29 ["FIN"] = true; |
7e75c348095b
net.websocket.frames: Add some brief tests
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
30 ["MASK"] = false; |
7e75c348095b
net.websocket.frames: Add some brief tests
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
31 ["RSV1"] = false; |
7e75c348095b
net.websocket.frames: Add some brief tests
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
32 ["RSV2"] = false; |
7e75c348095b
net.websocket.frames: Add some brief tests
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
33 ["RSV3"] = false; |
7e75c348095b
net.websocket.frames: Add some brief tests
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
34 }; |
10583
624ad69dbaf7
net.websocket.frames: Add test case for masked data
Kim Alvefur <zash@zash.se>
parents:
9660
diff
changeset
|
35 masked_data = { |
624ad69dbaf7
net.websocket.frames: Add test case for masked data
Kim Alvefur <zash@zash.se>
parents:
9660
diff
changeset
|
36 ["opcode"] = 0; |
624ad69dbaf7
net.websocket.frames: Add test case for masked data
Kim Alvefur <zash@zash.se>
parents:
9660
diff
changeset
|
37 ["length"] = 5; |
624ad69dbaf7
net.websocket.frames: Add test case for masked data
Kim Alvefur <zash@zash.se>
parents:
9660
diff
changeset
|
38 ["data"] = "hello"; |
624ad69dbaf7
net.websocket.frames: Add test case for masked data
Kim Alvefur <zash@zash.se>
parents:
9660
diff
changeset
|
39 ["FIN"] = true; |
624ad69dbaf7
net.websocket.frames: Add test case for masked data
Kim Alvefur <zash@zash.se>
parents:
9660
diff
changeset
|
40 ["MASK"] = true; |
624ad69dbaf7
net.websocket.frames: Add test case for masked data
Kim Alvefur <zash@zash.se>
parents:
9660
diff
changeset
|
41 ["RSV1"] = false; |
624ad69dbaf7
net.websocket.frames: Add test case for masked data
Kim Alvefur <zash@zash.se>
parents:
9660
diff
changeset
|
42 ["RSV2"] = false; |
624ad69dbaf7
net.websocket.frames: Add test case for masked data
Kim Alvefur <zash@zash.se>
parents:
9660
diff
changeset
|
43 ["RSV3"] = false; |
624ad69dbaf7
net.websocket.frames: Add test case for masked data
Kim Alvefur <zash@zash.se>
parents:
9660
diff
changeset
|
44 ["key"] = { 0x20, 0x20, 0x20, 0x20, }; |
624ad69dbaf7
net.websocket.frames: Add test case for masked data
Kim Alvefur <zash@zash.se>
parents:
9660
diff
changeset
|
45 }; |
10584
0c464bb7eb03
net.websocket.frames: Add ping and pong test cases
Kim Alvefur <zash@zash.se>
parents:
10583
diff
changeset
|
46 ping = { |
0c464bb7eb03
net.websocket.frames: Add ping and pong test cases
Kim Alvefur <zash@zash.se>
parents:
10583
diff
changeset
|
47 ["opcode"] = 0x9; |
0c464bb7eb03
net.websocket.frames: Add ping and pong test cases
Kim Alvefur <zash@zash.se>
parents:
10583
diff
changeset
|
48 ["length"] = 4; |
0c464bb7eb03
net.websocket.frames: Add ping and pong test cases
Kim Alvefur <zash@zash.se>
parents:
10583
diff
changeset
|
49 ["data"] = "ping"; |
0c464bb7eb03
net.websocket.frames: Add ping and pong test cases
Kim Alvefur <zash@zash.se>
parents:
10583
diff
changeset
|
50 ["FIN"] = true; |
0c464bb7eb03
net.websocket.frames: Add ping and pong test cases
Kim Alvefur <zash@zash.se>
parents:
10583
diff
changeset
|
51 ["MASK"] = false; |
0c464bb7eb03
net.websocket.frames: Add ping and pong test cases
Kim Alvefur <zash@zash.se>
parents:
10583
diff
changeset
|
52 ["RSV1"] = false; |
0c464bb7eb03
net.websocket.frames: Add ping and pong test cases
Kim Alvefur <zash@zash.se>
parents:
10583
diff
changeset
|
53 ["RSV2"] = false; |
0c464bb7eb03
net.websocket.frames: Add ping and pong test cases
Kim Alvefur <zash@zash.se>
parents:
10583
diff
changeset
|
54 ["RSV3"] = false; |
0c464bb7eb03
net.websocket.frames: Add ping and pong test cases
Kim Alvefur <zash@zash.se>
parents:
10583
diff
changeset
|
55 }; |
0c464bb7eb03
net.websocket.frames: Add ping and pong test cases
Kim Alvefur <zash@zash.se>
parents:
10583
diff
changeset
|
56 pong = { |
0c464bb7eb03
net.websocket.frames: Add ping and pong test cases
Kim Alvefur <zash@zash.se>
parents:
10583
diff
changeset
|
57 ["opcode"] = 0xa; |
0c464bb7eb03
net.websocket.frames: Add ping and pong test cases
Kim Alvefur <zash@zash.se>
parents:
10583
diff
changeset
|
58 ["length"] = 4; |
0c464bb7eb03
net.websocket.frames: Add ping and pong test cases
Kim Alvefur <zash@zash.se>
parents:
10583
diff
changeset
|
59 ["data"] = "pong"; |
0c464bb7eb03
net.websocket.frames: Add ping and pong test cases
Kim Alvefur <zash@zash.se>
parents:
10583
diff
changeset
|
60 ["FIN"] = true; |
0c464bb7eb03
net.websocket.frames: Add ping and pong test cases
Kim Alvefur <zash@zash.se>
parents:
10583
diff
changeset
|
61 ["MASK"] = false; |
0c464bb7eb03
net.websocket.frames: Add ping and pong test cases
Kim Alvefur <zash@zash.se>
parents:
10583
diff
changeset
|
62 ["RSV1"] = false; |
0c464bb7eb03
net.websocket.frames: Add ping and pong test cases
Kim Alvefur <zash@zash.se>
parents:
10583
diff
changeset
|
63 ["RSV2"] = false; |
0c464bb7eb03
net.websocket.frames: Add ping and pong test cases
Kim Alvefur <zash@zash.se>
parents:
10583
diff
changeset
|
64 ["RSV3"] = false; |
0c464bb7eb03
net.websocket.frames: Add ping and pong test cases
Kim Alvefur <zash@zash.se>
parents:
10583
diff
changeset
|
65 }; |
9660
7e75c348095b
net.websocket.frames: Add some brief tests
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
66 } |
7e75c348095b
net.websocket.frames: Add some brief tests
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
67 |
7e75c348095b
net.websocket.frames: Add some brief tests
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
68 describe("build", function () |
7e75c348095b
net.websocket.frames: Add some brief tests
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
69 local build = nwf.build; |
7e75c348095b
net.websocket.frames: Add some brief tests
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
70 it("works", function () |
7e75c348095b
net.websocket.frames: Add some brief tests
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
71 assert.equal("\0\0", build(test_frames.simple_empty)); |
7e75c348095b
net.websocket.frames: Add some brief tests
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
72 assert.equal("\0\5hello", build(test_frames.simple_data)); |
7e75c348095b
net.websocket.frames: Add some brief tests
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
73 assert.equal("\128\0", build(test_frames.simple_fin)); |
10583
624ad69dbaf7
net.websocket.frames: Add test case for masked data
Kim Alvefur <zash@zash.se>
parents:
9660
diff
changeset
|
74 assert.equal("\128\133 HELLO", build(test_frames.masked_data)); |
10584
0c464bb7eb03
net.websocket.frames: Add ping and pong test cases
Kim Alvefur <zash@zash.se>
parents:
10583
diff
changeset
|
75 assert.equal("\137\4ping", build(test_frames.ping)); |
0c464bb7eb03
net.websocket.frames: Add ping and pong test cases
Kim Alvefur <zash@zash.se>
parents:
10583
diff
changeset
|
76 assert.equal("\138\4pong", build(test_frames.pong)); |
9660
7e75c348095b
net.websocket.frames: Add some brief tests
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
77 end); |
7e75c348095b
net.websocket.frames: Add some brief tests
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
78 end); |
7e75c348095b
net.websocket.frames: Add some brief tests
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
79 |
7e75c348095b
net.websocket.frames: Add some brief tests
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
80 describe("parse", function () |
7e75c348095b
net.websocket.frames: Add some brief tests
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
81 local parse = nwf.parse; |
7e75c348095b
net.websocket.frames: Add some brief tests
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
82 it("works", function () |
7e75c348095b
net.websocket.frames: Add some brief tests
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
83 assert.same(test_frames.simple_empty, parse("\0\0")); |
7e75c348095b
net.websocket.frames: Add some brief tests
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
84 assert.same(test_frames.simple_data, parse("\0\5hello")); |
7e75c348095b
net.websocket.frames: Add some brief tests
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
85 assert.same(test_frames.simple_fin, parse("\128\0")); |
10583
624ad69dbaf7
net.websocket.frames: Add test case for masked data
Kim Alvefur <zash@zash.se>
parents:
9660
diff
changeset
|
86 assert.same(test_frames.masked_data, parse("\128\133 HELLO")); |
10584
0c464bb7eb03
net.websocket.frames: Add ping and pong test cases
Kim Alvefur <zash@zash.se>
parents:
10583
diff
changeset
|
87 assert.same(test_frames.ping, parse("\137\4ping")); |
0c464bb7eb03
net.websocket.frames: Add ping and pong test cases
Kim Alvefur <zash@zash.se>
parents:
10583
diff
changeset
|
88 assert.same(test_frames.pong, parse("\138\4pong")); |
9660
7e75c348095b
net.websocket.frames: Add some brief tests
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
89 end); |
7e75c348095b
net.websocket.frames: Add some brief tests
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
90 end); |
7e75c348095b
net.websocket.frames: Add some brief tests
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
91 |
7e75c348095b
net.websocket.frames: Add some brief tests
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
92 end); |
7e75c348095b
net.websocket.frames: Add some brief tests
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
93 |