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,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'digest/md5'
|
2
4
|
|
3
5
|
module WebSocket
|
@@ -6,7 +8,7 @@ module WebSocket
|
|
6
8
|
class Client76 < Client75
|
7
9
|
# @see WebSocket::Handshake::Base#valid?
|
8
10
|
def valid?
|
9
|
-
super && verify_challenge
|
11
|
+
super && verify_challenge && verify_protocol
|
10
12
|
end
|
11
13
|
|
12
14
|
private
|
@@ -62,22 +64,22 @@ module WebSocket
|
|
62
64
|
# Verify if challenge sent by server match generated one
|
63
65
|
# @return [Boolena] True if challenge matches, false otherwise(sets appropriate error)
|
64
66
|
def verify_challenge
|
65
|
-
|
67
|
+
raise WebSocket::Error::Handshake::InvalidAuthentication unless @handshake.leftovers == challenge
|
66
68
|
true
|
67
69
|
end
|
68
70
|
|
69
71
|
NOISE_CHARS = ("\x21".."\x2f").to_a + ("\x3a".."\x7e").to_a
|
70
72
|
|
71
73
|
# Generate Sec-WebSocket-Key1 and Sec-WebSocket-Key2
|
72
|
-
# @param [String] name of key. Will be used to set number variable needed later. Valid values: key1, key2
|
74
|
+
# @param key [String] name of key. Will be used to set number variable needed later. Valid values: key1, key2
|
73
75
|
# @return [String] generated key
|
74
76
|
def generate_key(key)
|
75
|
-
spaces =
|
77
|
+
spaces = rand(1..12)
|
76
78
|
max = 0xffffffff / spaces
|
77
79
|
number = rand(max + 1)
|
78
80
|
instance_variable_set("@#{key}_number", number)
|
79
81
|
key = (number * spaces).to_s
|
80
|
-
(1
|
82
|
+
rand(1..12).times do
|
81
83
|
char = NOISE_CHARS[rand(NOISE_CHARS.size)]
|
82
84
|
pos = rand(key.size + 1)
|
83
85
|
key[pos...pos] = char
|
@@ -93,6 +95,10 @@ module WebSocket
|
|
93
95
|
def generate_key3
|
94
96
|
[rand(0x100000000)].pack('N') + [rand(0x100000000)].pack('N')
|
95
97
|
end
|
98
|
+
|
99
|
+
def provided_protocols
|
100
|
+
Array(@handshake.headers['sec-websocket-protocol'].to_s.strip)
|
101
|
+
end
|
96
102
|
end
|
97
103
|
end
|
98
104
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'digest/sha1'
|
2
4
|
require 'base64'
|
3
5
|
|
@@ -20,10 +22,10 @@ module WebSocket
|
|
20
22
|
# @see WebSocket::Handshake::Handler::Base#handshake_keys
|
21
23
|
def handshake_keys
|
22
24
|
[
|
23
|
-
%w
|
24
|
-
%w
|
25
|
+
%w[Upgrade websocket],
|
26
|
+
%w[Connection Upgrade],
|
25
27
|
['Sec-WebSocket-Accept', signature]
|
26
|
-
]
|
28
|
+
] + protocol
|
27
29
|
end
|
28
30
|
|
29
31
|
# Signature of response, created from client request Sec-WebSocket-Key
|
@@ -35,13 +37,19 @@ module WebSocket
|
|
35
37
|
end
|
36
38
|
|
37
39
|
def verify_key
|
38
|
-
|
40
|
+
raise WebSocket::Error::Handshake::InvalidAuthentication unless key
|
39
41
|
true
|
40
42
|
end
|
41
43
|
|
42
44
|
def key
|
43
45
|
@handshake.headers['sec-websocket-key']
|
44
46
|
end
|
47
|
+
|
48
|
+
def protocol
|
49
|
+
return [] unless @handshake.headers.key?('sec-websocket-protocol')
|
50
|
+
protos = @handshake.headers['sec-websocket-protocol'].split(/ *, */) & @handshake.protocols
|
51
|
+
[['Sec-WebSocket-Protocol', protos.first]]
|
52
|
+
end
|
45
53
|
end
|
46
54
|
end
|
47
55
|
end
|
@@ -1,9 +1,19 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module WebSocket
|
2
4
|
module Handshake
|
3
5
|
module Handler
|
4
6
|
class Server75 < Server
|
5
7
|
private
|
6
8
|
|
9
|
+
def headers
|
10
|
+
{
|
11
|
+
origin: 'WebSocket-Origin',
|
12
|
+
location: 'WebSocket-Location',
|
13
|
+
protocol: 'WebSocket-Protocol'
|
14
|
+
}.freeze
|
15
|
+
end
|
16
|
+
|
7
17
|
# @see WebSocket::Handshake::Handler::Base#header_line
|
8
18
|
def header_line
|
9
19
|
'HTTP/1.1 101 Web Socket Protocol Handshake'
|
@@ -12,11 +22,17 @@ module WebSocket
|
|
12
22
|
# @see WebSocket::Handshake::Handler::Base#handshake_keys
|
13
23
|
def handshake_keys
|
14
24
|
[
|
15
|
-
%w
|
16
|
-
%w
|
17
|
-
[
|
18
|
-
[
|
19
|
-
]
|
25
|
+
%w[Upgrade WebSocket],
|
26
|
+
%w[Connection Upgrade],
|
27
|
+
[headers[:origin], @handshake.headers['origin']],
|
28
|
+
[headers[:location], @handshake.uri]
|
29
|
+
] + protocol
|
30
|
+
end
|
31
|
+
|
32
|
+
def protocol
|
33
|
+
return [] unless @handshake.headers.key?(headers[:protocol].downcase)
|
34
|
+
proto = @handshake.headers[headers[:protocol].downcase]
|
35
|
+
[[headers[:protocol], @handshake.protocols.include?(proto) ? proto : nil]]
|
20
36
|
end
|
21
37
|
end
|
22
38
|
end
|
@@ -1,9 +1,11 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'digest/md5'
|
2
4
|
|
3
5
|
module WebSocket
|
4
6
|
module Handshake
|
5
7
|
module Handler
|
6
|
-
class Server76 <
|
8
|
+
class Server76 < Server75
|
7
9
|
# @see WebSocket::Handshake::Base#valid?
|
8
10
|
def valid?
|
9
11
|
super && !finishing_line.nil?
|
@@ -11,6 +13,14 @@ module WebSocket
|
|
11
13
|
|
12
14
|
private
|
13
15
|
|
16
|
+
def headers
|
17
|
+
{
|
18
|
+
origin: 'Sec-WebSocket-Origin',
|
19
|
+
location: 'Sec-WebSocket-Location',
|
20
|
+
protocol: 'Sec-WebSocket-Protocol'
|
21
|
+
}.freeze
|
22
|
+
end
|
23
|
+
|
14
24
|
# @see WebSocket::Handshake::Base#reserved_leftover_lines
|
15
25
|
def reserved_leftover_lines
|
16
26
|
1
|
@@ -21,23 +31,11 @@ module WebSocket
|
|
21
31
|
'HTTP/1.1 101 WebSocket Protocol Handshake'
|
22
32
|
end
|
23
33
|
|
24
|
-
# @see WebSocket::Handshake::Handler::Base#handshake_keys
|
25
|
-
def handshake_keys
|
26
|
-
[
|
27
|
-
%w(Upgrade WebSocket),
|
28
|
-
%w(Connection Upgrade),
|
29
|
-
['Sec-WebSocket-Origin', @handshake.headers['origin']],
|
30
|
-
['Sec-WebSocket-Location', @handshake.uri]
|
31
|
-
]
|
32
|
-
end
|
33
|
-
|
34
34
|
# @see WebSocket::Handshake::Handler::Base#finishing_line
|
35
35
|
def finishing_line
|
36
36
|
@finishing_line ||= challenge_response
|
37
37
|
end
|
38
38
|
|
39
|
-
private
|
40
|
-
|
41
39
|
# Response to client challenge from request Sec-WebSocket-Key1, Sec-WebSocket-Key2 and leftovers
|
42
40
|
# @return [String] Challenge response or nil if error occured
|
43
41
|
def challenge_response
|
@@ -60,14 +58,14 @@ module WebSocket
|
|
60
58
|
|
61
59
|
spaces = string.scan(/ /).size
|
62
60
|
# As per 5.2.5, abort the connection if spaces are zero.
|
63
|
-
|
61
|
+
raise WebSocket::Error::Handshake::InvalidAuthentication if spaces.zero?
|
64
62
|
|
65
63
|
# As per 5.2.6, abort if numbers is not an integral multiple of spaces
|
66
|
-
|
64
|
+
raise WebSocket::Error::Handshake::InvalidAuthentication if numbers % spaces != 0
|
67
65
|
|
68
66
|
quotient = numbers / spaces
|
69
67
|
|
70
|
-
|
68
|
+
raise WebSocket::Error::Handshake::InvalidAuthentication if quotient > 2**32 - 1
|
71
69
|
|
72
70
|
quotient
|
73
71
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module WebSocket
|
2
4
|
module Handshake
|
3
5
|
# Construct or parse a server WebSocket handshake.
|
@@ -35,6 +37,7 @@ module WebSocket
|
|
35
37
|
# @param [Hash] args Arguments for server
|
36
38
|
#
|
37
39
|
# @option args [Boolean] :secure If true then server will use wss:// protocol
|
40
|
+
# @option args [Array<String>] :protocols an array of supported sub-protocols
|
38
41
|
#
|
39
42
|
# @example
|
40
43
|
# Websocket::Handshake::Server.new(secure: true)
|
@@ -70,7 +73,7 @@ module WebSocket
|
|
70
73
|
# @example
|
71
74
|
# @handshake.from_rack(env)
|
72
75
|
def from_rack(env)
|
73
|
-
@headers = env.select { |key, _value| key
|
76
|
+
@headers = env.select { |key, _value| key.to_s.start_with? 'HTTP_' }.each_with_object({}) do |tuple, memo|
|
74
77
|
key, value = tuple
|
75
78
|
memo[key.gsub(/\AHTTP_/, '').tr('_', '-').downcase] = value
|
76
79
|
end
|
@@ -153,7 +156,7 @@ module WebSocket
|
|
153
156
|
when 75 then Handler::Server75.new(self)
|
154
157
|
when 76, 0..3 then Handler::Server76.new(self)
|
155
158
|
when 4..17 then Handler::Server04.new(self)
|
156
|
-
else
|
159
|
+
else raise WebSocket::Error::Handshake::UnknownVersion
|
157
160
|
end
|
158
161
|
end
|
159
162
|
|
@@ -164,9 +167,9 @@ module WebSocket
|
|
164
167
|
# @return [Boolean] True if parsed correctly. False otherwise
|
165
168
|
def parse_first_line(line)
|
166
169
|
line_parts = line.match(PATH)
|
167
|
-
|
170
|
+
raise WebSocket::Error::Handshake::InvalidHeader unless line_parts
|
168
171
|
method = line_parts[1].strip
|
169
|
-
|
172
|
+
raise WebSocket::Error::Handshake::GetRequestRequired unless method == 'GET'
|
170
173
|
|
171
174
|
resource_name = line_parts[2].strip
|
172
175
|
@path, @query = resource_name.split('?', 2)
|
@@ -0,0 +1,12 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module WebSocket
|
4
|
+
module NiceInspect
|
5
|
+
# Recreate inspect as #to_s will be overwritten
|
6
|
+
def inspect
|
7
|
+
vars = instance_variables.map { |v| "#{v}=#{instance_variable_get(v).inspect}" }.join(', ')
|
8
|
+
insp = Kernel.format("#{self.class}:0x%08x", __id__)
|
9
|
+
"<#{insp} #{vars}>"
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
data/lib/websocket/version.rb
CHANGED
@@ -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 03' do
|
7
|
+
subject { frame }
|
8
|
+
|
5
9
|
let(:version) { 3 }
|
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) { "\x01\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 03' 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 03' 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 03' 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 text frame with continuation' do
|
@@ -49,15 +52,15 @@ RSpec.describe 'Incoming frame draft 03' do
|
|
49
52
|
let(:frame_type) { :text }
|
50
53
|
let(:decoded_text) { 'Hello' }
|
51
54
|
|
52
|
-
|
55
|
+
it_behaves_like 'valid_incoming_frame'
|
53
56
|
end
|
54
57
|
|
55
58
|
context 'should properly decode text frame in between of continuation' do
|
56
59
|
let(:encoded_text) { "\x84\x03Hel\x03\x03abc\x00\x02lo" }
|
57
|
-
let(:frame_type) { [
|
58
|
-
let(:decoded_text) { %w
|
60
|
+
let(:frame_type) { %i[pong text] }
|
61
|
+
let(:decoded_text) { %w[abc Hello] }
|
59
62
|
|
60
|
-
|
63
|
+
it_behaves_like 'valid_incoming_frame'
|
61
64
|
end
|
62
65
|
|
63
66
|
context 'should not return unfinished more frame' do
|
@@ -65,7 +68,7 @@ RSpec.describe 'Incoming frame draft 03' do
|
|
65
68
|
let(:frame_type) { :pong }
|
66
69
|
let(:decoded_text) { 'abc' }
|
67
70
|
|
68
|
-
|
71
|
+
it_behaves_like 'valid_incoming_frame'
|
69
72
|
end
|
70
73
|
|
71
74
|
context 'should properly decode 256 bytes binary frame' do
|
@@ -73,7 +76,7 @@ RSpec.describe 'Incoming frame draft 03' do
|
|
73
76
|
let(:frame_type) { :binary }
|
74
77
|
let(:decoded_text) { 'a' * 256 }
|
75
78
|
|
76
|
-
|
79
|
+
it_behaves_like 'valid_incoming_frame'
|
77
80
|
end
|
78
81
|
|
79
82
|
context 'should properly decode 64KiB binary frame' do
|
@@ -81,14 +84,14 @@ RSpec.describe 'Incoming frame draft 03' do
|
|
81
84
|
let(:frame_type) { :binary }
|
82
85
|
let(:decoded_text) { 'a' * 65_536 }
|
83
86
|
|
84
|
-
|
87
|
+
it_behaves_like 'valid_incoming_frame'
|
85
88
|
end
|
86
89
|
|
87
90
|
context 'should wait with incomplete frame' do
|
88
91
|
let(:encoded_text) { "\x04\x06Hello" }
|
89
92
|
let(:decoded_text) { nil }
|
90
93
|
|
91
|
-
|
94
|
+
it_behaves_like 'valid_incoming_frame'
|
92
95
|
end
|
93
96
|
|
94
97
|
context 'should raise error with invalid opcode' do
|
@@ -96,7 +99,7 @@ RSpec.describe 'Incoming frame draft 03' do
|
|
96
99
|
let(:decoded_text) { nil }
|
97
100
|
let(:error) { WebSocket::Error::Frame::UnknownOpcode }
|
98
101
|
|
99
|
-
|
102
|
+
it_behaves_like 'valid_incoming_frame'
|
100
103
|
end
|
101
104
|
|
102
105
|
context 'should raise error with too long frame' do
|
@@ -104,7 +107,7 @@ RSpec.describe 'Incoming frame draft 03' do
|
|
104
107
|
let(:decoded_text) { nil }
|
105
108
|
let(:error) { WebSocket::Error::Frame::TooLong }
|
106
109
|
|
107
|
-
|
110
|
+
it_behaves_like 'valid_incoming_frame'
|
108
111
|
end
|
109
112
|
|
110
113
|
context 'should raise error with continuation frame without more frame earlier' do
|
@@ -112,6 +115,6 @@ RSpec.describe 'Incoming frame draft 03' do
|
|
112
115
|
let(:decoded_text) { nil }
|
113
116
|
let(:error) { WebSocket::Error::Frame::UnexpectedContinuationFrame }
|
114
117
|
|
115
|
-
|
118
|
+
it_behaves_like 'valid_incoming_frame'
|
116
119
|
end
|
117
120
|
end
|
@@ -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 04' do
|
7
|
+
subject { frame }
|
8
|
+
|
5
9
|
let(:version) { 4 }
|
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 04' 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 04' 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 04' 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 text frame with continuation' do
|
@@ -49,15 +52,15 @@ RSpec.describe 'Incoming frame draft 04' do
|
|
49
52
|
let(:frame_type) { :text }
|
50
53
|
let(:decoded_text) { 'Hello' }
|
51
54
|
|
52
|
-
|
55
|
+
it_behaves_like 'valid_incoming_frame'
|
53
56
|
end
|
54
57
|
|
55
58
|
context 'should properly decode text frame in between of continuation' do
|
56
59
|
let(:encoded_text) { "\x04\x03Hel\x83\x03abc\x80\x02lo" }
|
57
|
-
let(:frame_type) { [
|
58
|
-
let(:decoded_text) { %w
|
60
|
+
let(:frame_type) { %i[pong text] }
|
61
|
+
let(:decoded_text) { %w[abc Hello] }
|
59
62
|
|
60
|
-
|
63
|
+
it_behaves_like 'valid_incoming_frame'
|
61
64
|
end
|
62
65
|
|
63
66
|
context 'should not return unfinished more frame' do
|
@@ -65,7 +68,7 @@ RSpec.describe 'Incoming frame draft 04' do
|
|
65
68
|
let(:frame_type) { :pong }
|
66
69
|
let(:decoded_text) { 'abc' }
|
67
70
|
|
68
|
-
|
71
|
+
it_behaves_like 'valid_incoming_frame'
|
69
72
|
end
|
70
73
|
|
71
74
|
context 'should properly decode 256 bytes binary frame' do
|
@@ -73,7 +76,7 @@ RSpec.describe 'Incoming frame draft 04' do
|
|
73
76
|
let(:frame_type) { :binary }
|
74
77
|
let(:decoded_text) { 'a' * 256 }
|
75
78
|
|
76
|
-
|
79
|
+
it_behaves_like 'valid_incoming_frame'
|
77
80
|
end
|
78
81
|
|
79
82
|
context 'should properly decode 64KiB binary frame' do
|
@@ -81,14 +84,14 @@ RSpec.describe 'Incoming frame draft 04' do
|
|
81
84
|
let(:frame_type) { :binary }
|
82
85
|
let(:decoded_text) { 'a' * 65_536 }
|
83
86
|
|
84
|
-
|
87
|
+
it_behaves_like 'valid_incoming_frame'
|
85
88
|
end
|
86
89
|
|
87
90
|
context 'should wait with incomplete frame' do
|
88
91
|
let(:encoded_text) { "\x84\x06Hello" }
|
89
92
|
let(:decoded_text) { nil }
|
90
93
|
|
91
|
-
|
94
|
+
it_behaves_like 'valid_incoming_frame'
|
92
95
|
end
|
93
96
|
|
94
97
|
context 'should raise error with invalid opcode' do
|
@@ -96,7 +99,7 @@ RSpec.describe 'Incoming frame draft 04' do
|
|
96
99
|
let(:decoded_text) { nil }
|
97
100
|
let(:error) { WebSocket::Error::Frame::UnknownOpcode }
|
98
101
|
|
99
|
-
|
102
|
+
it_behaves_like 'valid_incoming_frame'
|
100
103
|
end
|
101
104
|
|
102
105
|
context 'should raise error with too long frame' do
|
@@ -104,7 +107,7 @@ RSpec.describe 'Incoming frame draft 04' do
|
|
104
107
|
let(:decoded_text) { nil }
|
105
108
|
let(:error) { WebSocket::Error::Frame::TooLong }
|
106
109
|
|
107
|
-
|
110
|
+
it_behaves_like 'valid_incoming_frame'
|
108
111
|
end
|
109
112
|
|
110
113
|
context 'should raise error with continuation frame without more frame earlier' do
|
@@ -112,6 +115,6 @@ RSpec.describe 'Incoming frame draft 04' do
|
|
112
115
|
let(:decoded_text) { nil }
|
113
116
|
let(:error) { WebSocket::Error::Frame::UnexpectedContinuationFrame }
|
114
117
|
|
115
|
-
|
118
|
+
it_behaves_like 'valid_incoming_frame'
|
116
119
|
end
|
117
120
|
end
|