websocket 1.2.5 → 1.2.7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (74) hide show
  1. checksums.yaml +5 -5
  2. data/.codeclimate.yml +1 -0
  3. data/.rubocop.yml +4 -1
  4. data/.travis.yml +1 -5
  5. data/CHANGELOG.md +8 -0
  6. data/Gemfile +5 -3
  7. data/Rakefile +3 -1
  8. data/lib/websocket.rb +3 -1
  9. data/lib/websocket/error.rb +2 -0
  10. data/lib/websocket/exception_handler.rb +2 -0
  11. data/lib/websocket/frame.rb +2 -0
  12. data/lib/websocket/frame/base.rb +2 -0
  13. data/lib/websocket/frame/data.rb +3 -1
  14. data/lib/websocket/frame/handler.rb +2 -0
  15. data/lib/websocket/frame/handler/base.rb +4 -2
  16. data/lib/websocket/frame/handler/handler03.rb +5 -4
  17. data/lib/websocket/frame/handler/handler04.rb +1 -0
  18. data/lib/websocket/frame/handler/handler05.rb +1 -0
  19. data/lib/websocket/frame/handler/handler07.rb +2 -1
  20. data/lib/websocket/frame/handler/handler75.rb +2 -1
  21. data/lib/websocket/frame/incoming.rb +2 -0
  22. data/lib/websocket/frame/incoming/client.rb +2 -0
  23. data/lib/websocket/frame/incoming/server.rb +2 -0
  24. data/lib/websocket/frame/outgoing.rb +2 -0
  25. data/lib/websocket/frame/outgoing/client.rb +2 -0
  26. data/lib/websocket/frame/outgoing/server.rb +2 -0
  27. data/lib/websocket/handshake.rb +2 -0
  28. data/lib/websocket/handshake/base.rb +12 -3
  29. data/lib/websocket/handshake/client.rb +2 -0
  30. data/lib/websocket/handshake/handler.rb +2 -0
  31. data/lib/websocket/handshake/handler/base.rb +2 -0
  32. data/lib/websocket/handshake/handler/client.rb +2 -0
  33. data/lib/websocket/handshake/handler/client01.rb +2 -0
  34. data/lib/websocket/handshake/handler/client04.rb +4 -2
  35. data/lib/websocket/handshake/handler/client11.rb +2 -0
  36. data/lib/websocket/handshake/handler/client75.rb +4 -2
  37. data/lib/websocket/handshake/handler/client76.rb +4 -2
  38. data/lib/websocket/handshake/handler/server.rb +2 -0
  39. data/lib/websocket/handshake/handler/server04.rb +4 -2
  40. data/lib/websocket/handshake/handler/server75.rb +4 -2
  41. data/lib/websocket/handshake/handler/server76.rb +2 -0
  42. data/lib/websocket/handshake/server.rb +2 -0
  43. data/lib/websocket/nice_inspect.rb +2 -0
  44. data/lib/websocket/version.rb +3 -1
  45. data/spec/frame/incoming_03_spec.rb +18 -16
  46. data/spec/frame/incoming_04_spec.rb +18 -16
  47. data/spec/frame/incoming_05_spec.rb +20 -18
  48. data/spec/frame/incoming_07_spec.rb +22 -20
  49. data/spec/frame/incoming_75_spec.rb +11 -9
  50. data/spec/frame/incoming_common_spec.rb +1 -0
  51. data/spec/frame/masking_spec.rb +1 -0
  52. data/spec/frame/outgoing_03_spec.rb +10 -8
  53. data/spec/frame/outgoing_04_spec.rb +10 -8
  54. data/spec/frame/outgoing_05_spec.rb +10 -8
  55. data/spec/frame/outgoing_07_spec.rb +11 -9
  56. data/spec/frame/outgoing_75_spec.rb +6 -4
  57. data/spec/frame/outgoing_common_spec.rb +1 -0
  58. data/spec/handshake/client_04_spec.rb +6 -4
  59. data/spec/handshake/client_11_spec.rb +3 -1
  60. data/spec/handshake/client_75_spec.rb +4 -2
  61. data/spec/handshake/client_76_spec.rb +4 -2
  62. data/spec/handshake/server_04_spec.rb +4 -2
  63. data/spec/handshake/server_75_spec.rb +4 -2
  64. data/spec/handshake/server_76_spec.rb +4 -2
  65. data/spec/spec_helper.rb +2 -0
  66. data/spec/support/all_client_drafts.rb +2 -0
  67. data/spec/support/all_server_drafts.rb +2 -0
  68. data/spec/support/frames_base.rb +2 -0
  69. data/spec/support/handshake_requests.rb +65 -63
  70. data/spec/support/incoming_frames.rb +2 -0
  71. data/spec/support/outgoing_frames.rb +2 -0
  72. data/spec/support/overwrites.rb +2 -0
  73. data/websocket.gemspec +2 -2
  74. metadata +3 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: d1beb710905d152c983423d7119156b054b515c3
4
- data.tar.gz: e74c5149d1ff19ff7b5ed25a499c0d2b2d3bef4b
2
+ SHA256:
3
+ metadata.gz: 9fa1e04675b3abf21352767a5b1075b77de4dff1670d6644d65b17d09daef059
4
+ data.tar.gz: dbef4fe08a9ba610b68cd6ab92f2674ab18a4833874040207cac63742ead0100
5
5
  SHA512:
6
- metadata.gz: 2ec8c925807edd84216c70bfdc7947f9d24c5f37d9ca4eb11274f8f32d99bd0e405b7fe3ad405d1ad835318a18ef9aaf0256bf4d0996ef6bedbdf89455b2b6e0
7
- data.tar.gz: 8a64ac2c2bb7da84c15afe43df803abc14d90a6d7e65d358f7a52b909c663a2fab1641c14e0d2666ed5d712f2e6c0bae97dd1ce31818fd48dbde77184bf7e855
6
+ metadata.gz: 9874d45a9b3bd2e773bc05540de06f1b2e710fa32bc0ac7da582e77f8e20f79f7d3e9863be9bea590e0b6b741e5f8692f39d483061570398cdae3303fb160ac4
7
+ data.tar.gz: bac88133308b1f2ce15f27de62ff74309189f2f9ccc9fd9ba006aaa3b936fc13a8e51f92bc2728c1ce52216df4ec2ac9845f8e31a2ef8217dc6e368ae98db515
@@ -9,6 +9,7 @@ engines:
9
9
  enabled: true
10
10
  rubocop:
11
11
  enabled: true
12
+ channel: rubocop-0-52
12
13
  ratings:
13
14
  paths:
14
15
  - "**.rb"
@@ -2,7 +2,7 @@ require: rubocop-rspec
2
2
 
3
3
  AllCops:
4
4
  DisplayCopNames: true
5
- TargetRubyVersion: 2.1
5
+ TargetRubyVersion: 2.3
6
6
 
7
7
  # Target: 15
8
8
  Metrics/AbcSize:
@@ -40,6 +40,9 @@ Metrics/PerceivedComplexity:
40
40
  - lib/websocket/frame/handler/handler75.rb
41
41
  - spec/support/handshake_requests.rb
42
42
 
43
+ RSpec/ContextWording:
44
+ Enabled: false
45
+
43
46
  RSpec/DescribeClass:
44
47
  Enabled: false
45
48
 
@@ -2,10 +2,9 @@ dist: trusty
2
2
  language: ruby
3
3
  script: "bundle exec rake"
4
4
  rvm:
5
- - 2.1
6
- - 2.2
7
5
  - 2.3
8
6
  - 2.4
7
+ - 2.5
9
8
  - ruby-head
10
9
  - jruby-9.1.9.0 # https://github.com/travis-ci/travis-ci/issues/8446
11
10
  - jruby-head
@@ -16,6 +15,3 @@ matrix:
16
15
  - rvm: ruby-head
17
16
  - rvm: jruby-head
18
17
  - rvm: rbx-3
19
-
20
- before_install:
21
- - gem update bundler
@@ -1,5 +1,13 @@
1
1
  # Changelog
2
2
 
3
+ ## 1.2.7
4
+
5
+ - fix bug in previous version for Ruby 2.3
6
+
7
+ ## 1.2.6
8
+
9
+ - duplicate variables passed in initializers to avoid changing them
10
+
3
11
  ## 1.2.5
4
12
 
5
13
  - make handshake server resilient to non-string Rack env keys
data/Gemfile CHANGED
@@ -1,13 +1,15 @@
1
+ # frozen_string_literal: true
2
+
1
3
  source 'http://rubygems.org'
2
4
 
3
5
  group :development do
4
6
  gem 'rake'
5
- gem 'rspec', '~> 3.0'
7
+ gem 'rspec', '~> 3.7'
6
8
 
7
9
  # Use same version as Code Climate for consistency with CI
8
10
  # https://github.com/codeclimate/codeclimate-rubocop/blob/master/Gemfile.lock
9
- gem 'rubocop', '0.46.0', require: false
10
- gem 'rubocop-rspec', '1.8.0', require: false
11
+ gem 'rubocop', '0.52.1', require: false
12
+ gem 'rubocop-rspec', '1.21.0', require: false
11
13
  end
12
14
 
13
15
  gemspec
data/Rakefile CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'bundler'
2
4
  require 'rspec/core/rake_task'
3
5
  require 'rubocop/rake_task'
@@ -11,7 +13,7 @@ end
11
13
 
12
14
  RuboCop::RakeTask.new
13
15
 
14
- task default: %i(spec rubocop)
16
+ task default: %i[spec rubocop]
15
17
 
16
18
  namespace :autobahn do
17
19
  desc 'Run autobahn tests for client'
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # WebSocket protocol implementation in Ruby
2
4
  # This module does not provide a WebSocket server or client, but is made for using
3
5
  # in http servers or clients to provide WebSocket support.
@@ -6,7 +8,7 @@
6
8
  module WebSocket
7
9
  # Default WebSocket version to use
8
10
  DEFAULT_VERSION = 13
9
- ROOT = File.expand_path(File.dirname(__FILE__))
11
+ ROOT = __dir__
10
12
 
11
13
  autoload :Error, "#{ROOT}/websocket/error"
12
14
  autoload :ExceptionHandler, "#{ROOT}/websocket/exception_handler"
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module WebSocket
2
4
  class Error < RuntimeError
3
5
  class Frame < ::WebSocket::Error
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module WebSocket
2
4
  module ExceptionHandler
3
5
  attr_accessor :error
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module WebSocket
2
4
  module Frame
3
5
  autoload :Base, "#{::WebSocket::ROOT}/websocket/frame/base"
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module WebSocket
2
4
  module Frame
3
5
  # @abstract Subclass and override to implement custom frames
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module WebSocket
2
4
  module Frame
3
5
  class Data < String
@@ -11,7 +13,7 @@ module WebSocket
11
13
 
12
14
  # Convert all arguments to ASCII-8BIT for easier traversing
13
15
  def convert_args(args)
14
- args.each { |arg| arg.force_encoding('ASCII-8BIT') }
16
+ args.collect { |arg| arg.dup.force_encoding('ASCII-8BIT') }
15
17
  end
16
18
 
17
19
  # Extract mask from 4 first bytes according to spec
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module WebSocket
2
4
  module Frame
3
5
  module Handler
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module WebSocket
2
4
  module Frame
3
5
  module Handler
@@ -24,14 +26,14 @@ module WebSocket
24
26
  # @param [Symbol] frame_type Frame type
25
27
  # @return [Boolean] True if given frame type is control frame
26
28
  def control_frame?(frame_type)
27
- !%i(text binary continuation).include?(frame_type)
29
+ !%i[text binary continuation].include?(frame_type)
28
30
  end
29
31
 
30
32
  # Check if frame is one of data frames
31
33
  # @param [Symbol] frame_type Frame type
32
34
  # @return [Boolean] True if given frame type is data frame
33
35
  def data_frame?(frame_type)
34
- %i(text binary).include?(frame_type)
36
+ %i[text binary].include?(frame_type)
35
37
  end
36
38
  end
37
39
  end
@@ -1,4 +1,5 @@
1
1
  # encoding: binary
2
+ # frozen_string_literal: true
2
3
 
3
4
  require 'securerandom'
4
5
 
@@ -21,7 +22,7 @@ module WebSocket
21
22
 
22
23
  # @see WebSocket::Frame::Base#supported_frames
23
24
  def supported_frames
24
- %i(text binary close ping pong)
25
+ %i[text binary close ping pong]
25
26
  end
26
27
 
27
28
  # @see WebSocket::Frame::Handler::Base#encode_frame
@@ -89,14 +90,14 @@ module WebSocket
89
90
  def encode_header
90
91
  mask = @frame.outgoing_masking? ? 0b10000000 : 0b00000000
91
92
 
92
- output = ''
93
+ output = +''
93
94
  output << (type_to_opcode(@frame.type) | (fin ? 0b10000000 : 0b00000000)) # since more, rsv1-3 are 0 and 0x80 for Draft 4
94
95
  output << encode_payload_length(@frame.data.size, mask)
95
96
  output
96
97
  end
97
98
 
98
99
  def encode_payload_length(length, mask)
99
- output = ''
100
+ output = +''
100
101
  if length <= 125
101
102
  output << (length | mask) # since rsv4 is 0
102
103
  elsif length < 65_536 # write 2 byte length
@@ -197,7 +198,7 @@ module WebSocket
197
198
  end
198
199
 
199
200
  def decode_continuation_frame(application_data, frame_type)
200
- @application_data_buffer ||= ''
201
+ @application_data_buffer ||= +''
201
202
  @application_data_buffer << application_data
202
203
  @frame_type ||= frame_type
203
204
  end
@@ -1,4 +1,5 @@
1
1
  # encoding: binary
2
+ # frozen_string_literal: true
2
3
 
3
4
  module WebSocket
4
5
  module Frame
@@ -1,4 +1,5 @@
1
1
  # encoding: binary
2
+ # frozen_string_literal: true
2
3
 
3
4
  module WebSocket
4
5
  module Frame
@@ -1,4 +1,5 @@
1
1
  # encoding: binary
2
+ # frozen_string_literal: true
2
3
 
3
4
  module WebSocket
4
5
  module Frame
@@ -48,7 +49,7 @@ module WebSocket
48
49
  return true if data.nil?
49
50
  data.encode('UTF-8')
50
51
  true
51
- rescue
52
+ rescue StandardError
52
53
  false
53
54
  end
54
55
 
@@ -1,4 +1,5 @@
1
1
  # encoding: binary
2
+ # frozen_string_literal: true
2
3
 
3
4
  module WebSocket
4
5
  module Frame
@@ -6,7 +7,7 @@ module WebSocket
6
7
  class Handler75 < Base
7
8
  # @see WebSocket::Frame::Base#supported_frames
8
9
  def supported_frames
9
- %i(text close)
10
+ %i[text close]
10
11
  end
11
12
 
12
13
  # @see WebSocket::Frame::Handler::Base#encode_frame
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module WebSocket
2
4
  module Frame
3
5
  # Construct or parse incoming WebSocket Frame.
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module WebSocket
2
4
  module Frame
3
5
  class Incoming
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module WebSocket
2
4
  module Frame
3
5
  class Incoming
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module WebSocket
2
4
  module Frame
3
5
  # Construct or parse incoming WebSocket Frame.
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module WebSocket
2
4
  module Frame
3
5
  class Outgoing
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module WebSocket
2
4
  module Frame
3
5
  class Outgoing
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module WebSocket
2
4
  module Handshake
3
5
  autoload :Base, "#{::WebSocket::ROOT}/websocket/handshake/base"
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module WebSocket
2
4
  module Handshake
3
5
  # @abstract Subclass and override to implement custom handshakes
@@ -11,12 +13,19 @@ module WebSocket
11
13
 
12
14
  # Initialize new WebSocket Handshake and set it's state to :new
13
15
  def initialize(args = {})
14
- args.each { |k, v| instance_variable_set("@#{k}", v) }
16
+ args.each do |k, v|
17
+ value = begin
18
+ v.dup
19
+ rescue TypeError
20
+ v
21
+ end
22
+ instance_variable_set("@#{k}", value)
23
+ end
15
24
 
16
25
  @state = :new
17
26
  @handler = nil
18
27
 
19
- @data = ''
28
+ @data = +''
20
29
  @headers ||= {}
21
30
  @protocols ||= []
22
31
  end
@@ -62,7 +71,7 @@ module WebSocket
62
71
  # @example
63
72
  # @handshake.uri #=> "ws://example.com/path?query=true"
64
73
  def uri
65
- uri = secure ? 'wss://' : 'ws://'
74
+ uri = String.new(secure ? 'wss://' : 'ws://')
66
75
  uri << host
67
76
  uri << ":#{port}" if port
68
77
  uri << path
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'uri'
2
4
 
3
5
  module WebSocket
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module WebSocket
2
4
  module Handshake
3
5
  module Handler
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module WebSocket
2
4
  module Handshake
3
5
  module Handler
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module WebSocket
2
4
  module Handshake
3
5
  module Handler
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'digest/md5'
2
4
 
3
5
  module WebSocket
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'digest/sha1'
2
4
  require 'base64'
3
5
 
@@ -15,8 +17,8 @@ module WebSocket
15
17
  # @see WebSocket::Handshake::Handler::Base#handshake_keys
16
18
  def handshake_keys
17
19
  keys = [
18
- %w(Upgrade websocket),
19
- %w(Connection Upgrade)
20
+ %w[Upgrade websocket],
21
+ %w[Connection Upgrade]
20
22
  ]
21
23
  host = @handshake.host
22
24
  host += ":#{@handshake.port}" if @handshake.port
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module WebSocket
2
4
  module Handshake
3
5
  module Handler
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module WebSocket
2
4
  module Handshake
3
5
  module Handler
@@ -12,8 +14,8 @@ module WebSocket
12
14
  # @see WebSocket::Handshake::Handler::Base#handshake_keys
13
15
  def handshake_keys
14
16
  keys = [
15
- %w(Upgrade WebSocket),
16
- %w(Connection Upgrade)
17
+ %w[Upgrade WebSocket],
18
+ %w[Connection Upgrade]
17
19
  ]
18
20
  host = @handshake.host
19
21
  host += ":#{@handshake.port}" if @handshake.port
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'digest/md5'
2
4
 
3
5
  module WebSocket
@@ -72,12 +74,12 @@ module WebSocket
72
74
  # @param [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 = 1 + rand(12)
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 + rand(12)).times do
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