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
data/spec/support/frames_base.rb
CHANGED
@@ -1,27 +1,29 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
def client_handshake_75(args = {})
|
2
|
-
<<-
|
4
|
+
<<-REQUEST
|
3
5
|
GET #{args[:path] || '/demo'}#{"?#{args[:query]}" if args[:query]} HTTP/1.1\r
|
4
6
|
Upgrade: WebSocket\r
|
5
7
|
Connection: Upgrade\r
|
6
8
|
Host: #{args[:host] || 'example.com'}#{":#{args[:port]}" if args[:port]}\r
|
7
9
|
Origin: http://example.com\r
|
8
10
|
#{(args[:headers] || {}).map { |key, value| "#{key}: #{value}\r\n" }.join('')}\r
|
9
|
-
|
11
|
+
REQUEST
|
10
12
|
end
|
11
13
|
|
12
14
|
def server_handshake_75(args = {})
|
13
|
-
<<-
|
15
|
+
<<-REQUEST
|
14
16
|
HTTP/1.1 101 Web Socket Protocol Handshake\r
|
15
17
|
Upgrade: WebSocket\r
|
16
18
|
Connection: Upgrade\r
|
17
|
-
WebSocket-Origin: http://example.com\r
|
19
|
+
#{(args[:headers] || {}).map { |key, value| "#{key}: #{value}\r\n" }.join('')}WebSocket-Origin: http://example.com\r
|
18
20
|
WebSocket-Location: ws#{args[:secure] ? 's' : ''}://#{args[:host] || 'example.com'}#{":#{args[:port]}" if args[:port]}#{args[:path] || '/demo'}\r
|
19
21
|
\r
|
20
|
-
|
22
|
+
REQUEST
|
21
23
|
end
|
22
24
|
|
23
25
|
def client_handshake_76(args = {})
|
24
|
-
request = <<-
|
26
|
+
request = <<-REQUEST
|
25
27
|
GET #{args[:path] || '/demo'}#{"?#{args[:query]}" if args[:query]} HTTP/1.1\r
|
26
28
|
Upgrade: WebSocket\r
|
27
29
|
Connection: Upgrade\r
|
@@ -31,25 +33,25 @@ Origin: http://example.com\r
|
|
31
33
|
Sec-WebSocket-Key2: #{args[:key2] || '12998 5 Y3 1 .P00'}\r
|
32
34
|
\r
|
33
35
|
#{args[:key3] || '^n:ds[4U'}
|
34
|
-
|
36
|
+
REQUEST
|
35
37
|
request[0..-2]
|
36
38
|
end
|
37
39
|
|
38
40
|
def server_handshake_76(args = {})
|
39
|
-
request = <<-
|
41
|
+
request = <<-REQUEST
|
40
42
|
HTTP/1.1 101 WebSocket Protocol Handshake\r
|
41
43
|
Upgrade: WebSocket\r
|
42
44
|
Connection: Upgrade\r
|
43
|
-
Sec-WebSocket-Origin: http://example.com\r
|
45
|
+
#{(args[:headers] || {}).map { |key, value| "#{key}: #{value}\r\n" }.join('')}Sec-WebSocket-Origin: http://example.com\r
|
44
46
|
Sec-WebSocket-Location: ws#{args[:secure] ? 's' : ''}://#{args[:host] || 'example.com'}#{":#{args[:port]}" if args[:port]}#{args[:path] || '/demo'}\r
|
45
47
|
\r
|
46
48
|
#{args[:challenge] || "8jKS'y:G*Co,Wxa-"}
|
47
|
-
|
49
|
+
REQUEST
|
48
50
|
request[0..-2]
|
49
51
|
end
|
50
52
|
|
51
53
|
def client_handshake_04(args = {})
|
52
|
-
<<-
|
54
|
+
<<-REQUEST
|
53
55
|
GET #{args[:path] || '/demo'}#{"?#{args[:query]}" if args[:query]} HTTP/1.1\r
|
54
56
|
Upgrade: websocket\r
|
55
57
|
Connection: Upgrade\r
|
@@ -58,21 +60,21 @@ Host: #{args[:host] || 'example.com'}#{":#{args[:port]}" if args[:port]}\r
|
|
58
60
|
Sec-WebSocket-Version: #{args[:version] || '4'}\r
|
59
61
|
Sec-WebSocket-Key: #{args[:key] || 'dGhlIHNhbXBsZSBub25jZQ=='}\r
|
60
62
|
\r
|
61
|
-
|
63
|
+
REQUEST
|
62
64
|
end
|
63
65
|
|
64
66
|
def server_handshake_04(args = {})
|
65
|
-
<<-
|
67
|
+
<<-REQUEST
|
66
68
|
HTTP/1.1 101 Switching Protocols\r
|
67
69
|
Upgrade: websocket\r
|
68
70
|
Connection: Upgrade\r
|
69
|
-
Sec-WebSocket-Accept: #{args[:accept] || 's3pPLMBiTxaQ9kYGzzhZRbK+xOo='}\r
|
71
|
+
#{(args[:headers] || {}).map { |key, value| "#{key}: #{value}\r\n" }.join('')}Sec-WebSocket-Accept: #{args[:accept] || 's3pPLMBiTxaQ9kYGzzhZRbK+xOo='}\r
|
70
72
|
\r
|
71
|
-
|
73
|
+
REQUEST
|
72
74
|
end
|
73
75
|
|
74
76
|
def client_handshake_11(args = {})
|
75
|
-
<<-
|
77
|
+
<<-REQUEST
|
76
78
|
GET #{args[:path] || '/demo'}#{"?#{args[:query]}" if args[:query]} HTTP/1.1\r
|
77
79
|
Upgrade: websocket\r
|
78
80
|
Connection: Upgrade\r
|
@@ -81,7 +83,7 @@ Host: #{args[:host] || 'example.com'}#{":#{args[:port]}" if args[:port]}\r
|
|
81
83
|
Sec-WebSocket-Version: #{args[:version] || '4'}\r
|
82
84
|
Sec-WebSocket-Key: #{args[:key] || 'dGhlIHNhbXBsZSBub25jZQ=='}\r
|
83
85
|
\r
|
84
|
-
|
86
|
+
REQUEST
|
85
87
|
end
|
86
88
|
|
87
89
|
def server_handshake_11(args = {})
|
@@ -1,15 +1,34 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
RSpec.shared_examples_for 'valid_incoming_frame' do
|
2
4
|
let(:decoded_text_array) { Array(decoded_text) }
|
3
5
|
let(:frame_type_array) { Array(frame_type) }
|
4
6
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
7
|
+
it 'is incoming frame' do
|
8
|
+
expect(subject.class).to be WebSocket::Frame::Incoming
|
9
|
+
end
|
10
|
+
|
11
|
+
it 'is in proper verions' do
|
12
|
+
expect(subject.version).to eql version
|
13
|
+
end
|
11
14
|
|
12
|
-
it '
|
15
|
+
it 'does not have type set' do
|
16
|
+
expect(subject.type).to be nil
|
17
|
+
end
|
18
|
+
|
19
|
+
it 'is not decoded' do
|
20
|
+
expect(subject.decoded?).to be false
|
21
|
+
end
|
22
|
+
|
23
|
+
it 'contains encoded data' do
|
24
|
+
expect(subject.data).to eql(encoded_text || '')
|
25
|
+
end
|
26
|
+
|
27
|
+
it 'returns data as to_s' do
|
28
|
+
expect(subject.to_s).to eql(encoded_text || '')
|
29
|
+
end
|
30
|
+
|
31
|
+
it 'has specified number of returned frames' do
|
13
32
|
decoded_text_array.each_with_index do |da, index|
|
14
33
|
n = subject.next
|
15
34
|
expect(n).not_to be_nil, "Should return frame for #{da}, #{frame_type_array[index]}"
|
@@ -23,7 +42,7 @@ RSpec.shared_examples_for 'valid_incoming_frame' do
|
|
23
42
|
end
|
24
43
|
end
|
25
44
|
|
26
|
-
it '
|
45
|
+
it 'returns valid decoded frame for each specified decoded texts' do
|
27
46
|
decoded_text_array.each_with_index do |da, index|
|
28
47
|
f = subject.next
|
29
48
|
expect(f.decoded?).to be true
|
@@ -34,23 +53,25 @@ RSpec.shared_examples_for 'valid_incoming_frame' do
|
|
34
53
|
end
|
35
54
|
|
36
55
|
context 'with raising' do
|
37
|
-
before
|
38
|
-
after
|
39
|
-
|
40
|
-
it '
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
56
|
+
before { WebSocket.should_raise = true }
|
57
|
+
after { WebSocket.should_raise = false }
|
58
|
+
|
59
|
+
it 'has specified number of returned frames' do
|
60
|
+
if error
|
61
|
+
expect do
|
62
|
+
decoded_text_array.each_with_index do |da, index|
|
63
|
+
n = subject.next
|
64
|
+
expect(n).not_to be_nil, "Should return frame for #{da}, #{frame_type_array[index]}"
|
65
|
+
expect(n.class).to eql(WebSocket::Frame::Incoming), "Should be WebSocket::Frame::Incoming, #{n} received instead"
|
66
|
+
end
|
67
|
+
expect(subject.next).to be_nil
|
68
|
+
if error.is_a?(Class)
|
69
|
+
expect(subject.error).to eql(error.new.message)
|
70
|
+
else
|
71
|
+
expect(subject.error).to eql(error)
|
72
|
+
end
|
73
|
+
end.to raise_error(error)
|
74
|
+
end
|
54
75
|
end
|
55
76
|
end
|
56
77
|
end
|
@@ -1,13 +1,35 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
RSpec.shared_examples_for 'valid_outgoing_frame' do
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
4
|
+
it 'is outgoing frame' do
|
5
|
+
expect(subject.class).to be WebSocket::Frame::Outgoing
|
6
|
+
end
|
7
|
+
|
8
|
+
it 'is in proper verions' do
|
9
|
+
expect(subject.version).to eql version
|
10
|
+
end
|
11
|
+
|
12
|
+
it 'has proper type set' do
|
13
|
+
expect(subject.type).to eql frame_type
|
14
|
+
end
|
15
|
+
|
16
|
+
it 'contains decoded data' do
|
17
|
+
expect(subject.data).to eql(decoded_text)
|
18
|
+
end
|
19
|
+
|
20
|
+
it 'returns encoded data as to_s' do
|
21
|
+
expect(subject.to_s).to eql(encoded_text)
|
22
|
+
end
|
7
23
|
|
8
24
|
context 'after parsing' do
|
9
|
-
before
|
10
|
-
|
11
|
-
|
25
|
+
before { subject.to_s }
|
26
|
+
|
27
|
+
it 'has valid errors set' do
|
28
|
+
expect(subject.error).to eql error
|
29
|
+
end
|
30
|
+
|
31
|
+
it 'requires sending' do
|
32
|
+
expect(subject.require_sending?).to eql require_sending
|
33
|
+
end
|
12
34
|
end
|
13
35
|
end
|
data/spec/support/overwrites.rb
CHANGED
data/websocket.gemspec
CHANGED
@@ -1,4 +1,5 @@
|
|
1
|
-
#
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
2
3
|
$LOAD_PATH.push File.expand_path('../lib', __FILE__)
|
3
4
|
require 'websocket/version'
|
4
5
|
|
@@ -17,4 +18,6 @@ Gem::Specification.new do |s|
|
|
17
18
|
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
18
19
|
s.executables = `git ls-files -- bin/*`.split("\n").map { |f| File.basename(f) }
|
19
20
|
s.require_paths = ['lib']
|
21
|
+
|
22
|
+
s.required_ruby_version = '>= 2.0'
|
20
23
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: websocket
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.2.
|
4
|
+
version: 1.2.9
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Bernard Potocki
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-12-18 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Universal Ruby library to handle WebSocket protocol
|
14
14
|
email:
|
@@ -17,6 +17,8 @@ executables: []
|
|
17
17
|
extensions: []
|
18
18
|
extra_rdoc_files: []
|
19
19
|
files:
|
20
|
+
- ".codeclimate.yml"
|
21
|
+
- ".github/workflows/publish.yml"
|
20
22
|
- ".gitignore"
|
21
23
|
- ".rubocop.yml"
|
22
24
|
- ".travis.yml"
|
@@ -59,6 +61,7 @@ files:
|
|
59
61
|
- lib/websocket/handshake/handler/server75.rb
|
60
62
|
- lib/websocket/handshake/handler/server76.rb
|
61
63
|
- lib/websocket/handshake/server.rb
|
64
|
+
- lib/websocket/nice_inspect.rb
|
62
65
|
- lib/websocket/version.rb
|
63
66
|
- spec/frame/incoming_03_spec.rb
|
64
67
|
- spec/frame/incoming_04_spec.rb
|
@@ -101,15 +104,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
101
104
|
requirements:
|
102
105
|
- - ">="
|
103
106
|
- !ruby/object:Gem::Version
|
104
|
-
version: '0'
|
107
|
+
version: '2.0'
|
105
108
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
106
109
|
requirements:
|
107
110
|
- - ">="
|
108
111
|
- !ruby/object:Gem::Version
|
109
112
|
version: '0'
|
110
113
|
requirements: []
|
111
|
-
|
112
|
-
rubygems_version: 2.5.1
|
114
|
+
rubygems_version: 3.0.3
|
113
115
|
signing_key:
|
114
116
|
specification_version: 4
|
115
117
|
summary: Universal Ruby library to handle WebSocket protocol
|