websocket 1.2.3 → 1.2.9

Sign up to get free protection for your applications and to get access to all the features.
Files changed (76) hide show
  1. checksums.yaml +5 -5
  2. data/.codeclimate.yml +17 -0
  3. data/.github/workflows/publish.yml +17 -0
  4. data/.rubocop.yml +35 -3
  5. data/.travis.yml +14 -7
  6. data/CHANGELOG.md +24 -0
  7. data/Gemfile +12 -4
  8. data/README.md +3 -2
  9. data/Rakefile +8 -3
  10. data/lib/websocket.rb +4 -1
  11. data/lib/websocket/error.rb +8 -0
  12. data/lib/websocket/exception_handler.rb +3 -1
  13. data/lib/websocket/frame.rb +2 -0
  14. data/lib/websocket/frame/base.rb +5 -9
  15. data/lib/websocket/frame/data.rb +5 -2
  16. data/lib/websocket/frame/handler.rb +2 -0
  17. data/lib/websocket/frame/handler/base.rb +6 -4
  18. data/lib/websocket/frame/handler/handler03.rb +23 -16
  19. data/lib/websocket/frame/handler/handler04.rb +1 -0
  20. data/lib/websocket/frame/handler/handler05.rb +1 -0
  21. data/lib/websocket/frame/handler/handler07.rb +10 -9
  22. data/lib/websocket/frame/handler/handler75.rb +8 -7
  23. data/lib/websocket/frame/incoming.rb +2 -0
  24. data/lib/websocket/frame/incoming/client.rb +2 -0
  25. data/lib/websocket/frame/incoming/server.rb +2 -0
  26. data/lib/websocket/frame/outgoing.rb +3 -1
  27. data/lib/websocket/frame/outgoing/client.rb +2 -0
  28. data/lib/websocket/frame/outgoing/server.rb +2 -0
  29. data/lib/websocket/handshake.rb +2 -0
  30. data/lib/websocket/handshake/base.rb +26 -13
  31. data/lib/websocket/handshake/client.rb +17 -14
  32. data/lib/websocket/handshake/handler.rb +2 -0
  33. data/lib/websocket/handshake/handler/base.rb +2 -0
  34. data/lib/websocket/handshake/handler/client.rb +11 -0
  35. data/lib/websocket/handshake/handler/client01.rb +2 -0
  36. data/lib/websocket/handshake/handler/client04.rb +15 -4
  37. data/lib/websocket/handshake/handler/client11.rb +2 -0
  38. data/lib/websocket/handshake/handler/client75.rb +18 -2
  39. data/lib/websocket/handshake/handler/client76.rb +11 -5
  40. data/lib/websocket/handshake/handler/server.rb +2 -0
  41. data/lib/websocket/handshake/handler/server04.rb +12 -4
  42. data/lib/websocket/handshake/handler/server75.rb +21 -5
  43. data/lib/websocket/handshake/handler/server76.rb +14 -16
  44. data/lib/websocket/handshake/server.rb +7 -4
  45. data/lib/websocket/nice_inspect.rb +12 -0
  46. data/lib/websocket/version.rb +3 -1
  47. data/spec/frame/incoming_03_spec.rb +20 -17
  48. data/spec/frame/incoming_04_spec.rb +20 -17
  49. data/spec/frame/incoming_05_spec.rb +22 -19
  50. data/spec/frame/incoming_07_spec.rb +24 -21
  51. data/spec/frame/incoming_75_spec.rb +13 -10
  52. data/spec/frame/incoming_common_spec.rb +18 -8
  53. data/spec/frame/masking_spec.rb +3 -1
  54. data/spec/frame/outgoing_03_spec.rb +13 -10
  55. data/spec/frame/outgoing_04_spec.rb +13 -10
  56. data/spec/frame/outgoing_05_spec.rb +12 -9
  57. data/spec/frame/outgoing_07_spec.rb +13 -10
  58. data/spec/frame/outgoing_75_spec.rb +8 -5
  59. data/spec/frame/outgoing_common_spec.rb +11 -4
  60. data/spec/handshake/client_04_spec.rb +46 -3
  61. data/spec/handshake/client_11_spec.rb +5 -3
  62. data/spec/handshake/client_75_spec.rb +28 -1
  63. data/spec/handshake/client_76_spec.rb +30 -3
  64. data/spec/handshake/server_04_spec.rb +37 -4
  65. data/spec/handshake/server_75_spec.rb +25 -1
  66. data/spec/handshake/server_76_spec.rb +33 -9
  67. data/spec/spec_helper.rb +2 -2
  68. data/spec/support/all_client_drafts.rb +23 -21
  69. data/spec/support/all_server_drafts.rb +21 -16
  70. data/spec/support/frames_base.rb +2 -0
  71. data/spec/support/handshake_requests.rb +19 -17
  72. data/spec/support/incoming_frames.rb +46 -25
  73. data/spec/support/outgoing_frames.rb +30 -8
  74. data/spec/support/overwrites.rb +2 -0
  75. data/websocket.gemspec +4 -1
  76. metadata +7 -5
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module WebSocket
2
4
  module Frame
3
5
  class Base
@@ -1,27 +1,29 @@
1
+ # frozen_string_literal: true
2
+
1
3
  def client_handshake_75(args = {})
2
- <<-EOF
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
- EOF
11
+ REQUEST
10
12
  end
11
13
 
12
14
  def server_handshake_75(args = {})
13
- <<-EOF
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
- EOF
22
+ REQUEST
21
23
  end
22
24
 
23
25
  def client_handshake_76(args = {})
24
- request = <<-EOF
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
- EOF
36
+ REQUEST
35
37
  request[0..-2]
36
38
  end
37
39
 
38
40
  def server_handshake_76(args = {})
39
- request = <<-EOF
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
- EOF
49
+ REQUEST
48
50
  request[0..-2]
49
51
  end
50
52
 
51
53
  def client_handshake_04(args = {})
52
- <<-EOF
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
- EOF
63
+ REQUEST
62
64
  end
63
65
 
64
66
  def server_handshake_04(args = {})
65
- <<-EOF
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
- EOF
73
+ REQUEST
72
74
  end
73
75
 
74
76
  def client_handshake_11(args = {})
75
- <<-EOF
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
- EOF
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
- its(:class) { is_expected.to eql(WebSocket::Frame::Incoming) }
6
- its(:data) { is_expected.to eql(encoded_text || '') }
7
- its(:version) { is_expected.to eql(version) }
8
- its(:type) { is_expected.to be_nil }
9
- its(:decoded?) { is_expected.to be false }
10
- its(:to_s) { is_expected.to eql(encoded_text || '') }
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 'should have specified number of returned frames' do
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 'should return valid decoded frame for each specified decoded texts' do
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(:each) { WebSocket.should_raise = true }
38
- after(:each) { WebSocket.should_raise = false }
39
-
40
- it 'should have specified number of returned frames' do
41
- expect do
42
- decoded_text_array.each_with_index do |da, index|
43
- n = subject.next
44
- expect(n).not_to be_nil, "Should return frame for #{da}, #{frame_type_array[index]}"
45
- expect(n.class).to eql(WebSocket::Frame::Incoming), "Should be WebSocket::Frame::Incoming, #{n} received instead"
46
- end
47
- expect(subject.next).to be_nil
48
- if error.is_a?(Class)
49
- expect(subject.error).to eql(error.new.message)
50
- else
51
- expect(subject.error).to eql(error)
52
- end
53
- end.to raise_error(error) if error
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
- its(:class) { is_expected.to eql(WebSocket::Frame::Outgoing) }
3
- its(:version) { is_expected.to eql(version) }
4
- its(:type) { is_expected.to eql(frame_type) }
5
- its(:data) { is_expected.to eql(decoded_text) }
6
- its(:to_s) { is_expected.to eql(encoded_text) }
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(:each) { subject.to_s }
10
- its(:error) { is_expected.to eql(error) }
11
- its(:require_sending?) { is_expected.to eql(require_sending) }
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
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module WebSocket
2
4
  module Handshake
3
5
  class Base
@@ -1,4 +1,5 @@
1
- # -*- encoding: utf-8 -*-
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.3
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: 2016-04-05 00:00:00.000000000 Z
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
- rubyforge_project:
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