websocket 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +3 -0
- data/.travis.yml +11 -0
- data/CHANGELOG.md +5 -0
- data/Gemfile +5 -0
- data/README.md +117 -0
- data/Rakefile +23 -0
- data/autobahn-client.json +11 -0
- data/autobahn-server.json +10 -0
- data/examples/base.rb +162 -0
- data/examples/client.rb +70 -0
- data/examples/server.rb +56 -0
- data/examples/tests/autobahn_client.rb +52 -0
- data/examples/tests/echo_client.rb +42 -0
- data/examples/tests/echo_server.rb +45 -0
- data/lib/websocket.rb +16 -0
- data/lib/websocket/frame.rb +11 -0
- data/lib/websocket/frame/base.rb +45 -0
- data/lib/websocket/frame/data.rb +52 -0
- data/lib/websocket/frame/handler.rb +15 -0
- data/lib/websocket/frame/handler/base.rb +41 -0
- data/lib/websocket/frame/handler/handler03.rb +162 -0
- data/lib/websocket/frame/handler/handler04.rb +19 -0
- data/lib/websocket/frame/handler/handler05.rb +17 -0
- data/lib/websocket/frame/handler/handler07.rb +34 -0
- data/lib/websocket/frame/handler/handler75.rb +79 -0
- data/lib/websocket/frame/incoming.rb +43 -0
- data/lib/websocket/frame/incoming/client.rb +9 -0
- data/lib/websocket/frame/incoming/server.rb +9 -0
- data/lib/websocket/frame/outgoing.rb +28 -0
- data/lib/websocket/frame/outgoing/client.rb +9 -0
- data/lib/websocket/frame/outgoing/server.rb +9 -0
- data/lib/websocket/handshake.rb +10 -0
- data/lib/websocket/handshake/base.rb +67 -0
- data/lib/websocket/handshake/client.rb +80 -0
- data/lib/websocket/handshake/handler.rb +20 -0
- data/lib/websocket/handshake/handler/base.rb +25 -0
- data/lib/websocket/handshake/handler/client.rb +19 -0
- data/lib/websocket/handshake/handler/client01.rb +19 -0
- data/lib/websocket/handshake/handler/client04.rb +47 -0
- data/lib/websocket/handshake/handler/client75.rb +25 -0
- data/lib/websocket/handshake/handler/client76.rb +85 -0
- data/lib/websocket/handshake/handler/server.rb +30 -0
- data/lib/websocket/handshake/handler/server04.rb +38 -0
- data/lib/websocket/handshake/handler/server75.rb +26 -0
- data/lib/websocket/handshake/handler/server76.rb +71 -0
- data/lib/websocket/handshake/server.rb +56 -0
- data/lib/websocket/version.rb +3 -0
- data/spec/frame/incoming_03_spec.rb +117 -0
- data/spec/frame/incoming_04_spec.rb +117 -0
- data/spec/frame/incoming_05_spec.rb +133 -0
- data/spec/frame/incoming_07_spec.rb +133 -0
- data/spec/frame/incoming_75_spec.rb +59 -0
- data/spec/frame/incoming_common_spec.rb +22 -0
- data/spec/frame/outgoing_03_spec.rb +77 -0
- data/spec/frame/outgoing_04_spec.rb +77 -0
- data/spec/frame/outgoing_05_spec.rb +77 -0
- data/spec/frame/outgoing_07_spec.rb +77 -0
- data/spec/frame/outgoing_75_spec.rb +41 -0
- data/spec/frame/outgoing_common_spec.rb +15 -0
- data/spec/handshake/client_04_spec.rb +20 -0
- data/spec/handshake/client_75_spec.rb +11 -0
- data/spec/handshake/client_76_spec.rb +20 -0
- data/spec/handshake/server_04_spec.rb +18 -0
- data/spec/handshake/server_75_spec.rb +11 -0
- data/spec/handshake/server_76_spec.rb +46 -0
- data/spec/spec_helper.rb +4 -0
- data/spec/support/all_client_drafts.rb +77 -0
- data/spec/support/all_server_drafts.rb +86 -0
- data/spec/support/handshake_requests.rb +72 -0
- data/spec/support/incoming_frames.rb +30 -0
- data/spec/support/outgoing_frames.rb +14 -0
- data/websocket.gemspec +21 -0
- metadata +163 -0
@@ -0,0 +1,117 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe 'Incoming frame draft 03' do
|
4
|
+
let(:version) { 3 }
|
5
|
+
let(:frame) { WebSocket::Frame::Incoming.new(:version => version, :data => encoded_text) }
|
6
|
+
let(:encoded_text) { nil }
|
7
|
+
let(:decoded_text) { nil }
|
8
|
+
let(:frame_type) { nil }
|
9
|
+
let(:error) { nil }
|
10
|
+
subject { frame }
|
11
|
+
|
12
|
+
it_should_behave_like 'valid_incoming_frame'
|
13
|
+
|
14
|
+
context "should properly decode close frame" do
|
15
|
+
let(:encoded_text) { "\x01\x05" + decoded_text }
|
16
|
+
let(:frame_type) { :close }
|
17
|
+
let(:decoded_text) { "Hello" }
|
18
|
+
|
19
|
+
it_should_behave_like 'valid_incoming_frame'
|
20
|
+
end
|
21
|
+
|
22
|
+
context "should properly decode ping frame" do
|
23
|
+
let(:encoded_text) { "\x02\x05" + decoded_text }
|
24
|
+
let(:frame_type) { :ping }
|
25
|
+
let(:decoded_text) { "Hello" }
|
26
|
+
|
27
|
+
it_should_behave_like 'valid_incoming_frame'
|
28
|
+
end
|
29
|
+
|
30
|
+
context "should properly decode pong frame" do
|
31
|
+
let(:encoded_text) { "\x03\x05" + decoded_text }
|
32
|
+
let(:frame_type) { :pong }
|
33
|
+
let(:decoded_text) { "Hello" }
|
34
|
+
|
35
|
+
it_should_behave_like 'valid_incoming_frame'
|
36
|
+
end
|
37
|
+
|
38
|
+
context "should properly decode text frame" do
|
39
|
+
let(:encoded_text) { "\x04\x05" + decoded_text }
|
40
|
+
let(:decoded_text) { "Hello" }
|
41
|
+
let(:frame_type) { :text }
|
42
|
+
|
43
|
+
it_should_behave_like 'valid_incoming_frame'
|
44
|
+
end
|
45
|
+
|
46
|
+
context "should properly decode text frame with continuation" do
|
47
|
+
let(:encoded_text) { "\x84\x03Hel\x00\x02lo" }
|
48
|
+
let(:frame_type) { :text }
|
49
|
+
let(:decoded_text) { "Hello" }
|
50
|
+
|
51
|
+
it_should_behave_like 'valid_incoming_frame'
|
52
|
+
end
|
53
|
+
|
54
|
+
context "should properly decode text frame in between of continuation" do
|
55
|
+
let(:encoded_text) { "\x84\x03Hel\x03\x03abc\x00\x02lo" }
|
56
|
+
let(:frame_type) { [:pong, :text] }
|
57
|
+
let(:decoded_text) { ["abc", "Hello"] }
|
58
|
+
|
59
|
+
it_should_behave_like 'valid_incoming_frame'
|
60
|
+
end
|
61
|
+
|
62
|
+
context "should not return unfinished more frame" do
|
63
|
+
let(:encoded_text) { "\x84\x03Hel\x03\x03abc" }
|
64
|
+
let(:frame_type) { :pong }
|
65
|
+
let(:decoded_text) { "abc" }
|
66
|
+
|
67
|
+
it_should_behave_like 'valid_incoming_frame'
|
68
|
+
end
|
69
|
+
|
70
|
+
context "should properly decode 256 bytes binary frame" do
|
71
|
+
let(:encoded_text) { "\x05\x7E\x01\x00" + decoded_text }
|
72
|
+
let(:frame_type) { :binary }
|
73
|
+
let(:decoded_text) { "a" * 256 }
|
74
|
+
|
75
|
+
it_should_behave_like 'valid_incoming_frame'
|
76
|
+
end
|
77
|
+
|
78
|
+
context "should properly decode 64KiB binary frame" do
|
79
|
+
let(:encoded_text) { "\x05\x7F\x00\x00\x00\x00\x00\x01\x00\x00" + decoded_text }
|
80
|
+
let(:frame_type) { :binary }
|
81
|
+
let(:decoded_text) { "a" * 65536 }
|
82
|
+
|
83
|
+
it_should_behave_like 'valid_incoming_frame'
|
84
|
+
end
|
85
|
+
|
86
|
+
context "should wait with incomplete frame" do
|
87
|
+
let(:encoded_text) { "\x04\x06Hello" }
|
88
|
+
let(:decoded_text) { nil }
|
89
|
+
|
90
|
+
it_should_behave_like 'valid_incoming_frame'
|
91
|
+
end
|
92
|
+
|
93
|
+
context "should raise error with invalid opcode" do
|
94
|
+
let(:encoded_text) { "\x09\x05Hello" }
|
95
|
+
let(:decoded_text) { nil }
|
96
|
+
let(:error) { :unknown_opcode }
|
97
|
+
|
98
|
+
it_should_behave_like 'valid_incoming_frame'
|
99
|
+
end
|
100
|
+
|
101
|
+
context "should raise error with too long frame" do
|
102
|
+
let(:encoded_text) { "\x04\x7F" + "a" * WebSocket::Frame::Handler::Base::MAX_FRAME_SIZE }
|
103
|
+
let(:decoded_text) { nil }
|
104
|
+
let(:error) { :frame_too_long }
|
105
|
+
|
106
|
+
it_should_behave_like('valid_incoming_frame') unless RUBY_PLATFORM == "java"
|
107
|
+
end
|
108
|
+
|
109
|
+
context "should raise error with continuation frame without more frame earlier" do
|
110
|
+
let(:encoded_text) { "\x00\x05Hello" }
|
111
|
+
let(:decoded_text) { nil }
|
112
|
+
let(:error) { :unexpected_continuation_frame }
|
113
|
+
|
114
|
+
it_should_behave_like 'valid_incoming_frame'
|
115
|
+
end
|
116
|
+
|
117
|
+
end
|
@@ -0,0 +1,117 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe 'Incoming frame draft 04' do
|
4
|
+
let(:version) { 4 }
|
5
|
+
let(:frame) { WebSocket::Frame::Incoming.new(:version => version, :data => encoded_text) }
|
6
|
+
let(:encoded_text) { nil }
|
7
|
+
let(:decoded_text) { nil }
|
8
|
+
let(:frame_type) { nil }
|
9
|
+
let(:error) { nil }
|
10
|
+
subject { frame }
|
11
|
+
|
12
|
+
it_should_behave_like 'valid_incoming_frame'
|
13
|
+
|
14
|
+
context "should properly decode close frame" do
|
15
|
+
let(:encoded_text) { "\x81\x05" + decoded_text }
|
16
|
+
let(:frame_type) { :close }
|
17
|
+
let(:decoded_text) { "Hello" }
|
18
|
+
|
19
|
+
it_should_behave_like 'valid_incoming_frame'
|
20
|
+
end
|
21
|
+
|
22
|
+
context "should properly decode ping frame" do
|
23
|
+
let(:encoded_text) { "\x82\x05" + decoded_text }
|
24
|
+
let(:frame_type) { :ping }
|
25
|
+
let(:decoded_text) { "Hello" }
|
26
|
+
|
27
|
+
it_should_behave_like 'valid_incoming_frame'
|
28
|
+
end
|
29
|
+
|
30
|
+
context "should properly decode pong frame" do
|
31
|
+
let(:encoded_text) { "\x83\x05" + decoded_text }
|
32
|
+
let(:frame_type) { :pong }
|
33
|
+
let(:decoded_text) { "Hello" }
|
34
|
+
|
35
|
+
it_should_behave_like 'valid_incoming_frame'
|
36
|
+
end
|
37
|
+
|
38
|
+
context "should properly decode text frame" do
|
39
|
+
let(:encoded_text) { "\x84\x05" + decoded_text }
|
40
|
+
let(:decoded_text) { "Hello" }
|
41
|
+
let(:frame_type) { :text }
|
42
|
+
|
43
|
+
it_should_behave_like 'valid_incoming_frame'
|
44
|
+
end
|
45
|
+
|
46
|
+
context "should properly decode text frame with continuation" do
|
47
|
+
let(:encoded_text) { "\x04\x03Hel\x80\x02lo" }
|
48
|
+
let(:frame_type) { :text }
|
49
|
+
let(:decoded_text) { "Hello" }
|
50
|
+
|
51
|
+
it_should_behave_like 'valid_incoming_frame'
|
52
|
+
end
|
53
|
+
|
54
|
+
context "should properly decode text frame in between of continuation" do
|
55
|
+
let(:encoded_text) { "\x04\x03Hel\x83\x03abc\x80\x02lo" }
|
56
|
+
let(:frame_type) { [:pong, :text] }
|
57
|
+
let(:decoded_text) { ["abc", "Hello"] }
|
58
|
+
|
59
|
+
it_should_behave_like 'valid_incoming_frame'
|
60
|
+
end
|
61
|
+
|
62
|
+
context "should not return unfinished more frame" do
|
63
|
+
let(:encoded_text) { "\x04\x03Hel\x83\x03abc" }
|
64
|
+
let(:frame_type) { :pong }
|
65
|
+
let(:decoded_text) { "abc" }
|
66
|
+
|
67
|
+
it_should_behave_like 'valid_incoming_frame'
|
68
|
+
end
|
69
|
+
|
70
|
+
context "should properly decode 256 bytes binary frame" do
|
71
|
+
let(:encoded_text) { "\x85\x7E\x01\x00" + decoded_text }
|
72
|
+
let(:frame_type) { :binary }
|
73
|
+
let(:decoded_text) { "a" * 256 }
|
74
|
+
|
75
|
+
it_should_behave_like 'valid_incoming_frame'
|
76
|
+
end
|
77
|
+
|
78
|
+
context "should properly decode 64KiB binary frame" do
|
79
|
+
let(:encoded_text) { "\x85\x7F\x00\x00\x00\x00\x00\x01\x00\x00" + decoded_text }
|
80
|
+
let(:frame_type) { :binary }
|
81
|
+
let(:decoded_text) { "a" * 65536 }
|
82
|
+
|
83
|
+
it_should_behave_like 'valid_incoming_frame'
|
84
|
+
end
|
85
|
+
|
86
|
+
context "should wait with incomplete frame" do
|
87
|
+
let(:encoded_text) { "\x84\x06Hello" }
|
88
|
+
let(:decoded_text) { nil }
|
89
|
+
|
90
|
+
it_should_behave_like 'valid_incoming_frame'
|
91
|
+
end
|
92
|
+
|
93
|
+
context "should raise error with invalid opcode" do
|
94
|
+
let(:encoded_text) { "\x89\x05Hello" }
|
95
|
+
let(:decoded_text) { nil }
|
96
|
+
let(:error) { :unknown_opcode }
|
97
|
+
|
98
|
+
it_should_behave_like 'valid_incoming_frame'
|
99
|
+
end
|
100
|
+
|
101
|
+
context "should raise error with too long frame" do
|
102
|
+
let(:encoded_text) { "\x84\x7F" + "a" * WebSocket::Frame::Handler::Base::MAX_FRAME_SIZE }
|
103
|
+
let(:decoded_text) { nil }
|
104
|
+
let(:error) { :frame_too_long }
|
105
|
+
|
106
|
+
it_should_behave_like('valid_incoming_frame') unless RUBY_PLATFORM == "java"
|
107
|
+
end
|
108
|
+
|
109
|
+
context "should raise error with continuation frame without more frame earlier" do
|
110
|
+
let(:encoded_text) { "\x80\x05Hello" }
|
111
|
+
let(:decoded_text) { nil }
|
112
|
+
let(:error) { :unexpected_continuation_frame }
|
113
|
+
|
114
|
+
it_should_behave_like 'valid_incoming_frame'
|
115
|
+
end
|
116
|
+
|
117
|
+
end
|
@@ -0,0 +1,133 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe 'Incoming frame draft 05' do
|
4
|
+
let(:version) { 5 }
|
5
|
+
let(:frame) { WebSocket::Frame::Incoming.new(:version => version, :data => encoded_text) }
|
6
|
+
let(:encoded_text) { nil }
|
7
|
+
let(:decoded_text) { nil }
|
8
|
+
let(:frame_type) { nil }
|
9
|
+
let(:error) { nil }
|
10
|
+
subject { frame }
|
11
|
+
|
12
|
+
it_should_behave_like 'valid_incoming_frame'
|
13
|
+
|
14
|
+
context "should properly decode close frame" do
|
15
|
+
let(:encoded_text) { "\x81\x05" + decoded_text }
|
16
|
+
let(:frame_type) { :close }
|
17
|
+
let(:decoded_text) { "Hello" }
|
18
|
+
|
19
|
+
it_should_behave_like 'valid_incoming_frame'
|
20
|
+
end
|
21
|
+
|
22
|
+
context "should properly decode ping frame" do
|
23
|
+
let(:encoded_text) { "\x82\x05" + decoded_text }
|
24
|
+
let(:frame_type) { :ping }
|
25
|
+
let(:decoded_text) { "Hello" }
|
26
|
+
|
27
|
+
it_should_behave_like 'valid_incoming_frame'
|
28
|
+
end
|
29
|
+
|
30
|
+
context "should properly decode pong frame" do
|
31
|
+
let(:encoded_text) { "\x83\x05" + decoded_text }
|
32
|
+
let(:frame_type) { :pong }
|
33
|
+
let(:decoded_text) { "Hello" }
|
34
|
+
|
35
|
+
it_should_behave_like 'valid_incoming_frame'
|
36
|
+
end
|
37
|
+
|
38
|
+
context "should properly decode text frame" do
|
39
|
+
let(:encoded_text) { "\x84\x05" + decoded_text }
|
40
|
+
let(:decoded_text) { "Hello" }
|
41
|
+
let(:frame_type) { :text }
|
42
|
+
|
43
|
+
it_should_behave_like 'valid_incoming_frame'
|
44
|
+
end
|
45
|
+
|
46
|
+
context "should properly decode masked text frame" do
|
47
|
+
let(:encoded_text) { "\x84\x85\x37\xfa\x21\x3d\x7f\x9f\x4d\x51\x58" }
|
48
|
+
let(:decoded_text) { "Hello" }
|
49
|
+
let(:frame_type) { :text }
|
50
|
+
|
51
|
+
it_should_behave_like 'valid_incoming_frame'
|
52
|
+
end
|
53
|
+
|
54
|
+
context "should properly decode text frame with continuation" do
|
55
|
+
let(:encoded_text) { "\x04\x03Hel\x80\x02lo" }
|
56
|
+
let(:frame_type) { :text }
|
57
|
+
let(:decoded_text) { "Hello" }
|
58
|
+
|
59
|
+
it_should_behave_like 'valid_incoming_frame'
|
60
|
+
end
|
61
|
+
|
62
|
+
context "should properly decode masked text frame with continuation" do
|
63
|
+
let(:encoded_text) { "\x04\x83\x37\xfa\x21\x3d\x7f\x9f\x4d\x80\x82\x37\xfa\x21\x3d\x5b\x95" }
|
64
|
+
let(:frame_type) { :text }
|
65
|
+
let(:decoded_text) { "Hello" }
|
66
|
+
|
67
|
+
it_should_behave_like 'valid_incoming_frame'
|
68
|
+
end
|
69
|
+
|
70
|
+
context "should properly decode text frame in between of continuation" do
|
71
|
+
let(:encoded_text) { "\x04\x03Hel\x83\x03abc\x80\x02lo" }
|
72
|
+
let(:frame_type) { [:pong, :text] }
|
73
|
+
let(:decoded_text) { ["abc", "Hello"] }
|
74
|
+
|
75
|
+
it_should_behave_like 'valid_incoming_frame'
|
76
|
+
end
|
77
|
+
|
78
|
+
context "should not return unfinished more frame" do
|
79
|
+
let(:encoded_text) { "\x04\x03Hel\x83\x03abc" }
|
80
|
+
let(:frame_type) { :pong }
|
81
|
+
let(:decoded_text) { "abc" }
|
82
|
+
|
83
|
+
it_should_behave_like 'valid_incoming_frame'
|
84
|
+
end
|
85
|
+
|
86
|
+
context "should properly decode 256 bytes binary frame" do
|
87
|
+
let(:encoded_text) { "\x85\x7E\x01\x00" + decoded_text }
|
88
|
+
let(:frame_type) { :binary }
|
89
|
+
let(:decoded_text) { "a" * 256 }
|
90
|
+
|
91
|
+
it_should_behave_like 'valid_incoming_frame'
|
92
|
+
end
|
93
|
+
|
94
|
+
context "should properly decode 64KiB binary frame" do
|
95
|
+
let(:encoded_text) { "\x85\x7F\x00\x00\x00\x00\x00\x01\x00\x00" + decoded_text }
|
96
|
+
let(:frame_type) { :binary }
|
97
|
+
let(:decoded_text) { "a" * 65536 }
|
98
|
+
|
99
|
+
it_should_behave_like 'valid_incoming_frame'
|
100
|
+
end
|
101
|
+
|
102
|
+
context "should wait with incomplete frame" do
|
103
|
+
let(:encoded_text) { "\x84\x06Hello" }
|
104
|
+
let(:decoded_text) { nil }
|
105
|
+
|
106
|
+
it_should_behave_like 'valid_incoming_frame'
|
107
|
+
end
|
108
|
+
|
109
|
+
context "should raise error with invalid opcode" do
|
110
|
+
let(:encoded_text) { "\x89\x05Hello" }
|
111
|
+
let(:decoded_text) { nil }
|
112
|
+
let(:error) { :unknown_opcode }
|
113
|
+
|
114
|
+
it_should_behave_like 'valid_incoming_frame'
|
115
|
+
end
|
116
|
+
|
117
|
+
context "should raise error with too long frame" do
|
118
|
+
let(:encoded_text) { "\x84\x7F" + "a" * WebSocket::Frame::Handler::Base::MAX_FRAME_SIZE }
|
119
|
+
let(:decoded_text) { nil }
|
120
|
+
let(:error) { :frame_too_long }
|
121
|
+
|
122
|
+
it_should_behave_like('valid_incoming_frame') unless RUBY_PLATFORM == "java"
|
123
|
+
end
|
124
|
+
|
125
|
+
context "should raise error with continuation frame without more frame earlier" do
|
126
|
+
let(:encoded_text) { "\x80\x05Hello" }
|
127
|
+
let(:decoded_text) { nil }
|
128
|
+
let(:error) { :unexpected_continuation_frame }
|
129
|
+
|
130
|
+
it_should_behave_like 'valid_incoming_frame'
|
131
|
+
end
|
132
|
+
|
133
|
+
end
|
@@ -0,0 +1,133 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe 'Incoming frame draft 07' do
|
4
|
+
let(:version) { 7 }
|
5
|
+
let(:frame) { WebSocket::Frame::Incoming.new(:version => version, :data => encoded_text) }
|
6
|
+
let(:encoded_text) { nil }
|
7
|
+
let(:decoded_text) { nil }
|
8
|
+
let(:frame_type) { nil }
|
9
|
+
let(:error) { nil }
|
10
|
+
subject { frame }
|
11
|
+
|
12
|
+
it_should_behave_like 'valid_incoming_frame'
|
13
|
+
|
14
|
+
context "should properly decode close frame" do
|
15
|
+
let(:encoded_text) { "\x88\x05" + decoded_text }
|
16
|
+
let(:frame_type) { :close }
|
17
|
+
let(:decoded_text) { "Hello" }
|
18
|
+
|
19
|
+
it_should_behave_like 'valid_incoming_frame'
|
20
|
+
end
|
21
|
+
|
22
|
+
context "should properly decode ping frame" do
|
23
|
+
let(:encoded_text) { "\x89\x05" + decoded_text }
|
24
|
+
let(:frame_type) { :ping }
|
25
|
+
let(:decoded_text) { "Hello" }
|
26
|
+
|
27
|
+
it_should_behave_like 'valid_incoming_frame'
|
28
|
+
end
|
29
|
+
|
30
|
+
context "should properly decode pong frame" do
|
31
|
+
let(:encoded_text) { "\x8a\x05" + decoded_text }
|
32
|
+
let(:frame_type) { :pong }
|
33
|
+
let(:decoded_text) { "Hello" }
|
34
|
+
|
35
|
+
it_should_behave_like 'valid_incoming_frame'
|
36
|
+
end
|
37
|
+
|
38
|
+
context "should properly decode text frame" do
|
39
|
+
let(:encoded_text) { "\x81\x05\x48\x65\x6c\x6c\x6f" }
|
40
|
+
let(:decoded_text) { "Hello" }
|
41
|
+
let(:frame_type) { :text }
|
42
|
+
|
43
|
+
it_should_behave_like 'valid_incoming_frame'
|
44
|
+
end
|
45
|
+
|
46
|
+
context "should properly decode masked text frame" do
|
47
|
+
let(:encoded_text) { "\x81\x85\x37\xfa\x21\x3d\x7f\x9f\x4d\x51\x58" }
|
48
|
+
let(:decoded_text) { "Hello" }
|
49
|
+
let(:frame_type) { :text }
|
50
|
+
|
51
|
+
it_should_behave_like 'valid_incoming_frame'
|
52
|
+
end
|
53
|
+
|
54
|
+
context "should properly decode text frame with continuation" do
|
55
|
+
let(:encoded_text) { "\x01\x03Hel\x80\x02lo" }
|
56
|
+
let(:frame_type) { :text }
|
57
|
+
let(:decoded_text) { "Hello" }
|
58
|
+
|
59
|
+
it_should_behave_like 'valid_incoming_frame'
|
60
|
+
end
|
61
|
+
|
62
|
+
context "should properly decode masked text frame with continuation" do
|
63
|
+
let(:encoded_text) { "\x01\x83\x37\xfa\x21\x3d\x7f\x9f\x4d\x80\x82\x37\xfa\x21\x3d\x5b\x95" }
|
64
|
+
let(:frame_type) { :text }
|
65
|
+
let(:decoded_text) { "Hello" }
|
66
|
+
|
67
|
+
it_should_behave_like 'valid_incoming_frame'
|
68
|
+
end
|
69
|
+
|
70
|
+
context "should properly decode text frame in between of continuation" do
|
71
|
+
let(:encoded_text) { "\x01\x03Hel\x8a\x03abc\x80\x02lo" }
|
72
|
+
let(:frame_type) { [:pong, :text] }
|
73
|
+
let(:decoded_text) { ["abc", "Hello"] }
|
74
|
+
|
75
|
+
it_should_behave_like 'valid_incoming_frame'
|
76
|
+
end
|
77
|
+
|
78
|
+
context "should not return unfinished more frame" do
|
79
|
+
let(:encoded_text) { "\x01\x03Hel\x8a\x03abc" }
|
80
|
+
let(:frame_type) { :pong }
|
81
|
+
let(:decoded_text) { "abc" }
|
82
|
+
|
83
|
+
it_should_behave_like 'valid_incoming_frame'
|
84
|
+
end
|
85
|
+
|
86
|
+
context "should properly decode 256 bytes binary frame" do
|
87
|
+
let(:encoded_text) { "\x82\x7E\x01\x00" + decoded_text }
|
88
|
+
let(:frame_type) { :binary }
|
89
|
+
let(:decoded_text) { "a" * 256 }
|
90
|
+
|
91
|
+
it_should_behave_like 'valid_incoming_frame'
|
92
|
+
end
|
93
|
+
|
94
|
+
context "should properly decode 64KiB binary frame" do
|
95
|
+
let(:encoded_text) { "\x82\x7F\x00\x00\x00\x00\x00\x01\x00\x00" + decoded_text }
|
96
|
+
let(:frame_type) { :binary }
|
97
|
+
let(:decoded_text) { "a" * 65536 }
|
98
|
+
|
99
|
+
it_should_behave_like 'valid_incoming_frame'
|
100
|
+
end
|
101
|
+
|
102
|
+
context "should wait with incomplete frame" do
|
103
|
+
let(:encoded_text) { "\x81\x06Hello" }
|
104
|
+
let(:decoded_text) { nil }
|
105
|
+
|
106
|
+
it_should_behave_like 'valid_incoming_frame'
|
107
|
+
end
|
108
|
+
|
109
|
+
context "should raise error with invalid opcode" do
|
110
|
+
let(:encoded_text) { "\x85\x05Hello" }
|
111
|
+
let(:decoded_text) { nil }
|
112
|
+
let(:error) { :unknown_opcode }
|
113
|
+
|
114
|
+
it_should_behave_like 'valid_incoming_frame'
|
115
|
+
end
|
116
|
+
|
117
|
+
context "should raise error with too long frame" do
|
118
|
+
let(:encoded_text) { "\x81\x7F" + "a" * WebSocket::Frame::Handler::Base::MAX_FRAME_SIZE }
|
119
|
+
let(:decoded_text) { nil }
|
120
|
+
let(:error) { :frame_too_long }
|
121
|
+
|
122
|
+
it_should_behave_like('valid_incoming_frame') unless RUBY_PLATFORM == "java"
|
123
|
+
end
|
124
|
+
|
125
|
+
context "should raise error with continuation frame without more frame earlier" do
|
126
|
+
let(:encoded_text) { "\x80\x05Hello" }
|
127
|
+
let(:decoded_text) { nil }
|
128
|
+
let(:error) { :unexpected_continuation_frame }
|
129
|
+
|
130
|
+
it_should_behave_like 'valid_incoming_frame'
|
131
|
+
end
|
132
|
+
|
133
|
+
end
|