websocket 1.2.3 → 1.2.9
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.codeclimate.yml +17 -0
- data/.github/workflows/publish.yml +17 -0
- data/.rubocop.yml +35 -3
- data/.travis.yml +14 -7
- data/CHANGELOG.md +24 -0
- data/Gemfile +12 -4
- data/README.md +3 -2
- data/Rakefile +8 -3
- data/lib/websocket.rb +4 -1
- data/lib/websocket/error.rb +8 -0
- data/lib/websocket/exception_handler.rb +3 -1
- data/lib/websocket/frame.rb +2 -0
- data/lib/websocket/frame/base.rb +5 -9
- data/lib/websocket/frame/data.rb +5 -2
- data/lib/websocket/frame/handler.rb +2 -0
- data/lib/websocket/frame/handler/base.rb +6 -4
- data/lib/websocket/frame/handler/handler03.rb +23 -16
- data/lib/websocket/frame/handler/handler04.rb +1 -0
- data/lib/websocket/frame/handler/handler05.rb +1 -0
- data/lib/websocket/frame/handler/handler07.rb +10 -9
- data/lib/websocket/frame/handler/handler75.rb +8 -7
- data/lib/websocket/frame/incoming.rb +2 -0
- data/lib/websocket/frame/incoming/client.rb +2 -0
- data/lib/websocket/frame/incoming/server.rb +2 -0
- data/lib/websocket/frame/outgoing.rb +3 -1
- data/lib/websocket/frame/outgoing/client.rb +2 -0
- data/lib/websocket/frame/outgoing/server.rb +2 -0
- data/lib/websocket/handshake.rb +2 -0
- data/lib/websocket/handshake/base.rb +26 -13
- data/lib/websocket/handshake/client.rb +17 -14
- data/lib/websocket/handshake/handler.rb +2 -0
- data/lib/websocket/handshake/handler/base.rb +2 -0
- data/lib/websocket/handshake/handler/client.rb +11 -0
- data/lib/websocket/handshake/handler/client01.rb +2 -0
- data/lib/websocket/handshake/handler/client04.rb +15 -4
- data/lib/websocket/handshake/handler/client11.rb +2 -0
- data/lib/websocket/handshake/handler/client75.rb +18 -2
- data/lib/websocket/handshake/handler/client76.rb +11 -5
- data/lib/websocket/handshake/handler/server.rb +2 -0
- data/lib/websocket/handshake/handler/server04.rb +12 -4
- data/lib/websocket/handshake/handler/server75.rb +21 -5
- data/lib/websocket/handshake/handler/server76.rb +14 -16
- data/lib/websocket/handshake/server.rb +7 -4
- data/lib/websocket/nice_inspect.rb +12 -0
- data/lib/websocket/version.rb +3 -1
- data/spec/frame/incoming_03_spec.rb +20 -17
- data/spec/frame/incoming_04_spec.rb +20 -17
- data/spec/frame/incoming_05_spec.rb +22 -19
- data/spec/frame/incoming_07_spec.rb +24 -21
- data/spec/frame/incoming_75_spec.rb +13 -10
- data/spec/frame/incoming_common_spec.rb +18 -8
- data/spec/frame/masking_spec.rb +3 -1
- data/spec/frame/outgoing_03_spec.rb +13 -10
- data/spec/frame/outgoing_04_spec.rb +13 -10
- data/spec/frame/outgoing_05_spec.rb +12 -9
- data/spec/frame/outgoing_07_spec.rb +13 -10
- data/spec/frame/outgoing_75_spec.rb +8 -5
- data/spec/frame/outgoing_common_spec.rb +11 -4
- data/spec/handshake/client_04_spec.rb +46 -3
- data/spec/handshake/client_11_spec.rb +5 -3
- data/spec/handshake/client_75_spec.rb +28 -1
- data/spec/handshake/client_76_spec.rb +30 -3
- data/spec/handshake/server_04_spec.rb +37 -4
- data/spec/handshake/server_75_spec.rb +25 -1
- data/spec/handshake/server_76_spec.rb +33 -9
- data/spec/spec_helper.rb +2 -2
- data/spec/support/all_client_drafts.rb +23 -21
- data/spec/support/all_server_drafts.rb +21 -16
- data/spec/support/frames_base.rb +2 -0
- data/spec/support/handshake_requests.rb +19 -17
- data/spec/support/incoming_frames.rb +46 -25
- data/spec/support/outgoing_frames.rb +30 -8
- data/spec/support/overwrites.rb +2 -0
- data/websocket.gemspec +4 -1
- metadata +7 -5
@@ -1,23 +1,26 @@
|
|
1
1
|
# encoding: binary
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
2
4
|
require 'spec_helper'
|
3
5
|
|
4
6
|
RSpec.describe 'Incoming frame draft 05' do
|
7
|
+
subject { frame }
|
8
|
+
|
5
9
|
let(:version) { 5 }
|
6
10
|
let(:frame) { WebSocket::Frame::Incoming.new(version: version, data: encoded_text) }
|
7
11
|
let(:encoded_text) { nil }
|
8
12
|
let(:decoded_text) { nil }
|
9
13
|
let(:frame_type) { nil }
|
10
14
|
let(:error) { nil }
|
11
|
-
subject { frame }
|
12
15
|
|
13
|
-
|
16
|
+
it_behaves_like 'valid_incoming_frame'
|
14
17
|
|
15
18
|
context 'should properly decode close frame' do
|
16
19
|
let(:encoded_text) { "\x81\x05" + decoded_text }
|
17
20
|
let(:frame_type) { :close }
|
18
21
|
let(:decoded_text) { 'Hello' }
|
19
22
|
|
20
|
-
|
23
|
+
it_behaves_like 'valid_incoming_frame'
|
21
24
|
end
|
22
25
|
|
23
26
|
context 'should properly decode ping frame' do
|
@@ -25,7 +28,7 @@ RSpec.describe 'Incoming frame draft 05' do
|
|
25
28
|
let(:frame_type) { :ping }
|
26
29
|
let(:decoded_text) { 'Hello' }
|
27
30
|
|
28
|
-
|
31
|
+
it_behaves_like 'valid_incoming_frame'
|
29
32
|
end
|
30
33
|
|
31
34
|
context 'should properly decode pong frame' do
|
@@ -33,7 +36,7 @@ RSpec.describe 'Incoming frame draft 05' do
|
|
33
36
|
let(:frame_type) { :pong }
|
34
37
|
let(:decoded_text) { 'Hello' }
|
35
38
|
|
36
|
-
|
39
|
+
it_behaves_like 'valid_incoming_frame'
|
37
40
|
end
|
38
41
|
|
39
42
|
context 'should properly decode text frame' do
|
@@ -41,7 +44,7 @@ RSpec.describe 'Incoming frame draft 05' do
|
|
41
44
|
let(:decoded_text) { 'Hello' }
|
42
45
|
let(:frame_type) { :text }
|
43
46
|
|
44
|
-
|
47
|
+
it_behaves_like 'valid_incoming_frame'
|
45
48
|
end
|
46
49
|
|
47
50
|
context 'should properly decode masked text frame' do
|
@@ -49,7 +52,7 @@ RSpec.describe 'Incoming frame draft 05' do
|
|
49
52
|
let(:decoded_text) { 'Hello' }
|
50
53
|
let(:frame_type) { :text }
|
51
54
|
|
52
|
-
|
55
|
+
it_behaves_like 'valid_incoming_frame'
|
53
56
|
end
|
54
57
|
|
55
58
|
context 'should properly decode text frame with continuation' do
|
@@ -57,7 +60,7 @@ RSpec.describe 'Incoming frame draft 05' do
|
|
57
60
|
let(:frame_type) { :text }
|
58
61
|
let(:decoded_text) { 'Hello' }
|
59
62
|
|
60
|
-
|
63
|
+
it_behaves_like 'valid_incoming_frame'
|
61
64
|
end
|
62
65
|
|
63
66
|
context 'should properly decode masked text frame with continuation' do
|
@@ -65,15 +68,15 @@ RSpec.describe 'Incoming frame draft 05' do
|
|
65
68
|
let(:frame_type) { :text }
|
66
69
|
let(:decoded_text) { 'Hello' }
|
67
70
|
|
68
|
-
|
71
|
+
it_behaves_like 'valid_incoming_frame'
|
69
72
|
end
|
70
73
|
|
71
74
|
context 'should properly decode text frame in between of continuation' do
|
72
75
|
let(:encoded_text) { "\x04\x03Hel\x83\x03abc\x80\x02lo" }
|
73
|
-
let(:frame_type) { [
|
74
|
-
let(:decoded_text) { %w
|
76
|
+
let(:frame_type) { %i[pong text] }
|
77
|
+
let(:decoded_text) { %w[abc Hello] }
|
75
78
|
|
76
|
-
|
79
|
+
it_behaves_like 'valid_incoming_frame'
|
77
80
|
end
|
78
81
|
|
79
82
|
context 'should not return unfinished more frame' do
|
@@ -81,7 +84,7 @@ RSpec.describe 'Incoming frame draft 05' do
|
|
81
84
|
let(:frame_type) { :pong }
|
82
85
|
let(:decoded_text) { 'abc' }
|
83
86
|
|
84
|
-
|
87
|
+
it_behaves_like 'valid_incoming_frame'
|
85
88
|
end
|
86
89
|
|
87
90
|
context 'should properly decode 256 bytes binary frame' do
|
@@ -89,7 +92,7 @@ RSpec.describe 'Incoming frame draft 05' do
|
|
89
92
|
let(:frame_type) { :binary }
|
90
93
|
let(:decoded_text) { 'a' * 256 }
|
91
94
|
|
92
|
-
|
95
|
+
it_behaves_like 'valid_incoming_frame'
|
93
96
|
end
|
94
97
|
|
95
98
|
context 'should properly decode 64KiB binary frame' do
|
@@ -97,14 +100,14 @@ RSpec.describe 'Incoming frame draft 05' do
|
|
97
100
|
let(:frame_type) { :binary }
|
98
101
|
let(:decoded_text) { 'a' * 65_536 }
|
99
102
|
|
100
|
-
|
103
|
+
it_behaves_like 'valid_incoming_frame'
|
101
104
|
end
|
102
105
|
|
103
106
|
context 'should wait with incomplete frame' do
|
104
107
|
let(:encoded_text) { "\x84\x06Hello" }
|
105
108
|
let(:decoded_text) { nil }
|
106
109
|
|
107
|
-
|
110
|
+
it_behaves_like 'valid_incoming_frame'
|
108
111
|
end
|
109
112
|
|
110
113
|
context 'should raise error with invalid opcode' do
|
@@ -112,7 +115,7 @@ RSpec.describe 'Incoming frame draft 05' do
|
|
112
115
|
let(:decoded_text) { nil }
|
113
116
|
let(:error) { WebSocket::Error::Frame::UnknownOpcode }
|
114
117
|
|
115
|
-
|
118
|
+
it_behaves_like 'valid_incoming_frame'
|
116
119
|
end
|
117
120
|
|
118
121
|
context 'should raise error with too long frame' do
|
@@ -120,7 +123,7 @@ RSpec.describe 'Incoming frame draft 05' do
|
|
120
123
|
let(:decoded_text) { nil }
|
121
124
|
let(:error) { WebSocket::Error::Frame::TooLong }
|
122
125
|
|
123
|
-
|
126
|
+
it_behaves_like 'valid_incoming_frame'
|
124
127
|
end
|
125
128
|
|
126
129
|
context 'should raise error with continuation frame without more frame earlier' do
|
@@ -128,6 +131,6 @@ RSpec.describe 'Incoming frame draft 05' do
|
|
128
131
|
let(:decoded_text) { nil }
|
129
132
|
let(:error) { WebSocket::Error::Frame::UnexpectedContinuationFrame }
|
130
133
|
|
131
|
-
|
134
|
+
it_behaves_like 'valid_incoming_frame'
|
132
135
|
end
|
133
136
|
end
|
@@ -1,16 +1,19 @@
|
|
1
1
|
# encoding: binary
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
2
4
|
require 'spec_helper'
|
3
5
|
|
4
6
|
RSpec.describe 'Incoming frame draft 07' do
|
7
|
+
subject { frame }
|
8
|
+
|
5
9
|
let(:version) { 7 }
|
6
10
|
let(:frame) { WebSocket::Frame::Incoming.new(version: version, data: encoded_text) }
|
7
11
|
let(:encoded_text) { nil }
|
8
12
|
let(:decoded_text) { nil }
|
9
13
|
let(:frame_type) { nil }
|
10
14
|
let(:error) { nil }
|
11
|
-
subject { frame }
|
12
15
|
|
13
|
-
|
16
|
+
it_behaves_like 'valid_incoming_frame'
|
14
17
|
|
15
18
|
context 'should properly decode close frame' do
|
16
19
|
let(:encoded_text) { "\x88\x07\x03\xE8" + decoded_text }
|
@@ -18,7 +21,7 @@ RSpec.describe 'Incoming frame draft 07' do
|
|
18
21
|
let(:decoded_text) { 'Hello' }
|
19
22
|
let(:close_code) { 1000 }
|
20
23
|
|
21
|
-
|
24
|
+
it_behaves_like 'valid_incoming_frame'
|
22
25
|
end
|
23
26
|
|
24
27
|
context 'should raise error with invalid close code' do
|
@@ -26,7 +29,7 @@ RSpec.describe 'Incoming frame draft 07' do
|
|
26
29
|
let(:decoded_text) { nil }
|
27
30
|
let(:error) { WebSocket::Error::Frame::UnknownCloseCode }
|
28
31
|
|
29
|
-
|
32
|
+
it_behaves_like 'valid_incoming_frame'
|
30
33
|
end
|
31
34
|
|
32
35
|
context 'should properly decode close frame with invalid UTF-8 message' do
|
@@ -34,7 +37,7 @@ RSpec.describe 'Incoming frame draft 07' do
|
|
34
37
|
let(:decoded_text) { nil }
|
35
38
|
let(:error) { WebSocket::Error::Frame::InvalidPayloadEncoding }
|
36
39
|
|
37
|
-
|
40
|
+
it_behaves_like 'valid_incoming_frame'
|
38
41
|
end
|
39
42
|
|
40
43
|
context 'should properly decode ping frame' do
|
@@ -42,7 +45,7 @@ RSpec.describe 'Incoming frame draft 07' do
|
|
42
45
|
let(:frame_type) { :ping }
|
43
46
|
let(:decoded_text) { 'Hello' }
|
44
47
|
|
45
|
-
|
48
|
+
it_behaves_like 'valid_incoming_frame'
|
46
49
|
end
|
47
50
|
|
48
51
|
context 'should properly decode pong frame' do
|
@@ -50,7 +53,7 @@ RSpec.describe 'Incoming frame draft 07' do
|
|
50
53
|
let(:frame_type) { :pong }
|
51
54
|
let(:decoded_text) { 'Hello' }
|
52
55
|
|
53
|
-
|
56
|
+
it_behaves_like 'valid_incoming_frame'
|
54
57
|
end
|
55
58
|
|
56
59
|
context 'should properly decode text frame' do
|
@@ -58,7 +61,7 @@ RSpec.describe 'Incoming frame draft 07' do
|
|
58
61
|
let(:decoded_text) { 'Hello' }
|
59
62
|
let(:frame_type) { :text }
|
60
63
|
|
61
|
-
|
64
|
+
it_behaves_like 'valid_incoming_frame'
|
62
65
|
end
|
63
66
|
|
64
67
|
context 'should properly decode masked text frame' do
|
@@ -66,7 +69,7 @@ RSpec.describe 'Incoming frame draft 07' do
|
|
66
69
|
let(:decoded_text) { 'Hello' }
|
67
70
|
let(:frame_type) { :text }
|
68
71
|
|
69
|
-
|
72
|
+
it_behaves_like 'valid_incoming_frame'
|
70
73
|
end
|
71
74
|
|
72
75
|
context 'should properly decode text frame with continuation' do
|
@@ -74,7 +77,7 @@ RSpec.describe 'Incoming frame draft 07' do
|
|
74
77
|
let(:frame_type) { :text }
|
75
78
|
let(:decoded_text) { 'Hello' }
|
76
79
|
|
77
|
-
|
80
|
+
it_behaves_like 'valid_incoming_frame'
|
78
81
|
end
|
79
82
|
|
80
83
|
context 'should properly decode masked text frame with continuation' do
|
@@ -82,15 +85,15 @@ RSpec.describe 'Incoming frame draft 07' do
|
|
82
85
|
let(:frame_type) { :text }
|
83
86
|
let(:decoded_text) { 'Hello' }
|
84
87
|
|
85
|
-
|
88
|
+
it_behaves_like 'valid_incoming_frame'
|
86
89
|
end
|
87
90
|
|
88
91
|
context 'should properly decode text frame in between of continuation' do
|
89
92
|
let(:encoded_text) { "\x01\x03Hel\x8a\x03abc\x80\x02lo" }
|
90
|
-
let(:frame_type) { [
|
91
|
-
let(:decoded_text) { %w
|
93
|
+
let(:frame_type) { %i[pong text] }
|
94
|
+
let(:decoded_text) { %w[abc Hello] }
|
92
95
|
|
93
|
-
|
96
|
+
it_behaves_like 'valid_incoming_frame'
|
94
97
|
end
|
95
98
|
|
96
99
|
context 'should not return unfinished more frame' do
|
@@ -98,7 +101,7 @@ RSpec.describe 'Incoming frame draft 07' do
|
|
98
101
|
let(:frame_type) { :pong }
|
99
102
|
let(:decoded_text) { 'abc' }
|
100
103
|
|
101
|
-
|
104
|
+
it_behaves_like 'valid_incoming_frame'
|
102
105
|
end
|
103
106
|
|
104
107
|
context 'should properly decode 256 bytes binary frame' do
|
@@ -106,7 +109,7 @@ RSpec.describe 'Incoming frame draft 07' do
|
|
106
109
|
let(:frame_type) { :binary }
|
107
110
|
let(:decoded_text) { 'a' * 256 }
|
108
111
|
|
109
|
-
|
112
|
+
it_behaves_like 'valid_incoming_frame'
|
110
113
|
end
|
111
114
|
|
112
115
|
context 'should properly decode 64KiB binary frame' do
|
@@ -114,14 +117,14 @@ RSpec.describe 'Incoming frame draft 07' do
|
|
114
117
|
let(:frame_type) { :binary }
|
115
118
|
let(:decoded_text) { 'a' * 65_536 }
|
116
119
|
|
117
|
-
|
120
|
+
it_behaves_like 'valid_incoming_frame'
|
118
121
|
end
|
119
122
|
|
120
123
|
context 'should wait with incomplete frame' do
|
121
124
|
let(:encoded_text) { "\x81\x06Hello" }
|
122
125
|
let(:decoded_text) { nil }
|
123
126
|
|
124
|
-
|
127
|
+
it_behaves_like 'valid_incoming_frame'
|
125
128
|
end
|
126
129
|
|
127
130
|
context 'should raise error with invalid opcode' do
|
@@ -129,7 +132,7 @@ RSpec.describe 'Incoming frame draft 07' do
|
|
129
132
|
let(:decoded_text) { nil }
|
130
133
|
let(:error) { WebSocket::Error::Frame::UnknownOpcode }
|
131
134
|
|
132
|
-
|
135
|
+
it_behaves_like 'valid_incoming_frame'
|
133
136
|
end
|
134
137
|
|
135
138
|
context 'should raise error with too long frame' do
|
@@ -137,7 +140,7 @@ RSpec.describe 'Incoming frame draft 07' do
|
|
137
140
|
let(:decoded_text) { nil }
|
138
141
|
let(:error) { WebSocket::Error::Frame::TooLong }
|
139
142
|
|
140
|
-
|
143
|
+
it_behaves_like 'valid_incoming_frame'
|
141
144
|
end
|
142
145
|
|
143
146
|
context 'should raise error with continuation frame without more frame earlier' do
|
@@ -145,6 +148,6 @@ RSpec.describe 'Incoming frame draft 07' do
|
|
145
148
|
let(:decoded_text) { nil }
|
146
149
|
let(:error) { WebSocket::Error::Frame::UnexpectedContinuationFrame }
|
147
150
|
|
148
|
-
|
151
|
+
it_behaves_like 'valid_incoming_frame'
|
149
152
|
end
|
150
153
|
end
|
@@ -1,31 +1,34 @@
|
|
1
1
|
# encoding: binary
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
2
4
|
require 'spec_helper'
|
3
5
|
|
4
6
|
RSpec.describe 'Incoming frame draft 75' do
|
7
|
+
subject { frame }
|
8
|
+
|
5
9
|
let(:version) { 75 }
|
6
10
|
let(:frame) { WebSocket::Frame::Incoming.new(version: version, data: encoded_text) }
|
7
11
|
let(:encoded_text) { nil }
|
8
12
|
let(:decoded_text) { nil }
|
9
13
|
let(:frame_type) { nil }
|
10
14
|
let(:error) { nil }
|
11
|
-
subject { frame }
|
12
15
|
|
13
|
-
|
16
|
+
it_behaves_like 'valid_incoming_frame'
|
14
17
|
|
15
18
|
context 'with valid text frame' do
|
16
19
|
let(:encoded_text) { "\x00abc\xFF" }
|
17
20
|
let(:decoded_text) { 'abc' }
|
18
21
|
let(:frame_type) { :text }
|
19
22
|
|
20
|
-
|
23
|
+
it_behaves_like 'valid_incoming_frame'
|
21
24
|
end
|
22
25
|
|
23
26
|
context 'with two frames' do
|
24
27
|
let(:encoded_text) { "\x00abc\xFF\x00def\xFF" }
|
25
|
-
let(:decoded_text) { %w
|
26
|
-
let(:frame_type) { [
|
28
|
+
let(:decoded_text) { %w[abc def] }
|
29
|
+
let(:frame_type) { %i[text text] }
|
27
30
|
|
28
|
-
|
31
|
+
it_behaves_like 'valid_incoming_frame'
|
29
32
|
end
|
30
33
|
|
31
34
|
context 'with close frame' do
|
@@ -33,27 +36,27 @@ RSpec.describe 'Incoming frame draft 75' do
|
|
33
36
|
let(:decoded_text) { '' }
|
34
37
|
let(:frame_type) { :close }
|
35
38
|
|
36
|
-
|
39
|
+
it_behaves_like 'valid_incoming_frame'
|
37
40
|
end
|
38
41
|
|
39
42
|
context 'with incomplete frame' do
|
40
43
|
let(:encoded_text) { "\x00test" }
|
41
44
|
let(:decoded_text) { nil }
|
42
45
|
|
43
|
-
|
46
|
+
it_behaves_like 'valid_incoming_frame'
|
44
47
|
end
|
45
48
|
|
46
49
|
context 'with invalid frame' do
|
47
50
|
let(:encoded_text) { 'invalid' }
|
48
51
|
let(:error) { WebSocket::Error::Frame::Invalid }
|
49
52
|
|
50
|
-
|
53
|
+
it_behaves_like 'valid_incoming_frame'
|
51
54
|
end
|
52
55
|
|
53
56
|
context 'with too long frame' do
|
54
57
|
let(:encoded_text) { "\x00" + 'a' * WebSocket.max_frame_size + "\xFF" }
|
55
58
|
let(:error) { WebSocket::Error::Frame::TooLong }
|
56
59
|
|
57
|
-
|
60
|
+
it_behaves_like 'valid_incoming_frame'
|
58
61
|
end
|
59
62
|
end
|
@@ -1,22 +1,32 @@
|
|
1
1
|
# encoding: binary
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
2
4
|
require 'spec_helper'
|
3
5
|
|
4
6
|
RSpec.describe 'Incoming common frame' do
|
5
7
|
subject { WebSocket::Frame::Incoming.new }
|
6
8
|
|
7
|
-
|
8
|
-
|
9
|
-
|
9
|
+
it 'is version 13' do
|
10
|
+
expect(subject.version).to be 13
|
11
|
+
end
|
12
|
+
|
13
|
+
it 'is not decoded' do
|
14
|
+
expect(subject.decoded?).to be false
|
15
|
+
end
|
16
|
+
|
17
|
+
it 'has no errors' do
|
18
|
+
expect(subject.error?).to be false
|
19
|
+
end
|
10
20
|
|
11
|
-
it '
|
12
|
-
expect(subject.data).to eql
|
21
|
+
it 'allows adding data via <<' do
|
22
|
+
expect(subject.data).to eql ''
|
13
23
|
subject << 'test'
|
14
|
-
expect(subject.data).to eql
|
24
|
+
expect(subject.data).to eql 'test'
|
15
25
|
end
|
16
26
|
|
17
|
-
it '
|
27
|
+
it 'raises error on invalid version' do
|
18
28
|
subject = WebSocket::Frame::Incoming.new(version: 70)
|
19
29
|
expect(subject.error?).to be true
|
20
|
-
expect(subject.error).to
|
30
|
+
expect(subject.error).to be :unknown_protocol_version
|
21
31
|
end
|
22
32
|
end
|
data/spec/frame/masking_spec.rb
CHANGED
@@ -1,8 +1,10 @@
|
|
1
1
|
# encoding: binary
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
2
4
|
require 'spec_helper'
|
3
5
|
|
4
6
|
RSpec.describe 'Masking frame draft 07' do
|
5
|
-
it '
|
7
|
+
it 'encodes and decode masked frame correctly' do
|
6
8
|
outgoing_frame = WebSocket::Frame::Outgoing::Client.new(data: 'Hello World', type: 'text')
|
7
9
|
outgoing_frame.to_s
|
8
10
|
expect(outgoing_frame.error).to be_nil
|
@@ -1,17 +1,20 @@
|
|
1
1
|
# encoding: binary
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
2
4
|
require 'spec_helper'
|
3
5
|
|
4
6
|
RSpec.describe 'Outgoing frame draft 03' do
|
5
|
-
|
7
|
+
subject { frame }
|
8
|
+
|
9
|
+
let(:version) { 3 }
|
6
10
|
let(:frame) { WebSocket::Frame::Outgoing.new(version: version, data: decoded_text, type: frame_type) }
|
7
11
|
let(:decoded_text) { '' }
|
8
12
|
let(:encoded_text) { "\x04\x00" }
|
9
13
|
let(:frame_type) { :text }
|
10
14
|
let(:require_sending) { true }
|
11
15
|
let(:error) { nil }
|
12
|
-
subject { frame }
|
13
16
|
|
14
|
-
|
17
|
+
it_behaves_like 'valid_outgoing_frame'
|
15
18
|
|
16
19
|
context 'should properly encode close frame' do
|
17
20
|
let(:frame_type) { :close }
|
@@ -19,7 +22,7 @@ RSpec.describe 'Outgoing frame draft 03' do
|
|
19
22
|
let(:encoded_text) { "\x01\x05" + decoded_text }
|
20
23
|
let(:require_sending) { true }
|
21
24
|
|
22
|
-
|
25
|
+
it_behaves_like 'valid_outgoing_frame'
|
23
26
|
end
|
24
27
|
|
25
28
|
context 'should properly encode ping frame' do
|
@@ -28,7 +31,7 @@ RSpec.describe 'Outgoing frame draft 03' do
|
|
28
31
|
let(:encoded_text) { "\x02\x05" + decoded_text }
|
29
32
|
let(:require_sending) { true }
|
30
33
|
|
31
|
-
|
34
|
+
it_behaves_like 'valid_outgoing_frame'
|
32
35
|
end
|
33
36
|
|
34
37
|
context 'should properly encode pong frame' do
|
@@ -37,7 +40,7 @@ RSpec.describe 'Outgoing frame draft 03' do
|
|
37
40
|
let(:encoded_text) { "\x03\x05" + decoded_text }
|
38
41
|
let(:require_sending) { true }
|
39
42
|
|
40
|
-
|
43
|
+
it_behaves_like 'valid_outgoing_frame'
|
41
44
|
end
|
42
45
|
|
43
46
|
context 'should properly encode text frame' do
|
@@ -45,7 +48,7 @@ RSpec.describe 'Outgoing frame draft 03' do
|
|
45
48
|
let(:encoded_text) { "\x04\x05" + decoded_text }
|
46
49
|
let(:require_sending) { true }
|
47
50
|
|
48
|
-
|
51
|
+
it_behaves_like 'valid_outgoing_frame'
|
49
52
|
end
|
50
53
|
|
51
54
|
context 'should properly encode 256 bytes binary frame' do
|
@@ -54,7 +57,7 @@ RSpec.describe 'Outgoing frame draft 03' do
|
|
54
57
|
let(:encoded_text) { "\x05\x7E\x01\x00" + decoded_text }
|
55
58
|
let(:require_sending) { true }
|
56
59
|
|
57
|
-
|
60
|
+
it_behaves_like 'valid_outgoing_frame'
|
58
61
|
end
|
59
62
|
|
60
63
|
context 'should properly encode 64KiB binary frame' do
|
@@ -63,7 +66,7 @@ RSpec.describe 'Outgoing frame draft 03' do
|
|
63
66
|
let(:encoded_text) { "\x05\x7F\x00\x00\x00\x00\x00\x01\x00\x00" + decoded_text }
|
64
67
|
let(:require_sending) { true }
|
65
68
|
|
66
|
-
|
69
|
+
it_behaves_like 'valid_outgoing_frame'
|
67
70
|
end
|
68
71
|
|
69
72
|
context 'should return error for unknown frame type' do
|
@@ -73,6 +76,6 @@ RSpec.describe 'Outgoing frame draft 03' do
|
|
73
76
|
let(:error) { :unknown_frame_type }
|
74
77
|
let(:require_sending) { false }
|
75
78
|
|
76
|
-
|
79
|
+
it_behaves_like 'valid_outgoing_frame'
|
77
80
|
end
|
78
81
|
end
|