websocket 1.2.4 → 1.2.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (49) hide show
  1. checksums.yaml +4 -4
  2. data/.codeclimate.yml +16 -0
  3. data/.rubocop.yml +18 -3
  4. data/.travis.yml +6 -8
  5. data/CHANGELOG.md +4 -0
  6. data/Gemfile +10 -0
  7. data/README.md +2 -2
  8. data/Rakefile +1 -1
  9. data/lib/websocket.rb +1 -0
  10. data/lib/websocket/frame/base.rb +1 -7
  11. data/lib/websocket/frame/handler/base.rb +2 -2
  12. data/lib/websocket/frame/handler/handler03.rb +2 -1
  13. data/lib/websocket/frame/handler/handler75.rb +1 -1
  14. data/lib/websocket/handshake/base.rb +1 -7
  15. data/lib/websocket/handshake/handler/client.rb +9 -0
  16. data/lib/websocket/handshake/handler/client04.rb +6 -7
  17. data/lib/websocket/handshake/handler/client75.rb +6 -7
  18. data/lib/websocket/handshake/handler/client76.rb +2 -7
  19. data/lib/websocket/handshake/handler/server75.rb +13 -5
  20. data/lib/websocket/handshake/handler/server76.rb +9 -17
  21. data/lib/websocket/handshake/server.rb +1 -1
  22. data/lib/websocket/nice_inspect.rb +10 -0
  23. data/lib/websocket/version.rb +1 -1
  24. data/spec/frame/incoming_03_spec.rb +3 -2
  25. data/spec/frame/incoming_04_spec.rb +3 -2
  26. data/spec/frame/incoming_05_spec.rb +3 -2
  27. data/spec/frame/incoming_07_spec.rb +3 -2
  28. data/spec/frame/incoming_75_spec.rb +3 -2
  29. data/spec/frame/incoming_common_spec.rb +17 -8
  30. data/spec/frame/masking_spec.rb +2 -1
  31. data/spec/frame/outgoing_03_spec.rb +2 -1
  32. data/spec/frame/outgoing_04_spec.rb +2 -1
  33. data/spec/frame/outgoing_05_spec.rb +2 -1
  34. data/spec/frame/outgoing_07_spec.rb +2 -1
  35. data/spec/frame/outgoing_75_spec.rb +2 -1
  36. data/spec/frame/outgoing_common_spec.rb +10 -4
  37. data/spec/handshake/client_04_spec.rb +3 -3
  38. data/spec/handshake/client_11_spec.rb +2 -2
  39. data/spec/handshake/client_75_spec.rb +1 -1
  40. data/spec/handshake/client_76_spec.rb +3 -3
  41. data/spec/handshake/server_04_spec.rb +2 -2
  42. data/spec/handshake/server_76_spec.rb +8 -8
  43. data/spec/spec_helper.rb +0 -2
  44. data/spec/support/all_client_drafts.rb +21 -21
  45. data/spec/support/all_server_drafts.rb +19 -16
  46. data/spec/support/incoming_frames.rb +29 -12
  47. data/spec/support/outgoing_frames.rb +28 -8
  48. data/websocket.gemspec +2 -4
  49. metadata +7 -61
@@ -1,3 +1,5 @@
1
+ require 'webrick'
2
+
1
3
  RSpec.shared_examples_for 'all server drafts' do
2
4
  def validate_request
3
5
  handshake << client_request
@@ -8,7 +10,7 @@ RSpec.shared_examples_for 'all server drafts' do
8
10
  expect(handshake.to_s).to eql(server_response)
9
11
  end
10
12
 
11
- it 'should be valid' do
13
+ it 'is valid' do
12
14
  handshake << client_request
13
15
 
14
16
  expect(handshake.error).to be_nil
@@ -16,86 +18,87 @@ RSpec.shared_examples_for 'all server drafts' do
16
18
  expect(handshake).to be_valid
17
19
  end
18
20
 
19
- it 'should return valid version' do
21
+ it 'returns valid version' do
20
22
  handshake << client_request
21
23
 
22
24
  expect(handshake.version).to eql(version)
23
25
  end
24
26
 
25
- it 'should return valid host' do
27
+ it 'returns valid host' do
26
28
  @request_params = { host: 'www.test.cc' }
27
29
  handshake << client_request
28
30
 
29
31
  expect(handshake.host).to eql('www.test.cc')
30
32
  end
31
33
 
32
- it 'should return valid path' do
34
+ it 'returns valid path' do
33
35
  @request_params = { path: '/custom' }
34
36
  handshake << client_request
35
37
 
36
38
  expect(handshake.path).to eql('/custom')
37
39
  end
38
40
 
39
- it 'should return valid query' do
41
+ it 'returns valid query' do
40
42
  @request_params = { path: '/custom?aaa=bbb' }
41
43
  handshake << client_request
42
44
 
43
45
  expect(handshake.query).to eql('aaa=bbb')
44
46
  end
45
47
 
46
- it 'should return valid port' do
48
+ it 'returns valid port' do
47
49
  @request_params = { port: 123 }
48
50
  handshake << client_request
49
51
 
50
52
  expect(handshake.port).to eql('123')
51
53
  end
52
54
 
53
- it 'should return valid response' do
55
+ it 'returns valid response' do
54
56
  validate_request
55
57
  end
56
58
 
57
- it 'should allow custom path' do
59
+ it 'allows custom path' do
58
60
  @request_params = { path: '/custom' }
59
61
  validate_request
60
62
  end
61
63
 
62
- it 'should allow query in path' do
64
+ it 'allows query in path' do
63
65
  @request_params = { path: '/custom?test=true' }
64
66
  validate_request
65
67
  end
66
68
 
67
- it 'should allow custom port' do
69
+ it 'allows custom port' do
68
70
  @request_params = { port: 123 }
69
71
  validate_request
70
72
  end
71
73
 
72
- it 'should recognize unfinished requests' do
74
+ it 'recognizes unfinished requests' do
73
75
  handshake << client_request[0..-10]
74
76
 
75
77
  expect(handshake).not_to be_finished
76
78
  expect(handshake).not_to be_valid
77
79
  end
78
80
 
79
- it 'should disallow requests with invalid request method' do
81
+ it 'disallows requests with invalid request method' do
80
82
  handshake << client_request.gsub('GET', 'POST')
81
83
 
82
84
  expect(handshake).to be_finished
83
85
  expect(handshake).not_to be_valid
84
- expect(handshake.error).to eql(:get_request_required)
86
+ expect(handshake.error).to be(:get_request_required)
85
87
  end
86
88
 
87
- it 'should parse a rack request' do
89
+ it 'parses a rack request' do
88
90
  request = WEBrick::HTTPRequest.new(ServerSoftware: 'rspec')
89
91
  expect(request.parse(StringIO.new(client_request))).to be true
90
92
  rest = client_request.slice((request.to_s.length..-1))
91
93
 
92
94
  handshake.from_rack(request.meta_vars.merge(
93
- 'rack.input' => StringIO.new(rest)
95
+ 'rack.input' => StringIO.new(rest),
96
+ :random_key => :random_value
94
97
  ))
95
98
  validate_request
96
99
  end
97
100
 
98
- it 'should parse a hash request' do
101
+ it 'parses a hash request' do
99
102
  request = WEBrick::HTTPRequest.new(ServerSoftware: 'rspec')
100
103
  expect(request.parse(StringIO.new(client_request))).to be true
101
104
  body = client_request.slice((request.to_s.length..-1))
@@ -2,14 +2,31 @@ RSpec.shared_examples_for 'valid_incoming_frame' do
2
2
  let(:decoded_text_array) { Array(decoded_text) }
3
3
  let(:frame_type_array) { Array(frame_type) }
4
4
 
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 || '') }
11
-
12
- it 'should have specified number of returned frames' do
5
+ it 'is incoming frame' do
6
+ expect(subject.class).to be WebSocket::Frame::Incoming
7
+ end
8
+
9
+ it 'is in proper verions' do
10
+ expect(subject.version).to eql version
11
+ end
12
+
13
+ it 'does not have type set' do
14
+ expect(subject.type).to be nil
15
+ end
16
+
17
+ it 'is not decoded' do
18
+ expect(subject.decoded?).to be false
19
+ end
20
+
21
+ it 'contains encoded data' do
22
+ expect(subject.data).to eql(encoded_text || '')
23
+ end
24
+
25
+ it 'returns data as to_s' do
26
+ expect(subject.to_s).to eql(encoded_text || '')
27
+ end
28
+
29
+ it 'has specified number of returned frames' do
13
30
  decoded_text_array.each_with_index do |da, index|
14
31
  n = subject.next
15
32
  expect(n).not_to be_nil, "Should return frame for #{da}, #{frame_type_array[index]}"
@@ -23,7 +40,7 @@ RSpec.shared_examples_for 'valid_incoming_frame' do
23
40
  end
24
41
  end
25
42
 
26
- it 'should return valid decoded frame for each specified decoded texts' do
43
+ it 'returns valid decoded frame for each specified decoded texts' do
27
44
  decoded_text_array.each_with_index do |da, index|
28
45
  f = subject.next
29
46
  expect(f.decoded?).to be true
@@ -34,10 +51,10 @@ RSpec.shared_examples_for 'valid_incoming_frame' do
34
51
  end
35
52
 
36
53
  context 'with raising' do
37
- before(:each) { WebSocket.should_raise = true }
38
- after(:each) { WebSocket.should_raise = false }
54
+ before { WebSocket.should_raise = true }
55
+ after { WebSocket.should_raise = false }
39
56
 
40
- it 'should have specified number of returned frames' do
57
+ it 'has specified number of returned frames' do
41
58
  if error
42
59
  expect do
43
60
  decoded_text_array.each_with_index do |da, index|
@@ -1,13 +1,33 @@
1
1
  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) }
2
+ it 'is outgoing frame' do
3
+ expect(subject.class).to be WebSocket::Frame::Outgoing
4
+ end
5
+
6
+ it 'is in proper verions' do
7
+ expect(subject.version).to eql version
8
+ end
9
+
10
+ it 'has proper type set' do
11
+ expect(subject.type).to eql frame_type
12
+ end
13
+
14
+ it 'contains decoded data' do
15
+ expect(subject.data).to eql(decoded_text)
16
+ end
17
+
18
+ it 'returns encoded data as to_s' do
19
+ expect(subject.to_s).to eql(encoded_text)
20
+ end
7
21
 
8
22
  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) }
23
+ before { subject.to_s }
24
+
25
+ it 'has valid errors set' do
26
+ expect(subject.error).to eql error
27
+ end
28
+
29
+ it 'requires sending' do
30
+ expect(subject.require_sending?).to eql require_sending
31
+ end
12
32
  end
13
33
  end
@@ -1,4 +1,5 @@
1
1
  # -*- encoding: utf-8 -*-
2
+
2
3
  $LOAD_PATH.push File.expand_path('../lib', __FILE__)
3
4
  require 'websocket/version'
4
5
 
@@ -18,8 +19,5 @@ Gem::Specification.new do |s|
18
19
  s.executables = `git ls-files -- bin/*`.split("\n").map { |f| File.basename(f) }
19
20
  s.require_paths = ['lib']
20
21
 
21
- s.add_development_dependency 'rake'
22
- s.add_development_dependency 'rspec', '~> 3.0'
23
- s.add_development_dependency 'rspec-its'
24
- s.add_development_dependency 'rubocop'
22
+ s.required_ruby_version = '>= 2.0'
25
23
  end
metadata CHANGED
@@ -1,71 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: websocket
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.4
4
+ version: 1.2.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bernard Potocki
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-01-31 00:00:00.000000000 Z
12
- dependencies:
13
- - !ruby/object:Gem::Dependency
14
- name: rake
15
- requirement: !ruby/object:Gem::Requirement
16
- requirements:
17
- - - ">="
18
- - !ruby/object:Gem::Version
19
- version: '0'
20
- type: :development
21
- prerelease: false
22
- version_requirements: !ruby/object:Gem::Requirement
23
- requirements:
24
- - - ">="
25
- - !ruby/object:Gem::Version
26
- version: '0'
27
- - !ruby/object:Gem::Dependency
28
- name: rspec
29
- requirement: !ruby/object:Gem::Requirement
30
- requirements:
31
- - - "~>"
32
- - !ruby/object:Gem::Version
33
- version: '3.0'
34
- type: :development
35
- prerelease: false
36
- version_requirements: !ruby/object:Gem::Requirement
37
- requirements:
38
- - - "~>"
39
- - !ruby/object:Gem::Version
40
- version: '3.0'
41
- - !ruby/object:Gem::Dependency
42
- name: rspec-its
43
- requirement: !ruby/object:Gem::Requirement
44
- requirements:
45
- - - ">="
46
- - !ruby/object:Gem::Version
47
- version: '0'
48
- type: :development
49
- prerelease: false
50
- version_requirements: !ruby/object:Gem::Requirement
51
- requirements:
52
- - - ">="
53
- - !ruby/object:Gem::Version
54
- version: '0'
55
- - !ruby/object:Gem::Dependency
56
- name: rubocop
57
- requirement: !ruby/object:Gem::Requirement
58
- requirements:
59
- - - ">="
60
- - !ruby/object:Gem::Version
61
- version: '0'
62
- type: :development
63
- prerelease: false
64
- version_requirements: !ruby/object:Gem::Requirement
65
- requirements:
66
- - - ">="
67
- - !ruby/object:Gem::Version
68
- version: '0'
11
+ date: 2017-11-14 00:00:00.000000000 Z
12
+ dependencies: []
69
13
  description: Universal Ruby library to handle WebSocket protocol
70
14
  email:
71
15
  - bernard.potocki@imanel.org
@@ -73,6 +17,7 @@ executables: []
73
17
  extensions: []
74
18
  extra_rdoc_files: []
75
19
  files:
20
+ - ".codeclimate.yml"
76
21
  - ".gitignore"
77
22
  - ".rubocop.yml"
78
23
  - ".travis.yml"
@@ -115,6 +60,7 @@ files:
115
60
  - lib/websocket/handshake/handler/server75.rb
116
61
  - lib/websocket/handshake/handler/server76.rb
117
62
  - lib/websocket/handshake/server.rb
63
+ - lib/websocket/nice_inspect.rb
118
64
  - lib/websocket/version.rb
119
65
  - spec/frame/incoming_03_spec.rb
120
66
  - spec/frame/incoming_04_spec.rb
@@ -157,7 +103,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
157
103
  requirements:
158
104
  - - ">="
159
105
  - !ruby/object:Gem::Version
160
- version: '0'
106
+ version: '2.0'
161
107
  required_rubygems_version: !ruby/object:Gem::Requirement
162
108
  requirements:
163
109
  - - ">="
@@ -165,7 +111,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
165
111
  version: '0'
166
112
  requirements: []
167
113
  rubyforge_project:
168
- rubygems_version: 2.5.2
114
+ rubygems_version: 2.6.14
169
115
  signing_key:
170
116
  specification_version: 4
171
117
  summary: Universal Ruby library to handle WebSocket protocol