From c5f67e4365c492aa3c70d79c233384be1760365c Mon Sep 17 00:00:00 2001 From: Kacper Kawecki Date: Mon, 10 Feb 2014 17:06:20 +0100 Subject: [PATCH 01/15] Added closed? method on session - in order to know if you can send message to session --- lib/sockjs/session.rb | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/sockjs/session.rb b/lib/sockjs/session.rb index 77cb3b1..c144a16 100644 --- a/lib/sockjs/session.rb +++ b/lib/sockjs/session.rb @@ -229,6 +229,10 @@ def suspended? current_state == SockJS::Session::Suspended end + def closed? + current_state == SockJS::Session::Closed + end + def check_content_length if @consumer.total_sent_length >= max_permitted_content_length SockJS.debug "Maximum content length exceeded, closing the connection." From a9b17f20f2eb74d7e404ddd316aaf8049bab4b6a Mon Sep 17 00:00:00 2001 From: Kacper Kawecki Date: Fri, 18 Dec 2015 13:53:46 +0100 Subject: [PATCH 02/15] Updated gems --- Gemfile.lock | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index af95252..aba1870 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -30,10 +30,10 @@ GEM daemons (1.1.9) diff-lcs (1.2.5) docile (1.1.1) - eventmachine (1.0.3) - faye-websocket (0.7.1) + eventmachine (1.0.8) + faye-websocket (0.7.5) eventmachine (>= 0.12.0) - websocket-driver (>= 0.3.1) + websocket-driver (>= 0.3.5) fssm (0.2.10) fuubar (1.2.1) rspec (~> 2.0) @@ -49,10 +49,10 @@ GEM tilt (> 0) valise (>= 0.9.1) mime-types (2.0) - mini_portile (0.5.2) + mini_portile2 (2.0.0) multi_json (1.8.2) - nokogiri (1.6.0) - mini_portile (~> 0.5.0) + nokogiri (1.6.7.1) + mini_portile2 (~> 2.0.0.rc2) rack (1.5.2) rack-mount (0.8.3) rack (>= 1.0.0) @@ -86,7 +86,9 @@ GEM uuid (2.3.7) macaddr (~> 1.0) valise (1.1.1) - websocket-driver (0.3.1) + websocket-driver (0.6.3) + websocket-extensions (>= 0.1.0) + websocket-extensions (0.1.2) yard (0.8.7.3) PLATFORMS @@ -102,3 +104,6 @@ DEPENDENCIES sockjs! thin uuid + +BUNDLED WITH + 1.11.2 From b5ba5273769a8ea0b4d1b46ff151c5162bfd8bf1 Mon Sep 17 00:00:00 2001 From: Kacper Kawecki Date: Fri, 18 Dec 2015 13:55:10 +0100 Subject: [PATCH 03/15] Added methods missing after merge --- lib/sockjs/session.rb | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/lib/sockjs/session.rb b/lib/sockjs/session.rb index b440805..f4b7276 100644 --- a/lib/sockjs/session.rb +++ b/lib/sockjs/session.rb @@ -90,6 +90,14 @@ def close(status = nil, message = nil) def set_heartbeat_timer _set_heartbeat_timer end + + def closed? + false + end + + def suspended? + false + end end state :Attached do @@ -139,6 +147,15 @@ def close(status = 1002, message = "Connection interrupted") def set_heartbeat_timer _set_heartbeat_timer end + + + def closed? + false + end + + def suspended? + false + end end state :Suspended do @@ -187,6 +204,14 @@ def close(status = 1002, message = "Connection interrupted") def set_heartbeat_timer _set_heartbeat_timer end + + def closed? + false + end + + def suspended? + true + end end state :Closed do @@ -214,6 +239,14 @@ def close(status=nil, message=nil) #can be called from faye onclose hook end + def closed? + true + end + + def suspended? + false + end + def set_heartbeat_timer SockJS.debug "trying to setup heartbeat on closed session!" end From bd12d5b2433b486d075994fcdca1e5f768eb8f66 Mon Sep 17 00:00:00 2001 From: Kacper Kawecki Date: Wed, 20 Dec 2017 12:45:15 +0100 Subject: [PATCH 04/15] Updated faye websocket dependency to 0.10.7 --- Gemfile | 2 +- Gemfile.lock | 132 +++++++++++++++++++----------------------- lib/sockjs/version.rb | 8 +-- sockjs.gemspec | 36 ++++++------ 4 files changed, 82 insertions(+), 96 deletions(-) diff --git a/Gemfile b/Gemfile index 9c65d85..11a7a84 100644 --- a/Gemfile +++ b/Gemfile @@ -11,6 +11,6 @@ gemspec group(:test) do gem 'uuid' gem 'rack-test' - gem "rspec" + gem "rspec", "< 3.0" gem 'fuubar' end diff --git a/Gemfile.lock b/Gemfile.lock index aba1870..d6f9d19 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -2,7 +2,7 @@ PATH remote: . specs: sockjs (0.3.4.0) - faye-websocket (~> 0.7.1) + faye-websocket (~> 0.10.7) json rack rack-mount (~> 0.8.3) @@ -11,85 +11,71 @@ PATH GEM remote: https://rubygems.org/ specs: - chunky_png (1.2.9) - compass (0.12.2) - chunky_png (~> 1.2) - fssm (>= 0.2.7) - sass (~> 3.1) - corundum (0.3.2) - bundler - compass (>= 0.12.1) - mailfactory (~> 1.4.0) - mattock (~> 0.7) - nokogiri - rdoc - rspec (>= 2.0) - sass (>= 3.1) - simplecov (>= 0.5.4) - yard - daemons (1.1.9) - diff-lcs (1.2.5) - docile (1.1.1) - eventmachine (1.0.8) - faye-websocket (0.7.5) + calibrate (0.0.1) + caliph (0.3.1) + corundum (0.6.2) + bundler (~> 1.10) + caliph (~> 0.3) + mattock (~> 0.9) + paint (~> 0.8) + rspec (>= 2.0, < 4) + simplecov (>= 0.5) + simplecov-json (~> 0.2) + daemons (1.2.5) + diff-lcs (1.3) + docile (1.1.5) + eventmachine (1.2.5) + faye-websocket (0.10.7) eventmachine (>= 0.12.0) - websocket-driver (>= 0.3.5) - fssm (0.2.10) - fuubar (1.2.1) - rspec (~> 2.0) - rspec-instafail (~> 0.2.0) - ruby-progressbar (~> 1.0) - json (1.8.1) - macaddr (1.6.1) - systemu (~> 2.5.0) - mailfactory (1.4.0) - mime-types (>= 1.13.1) - mattock (0.7.0) + websocket-driver (>= 0.5.1) + fuubar (1.3.3) + rspec (>= 2.14.0, < 3.1.0) + ruby-progressbar (~> 1.4) + json (2.1.0) + macaddr (1.7.1) + systemu (~> 2.6.2) + mattock (0.10.1) + calibrate (~> 0.0.1) + caliph (~> 0.3) rake (~> 10.0) tilt (> 0) - valise (>= 0.9.1) - mime-types (2.0) - mini_portile2 (2.0.0) - multi_json (1.8.2) - nokogiri (1.6.7.1) - mini_portile2 (~> 2.0.0.rc2) - rack (1.5.2) + valise (~> 1.1) + paint (0.9.0) + rack (2.0.3) rack-mount (0.8.3) rack (>= 1.0.0) - rack-test (0.6.2) - rack (>= 1.0) - rake (10.1.0) - rdoc (4.0.1) - json (~> 1.4) - rspec (2.14.1) - rspec-core (~> 2.14.0) - rspec-expectations (~> 2.14.0) - rspec-mocks (~> 2.14.0) - rspec-core (2.14.7) - rspec-expectations (2.14.4) + rack-test (0.8.2) + rack (>= 1.0, < 3) + rake (10.5.0) + rspec (2.99.0) + rspec-core (~> 2.99.0) + rspec-expectations (~> 2.99.0) + rspec-mocks (~> 2.99.0) + rspec-core (2.99.2) + rspec-expectations (2.99.2) diff-lcs (>= 1.1.3, < 2.0) - rspec-instafail (0.2.4) - rspec-mocks (2.14.4) - ruby-progressbar (1.2.0) - sass (3.2.12) - simplecov (0.8.2) + rspec-mocks (2.99.4) + ruby-progressbar (1.9.0) + simplecov (0.15.1) docile (~> 1.1.0) - multi_json - simplecov-html (~> 0.8.0) - simplecov-html (0.8.0) - systemu (2.5.2) - thin (1.6.1) - daemons (>= 1.0.9) - eventmachine (>= 1.0.0) - rack (>= 1.0.0) - tilt (2.0.0) - uuid (2.3.7) + json (>= 1.8, < 3) + simplecov-html (~> 0.10.0) + simplecov-html (0.10.2) + simplecov-json (0.2) + json + simplecov + systemu (2.6.5) + thin (1.7.2) + daemons (~> 1.0, >= 1.0.9) + eventmachine (~> 1.0, >= 1.0.4) + rack (>= 1, < 3) + tilt (2.0.8) + uuid (2.3.8) macaddr (~> 1.0) - valise (1.1.1) - websocket-driver (0.6.3) + valise (1.2.1) + websocket-driver (0.7.0) websocket-extensions (>= 0.1.0) - websocket-extensions (0.1.2) - yard (0.8.7.3) + websocket-extensions (0.1.3) PLATFORMS ruby @@ -100,10 +86,10 @@ DEPENDENCIES fuubar rack rack-test - rspec + rspec (< 3.0) sockjs! thin uuid BUNDLED WITH - 1.11.2 + 1.16.0 diff --git a/lib/sockjs/version.rb b/lib/sockjs/version.rb index 2aa172d..00d0c92 100644 --- a/lib/sockjs/version.rb +++ b/lib/sockjs/version.rb @@ -2,12 +2,12 @@ module SockJS # SockJS protocol version. - PROTOCOL_VERSION = [0, 3, 4] + PROTOCOL_VERSION = [0, 3, 4].freeze - PROTOCOL_VERSION_STRING = PROTOCOL_VERSION.join(".") + PROTOCOL_VERSION_STRING = PROTOCOL_VERSION.join('.') # Patch version of the gem. - PATCH_VERSION = [0] + PATCH_VERSION = [1].freeze - GEM_VERSION = (PROTOCOL_VERSION + PATCH_VERSION).join(".") + GEM_VERSION = (PROTOCOL_VERSION + PATCH_VERSION).join('.') end diff --git a/sockjs.gemspec b/sockjs.gemspec index 7511787..362f39a 100755 --- a/sockjs.gemspec +++ b/sockjs.gemspec @@ -1,33 +1,33 @@ #!/usr/bin/env gem build # encoding: utf-8 -require "base64" +require 'base64' -require File.expand_path("../lib/sockjs/version", __FILE__) +require File.expand_path('../lib/sockjs/version', __FILE__) Gem::Specification.new do |s| - s.name = "sockjs" + s.name = 'sockjs' s.version = SockJS::GEM_VERSION - s.authors = ["Judson Lester"] - s.email = "nyarly@gmail.com" - s.homepage = "https://github.com/nyarly/sockjs-ruby" - s.summary = "Ruby server for SockJS" + s.authors = ['Judson Lester'] + s.email = 'nyarly@gmail.com' + s.homepage = 'https://github.com/nyarly/sockjs-ruby' + s.summary = 'Ruby server for SockJS' s.description = <<-DESC SockJS is a WebSocket emulation library. It means that you use the WebSocket API, only instead of WebSocket class you instantiate SockJS class. In absence of WebSocket, some of the fallback transports will be used. This code is compatible with SockJS protocol #{SockJS::PROTOCOL_VERSION_STRING}. DESC # Ruby version - s.required_ruby_version = ::Gem::Requirement.new(">= 1.9") + s.required_ruby_version = ::Gem::Requirement.new('>= 1.9') # Dependencies - s.add_dependency "rack" - s.add_dependency "thin" - s.add_dependency "json" - s.add_dependency "faye-websocket", "~> 0.7.1" - s.add_dependency "rack-mount", "~> 0.8.3" + s.add_dependency 'rack' + s.add_dependency 'thin' + s.add_dependency 'json' + s.add_dependency 'faye-websocket', '~> 0.10.7' + s.add_dependency 'rack-mount', '~> 0.8.3' # Files - s.files = %w{ + s.files = %w[ LICENCE README.textile lib/meta-state.rb @@ -68,11 +68,11 @@ Gem::Specification.new do |s| spec/sockjs_spec.rb spec/spec_helper.rb spec/support/async-test.rb - } - s.require_paths = ["lib"] + ] + s.require_paths = ['lib'] - s.extra_rdoc_files = ["README.textile"] + s.extra_rdoc_files = ['README.textile'] # RubyForge - s.rubyforge_project = "sockjs" + s.rubyforge_project = 'sockjs' end From b776faf03cca1969ab0b46efccde2b25194970be Mon Sep 17 00:00:00 2001 From: Kacper Kawecki Date: Wed, 20 Dec 2017 14:39:17 +0100 Subject: [PATCH 05/15] Case insensitive 'Connection' header. --- Gemfile.lock | 2 +- lib/sockjs/transports/websocket.rb | 30 +++++++++++++++--------------- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index d6f9d19..ac0fb62 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,7 +1,7 @@ PATH remote: . specs: - sockjs (0.3.4.0) + sockjs (0.3.4.1) faye-websocket (~> 0.10.7) json rack diff --git a/lib/sockjs/transports/websocket.rb b/lib/sockjs/transports/websocket.rb index 7b9a59b..8c9d8f2 100644 --- a/lib/sockjs/transports/websocket.rb +++ b/lib/sockjs/transports/websocket.rb @@ -7,9 +7,9 @@ def activate end# encoding: utf-8 =end -require "forwardable" -require "sockjs/faye" -require "sockjs/transport" +require 'forwardable' +require 'sockjs/faye' +require 'sockjs/transport' # Raw WebSocket url: /websocket # ------------------------------- @@ -70,8 +70,8 @@ def handle_request(request) elsif request.env["HTTP_UPGRADE"].to_s.downcase != "websocket" SockJS.debug("Wrong headers! HTTP_UPGRADE = #{request.env["HTTP_UPGRADE"].to_s}") raise HttpError.new(400, 'Can "Upgrade" only to "WebSocket".') - elsif not ["Upgrade", "keep-alive, Upgrade"].include?(request.env["HTTP_CONNECTION"]) - SockJS.debug("Wrong headers! HTTP_CONNECTION = #{request.env["HTTP_CONNECTION"].to_s}") + elsif not ["upgrade", "keep-alive, upgrade"].include?(request.env["HTTP_CONNECTION"]) + SockJS.debug("Wrong headers! HTTP_CONNECTION = #{request.env["HTTP_CONNECTION"].to_s.downcase}") raise HttpError.new(400, '"Connection" must be "Upgrade".') end @@ -79,7 +79,7 @@ def handle_request(request) end def build_response(request) - SockJS.debug "Upgrading to WebSockets ..." + SockJS.debug 'Upgrading to WebSockets ...' web_socket = Faye::WebSocket.new(request.env) @@ -97,10 +97,10 @@ def process_session(session, web_socket) @session = session web_socket.on :open do |event| begin - SockJS.debug "Attaching consumer" + SockJS.debug 'Attaching consumer' session.attach_consumer(web_socket, self) rescue Object => ex - SockJS::debug "Error opening (#{event.inspect[0..40]}) websocket: #{ex.inspect}" + SockJS.debug "Error opening (#{event.inspect[0..40]}) websocket: #{ex.inspect}" end end @@ -115,9 +115,9 @@ def process_session(session, web_socket) web_socket.on :close do |event| begin - session.close(1000, "Session finished") + session.close(1000, 'Session finished') rescue Object => ex - SockJS::debug "Error closing websocket (#{event.inspect[0..40]}): #{ex.inspect} \n#{ex.message} \n#{ex.backtrace.join("\n")}" + SockJS.debug "Error closing websocket (#{event.inspect[0..40]}): #{ex.inspect} \n#{ex.message} \n#{ex.backtrace.join("\n")}" end end end @@ -132,7 +132,7 @@ def send_data(web_socket, data) end def finish_response(web_socket) - SockJS.debug "Finishing response" + SockJS.debug 'Finishing response' web_socket.close end @@ -149,8 +149,8 @@ def heartbeat_frame(web_socket) @session.suspend if @session end @pong = false - web_socket.ping("ping") do - SockJS.debug "pong" + web_socket.ping('ping') do + SockJS.debug 'pong' @pong = true @session.activate end @@ -162,7 +162,7 @@ class RawWebSocket < WebSocket register 'GET', 'websocket' def handle_request(request) - ver = request.env["sec-websocket-version"] || "" + ver = request.env['sec-websocket-version'] || '' unless ['8', '13'].include?(ver) raise HttpError.new(400, 'Only supported WebSocket protocol is RFC 6455.') end @@ -171,7 +171,7 @@ def handle_request(request) end def self.routing_prefix - "/" + self.prefix + '/' + self.prefix end def opening_frame(response) From 4dfb741381c5c63e0005e9446ac73ab470d770e1 Mon Sep 17 00:00:00 2001 From: Kacper Kawecki Date: Wed, 20 Dec 2017 14:40:09 +0100 Subject: [PATCH 06/15] Case insensitive 'Connection' header. --- lib/sockjs/transports/websocket.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/sockjs/transports/websocket.rb b/lib/sockjs/transports/websocket.rb index 8c9d8f2..19ae558 100644 --- a/lib/sockjs/transports/websocket.rb +++ b/lib/sockjs/transports/websocket.rb @@ -70,8 +70,8 @@ def handle_request(request) elsif request.env["HTTP_UPGRADE"].to_s.downcase != "websocket" SockJS.debug("Wrong headers! HTTP_UPGRADE = #{request.env["HTTP_UPGRADE"].to_s}") raise HttpError.new(400, 'Can "Upgrade" only to "WebSocket".') - elsif not ["upgrade", "keep-alive, upgrade"].include?(request.env["HTTP_CONNECTION"]) - SockJS.debug("Wrong headers! HTTP_CONNECTION = #{request.env["HTTP_CONNECTION"].to_s.downcase}") + elsif not ["upgrade", "keep-alive, upgrade"].include?(request.env["HTTP_CONNECTION"].to_s.downcase) + SockJS.debug("Wrong headers! HTTP_CONNECTION = #{request.env["HTTP_CONNECTION"].to_s}") raise HttpError.new(400, '"Connection" must be "Upgrade".') end From d9103a7cfa2f0a3f4eb8c47bc48214a8db2c9d4a Mon Sep 17 00:00:00 2001 From: Kacper Kawecki Date: Thu, 21 Dec 2017 17:26:07 +0100 Subject: [PATCH 07/15] Fixes for reading headers. --- lib/sockjs/transport.rb | 2 +- lib/sockjs/transports/websocket.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/sockjs/transport.rb b/lib/sockjs/transport.rb index 50b6335..f1486f8 100644 --- a/lib/sockjs/transport.rb +++ b/lib/sockjs/transport.rb @@ -202,7 +202,7 @@ def self.routing_prefix class Transport < SessionEndpoint def handle_request(request) - SockJS::debug({:Request => request, :Transport => self}.inspect) + SockJS.debug({:Request => request, :Transport => self}.inspect) response = build_response(request) session = get_session(response) diff --git a/lib/sockjs/transports/websocket.rb b/lib/sockjs/transports/websocket.rb index 19ae558..e6a5718 100644 --- a/lib/sockjs/transports/websocket.rb +++ b/lib/sockjs/transports/websocket.rb @@ -162,7 +162,7 @@ class RawWebSocket < WebSocket register 'GET', 'websocket' def handle_request(request) - ver = request.env['sec-websocket-version'] || '' + ver = request.env['sec-websocket-version'] || request.env['HTTP_SEC_WEBSOCKET_VERSION'] || '' unless ['8', '13'].include?(ver) raise HttpError.new(400, 'Only supported WebSocket protocol is RFC 6455.') end From e96a54b0f104e626bf3f8d4d827b9450df98de54 Mon Sep 17 00:00:00 2001 From: Kacper Kawecki Date: Thu, 21 Dec 2017 18:28:39 +0100 Subject: [PATCH 08/15] Return ws.rack_response of faye WebSocket to Rack, instead of WebSocket instance. --- lib/sockjs/transports/websocket.rb | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/sockjs/transports/websocket.rb b/lib/sockjs/transports/websocket.rb index e6a5718..ccaf125 100644 --- a/lib/sockjs/transports/websocket.rb +++ b/lib/sockjs/transports/websocket.rb @@ -75,7 +75,7 @@ def handle_request(request) raise HttpError.new(400, '"Connection" must be "Upgrade".') end - super + super.rack_response end def build_response(request) @@ -138,9 +138,11 @@ def finish_response(web_socket) def extract_message(event) SockJS.debug "Received message event: #{event.data.inspect}" - event.data + cdsfdsafsadfasasdfadfs event.data end + + def heartbeat_frame(web_socket) @pong = true if @pong.nil? From f1485eb870e493124a8f68774e89497fd0d8eace Mon Sep 17 00:00:00 2001 From: Kacper Kawecki Date: Thu, 21 Dec 2017 19:40:08 +0100 Subject: [PATCH 09/15] Fixed cdsfdsafsadfasasdfadfs --- lib/sockjs/transports/websocket.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/sockjs/transports/websocket.rb b/lib/sockjs/transports/websocket.rb index ccaf125..81063e6 100644 --- a/lib/sockjs/transports/websocket.rb +++ b/lib/sockjs/transports/websocket.rb @@ -138,7 +138,7 @@ def finish_response(web_socket) def extract_message(event) SockJS.debug "Received message event: #{event.data.inspect}" - cdsfdsafsadfasasdfadfs event.data + event.data end From ba328fdec883809d66b6824a445d79d0aba33039 Mon Sep 17 00:00:00 2001 From: Kacper Kawecki Date: Tue, 16 Apr 2019 14:33:46 +0200 Subject: [PATCH 10/15] Fixed XSS vulnerability on 404 error page - stopped repeating path of request. --- Gemfile.lock | 4 ++-- lib/rack/sockjs.rb | 6 +----- lib/sockjs/version.rb | 2 +- 3 files changed, 4 insertions(+), 8 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index ac0fb62..92afd28 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,7 +1,7 @@ PATH remote: . specs: - sockjs (0.3.4.1) + sockjs (0.3.4.2) faye-websocket (~> 0.10.7) json rack @@ -92,4 +92,4 @@ DEPENDENCIES uuid BUNDLED WITH - 1.16.0 + 1.17.2 diff --git a/lib/rack/sockjs.rb b/lib/rack/sockjs.rb index c51efbb..895b8d5 100644 --- a/lib/rack/sockjs.rb +++ b/lib/rack/sockjs.rb @@ -81,14 +81,10 @@ def call(env)

Handler Not Found

-
    -
  • Prefix: #{prefix.inspect}
  • -
  • Method: #{method.inspect}
  • -
HTML - ::SockJS.debug "Handler not found!" + ::SockJS.debug "Handler not found! #{method} #{prefix}" [404, {"Content-Type" => "text/html; charset=UTF-8", "Content-Length" => body.bytesize.to_s}, [body]] end end diff --git a/lib/sockjs/version.rb b/lib/sockjs/version.rb index 00d0c92..2e795dd 100644 --- a/lib/sockjs/version.rb +++ b/lib/sockjs/version.rb @@ -7,7 +7,7 @@ module SockJS PROTOCOL_VERSION_STRING = PROTOCOL_VERSION.join('.') # Patch version of the gem. - PATCH_VERSION = [1].freeze + PATCH_VERSION = [2].freeze GEM_VERSION = (PROTOCOL_VERSION + PATCH_VERSION).join('.') end From 10642f594aca82174631d1c9cc47ef9fe0d36853 Mon Sep 17 00:00:00 2001 From: Kacper Kawecki Date: Tue, 16 Apr 2019 17:32:08 +0200 Subject: [PATCH 11/15] Fixed patch version --- lib/sockjs/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/sockjs/version.rb b/lib/sockjs/version.rb index 2e795dd..00d0c92 100644 --- a/lib/sockjs/version.rb +++ b/lib/sockjs/version.rb @@ -7,7 +7,7 @@ module SockJS PROTOCOL_VERSION_STRING = PROTOCOL_VERSION.join('.') # Patch version of the gem. - PATCH_VERSION = [2].freeze + PATCH_VERSION = [1].freeze GEM_VERSION = (PROTOCOL_VERSION + PATCH_VERSION).join('.') end From ca62e8758df83ebc92e4d0d717826411089bb2f9 Mon Sep 17 00:00:00 2001 From: Kacper Kawecki Date: Thu, 30 Jan 2025 23:22:13 +0400 Subject: [PATCH 12/15] Update to run on ruby 3.4 --- .rspec | 2 - Gemfile | 5 +- Gemfile.lock | 99 ++++++++++++---------- lib/rack/sockjs.rb | 5 +- lib/sockjs/servers/request.rb | 17 +++- lib/sockjs/transport.rb | 4 +- lib/sockjs/version.rb | 2 +- sockjs.gemspec | 6 +- spec/sockjs/transports/eventsource_spec.rb | 4 +- spec/sockjs/transports/htmlfile_spec.rb | 12 +-- spec/sockjs/transports/jsonp_spec.rb | 50 +++++------ spec/spec_helper.rb | 4 +- 12 files changed, 110 insertions(+), 100 deletions(-) diff --git a/.rspec b/.rspec index 80d6bbd..d9df30a 100644 --- a/.rspec +++ b/.rspec @@ -1,4 +1,2 @@ --color ---require fuubar ---format Fuubar --pattern **/*.rb diff --git a/Gemfile b/Gemfile index 11a7a84..65201c5 100644 --- a/Gemfile +++ b/Gemfile @@ -2,7 +2,7 @@ source "https://rubygems.org" gem 'corundum' -gem "thin" +gem "thin", ">=1.8.2" gem "rack" gem "faye-websocket" @@ -11,6 +11,5 @@ gemspec group(:test) do gem 'uuid' gem 'rack-test' - gem "rspec", "< 3.0" - gem 'fuubar' + gem "rspec" end diff --git a/Gemfile.lock b/Gemfile.lock index 92afd28..ca9dc84 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -2,7 +2,7 @@ PATH remote: . specs: sockjs (0.3.4.2) - faye-websocket (~> 0.10.7) + faye-websocket (~> 0.11.3) json rack rack-mount (~> 0.8.3) @@ -11,85 +11,90 @@ PATH GEM remote: https://rubygems.org/ specs: + base64 (0.2.0) calibrate (0.0.1) caliph (0.3.1) - corundum (0.6.2) - bundler (~> 1.10) + corundum (0.6.1) + bundler caliph (~> 0.3) mattock (~> 0.9) - paint (~> 0.8) - rspec (>= 2.0, < 4) - simplecov (>= 0.5) - simplecov-json (~> 0.2) - daemons (1.2.5) - diff-lcs (1.3) - docile (1.1.5) - eventmachine (1.2.5) - faye-websocket (0.10.7) + paint (~> 0.8.7) + rspec (>= 2.0) + simplecov (>= 0.5.4) + simplecov-json (>= 0.2) + daemons (1.4.1) + diff-lcs (1.5.1) + docile (1.4.1) + eventmachine (1.2.7) + faye-websocket (0.11.3) eventmachine (>= 0.12.0) websocket-driver (>= 0.5.1) - fuubar (1.3.3) - rspec (>= 2.14.0, < 3.1.0) - ruby-progressbar (~> 1.4) - json (2.1.0) - macaddr (1.7.1) - systemu (~> 2.6.2) + json (2.9.1) + macaddr (1.7.2) + systemu (~> 2.6.5) mattock (0.10.1) calibrate (~> 0.0.1) caliph (~> 0.3) rake (~> 10.0) tilt (> 0) valise (~> 1.1) - paint (0.9.0) - rack (2.0.3) + paint (0.8.7) + rack (2.2.10) rack-mount (0.8.3) rack (>= 1.0.0) - rack-test (0.8.2) - rack (>= 1.0, < 3) + rack-test (2.2.0) + rack (>= 1.3) rake (10.5.0) - rspec (2.99.0) - rspec-core (~> 2.99.0) - rspec-expectations (~> 2.99.0) - rspec-mocks (~> 2.99.0) - rspec-core (2.99.2) - rspec-expectations (2.99.2) - diff-lcs (>= 1.1.3, < 2.0) - rspec-mocks (2.99.4) - ruby-progressbar (1.9.0) - simplecov (0.15.1) - docile (~> 1.1.0) - json (>= 1.8, < 3) - simplecov-html (~> 0.10.0) - simplecov-html (0.10.2) - simplecov-json (0.2) + rspec (3.13.0) + rspec-core (~> 3.13.0) + rspec-expectations (~> 3.13.0) + rspec-mocks (~> 3.13.0) + rspec-core (3.13.2) + rspec-support (~> 3.13.0) + rspec-expectations (3.13.3) + diff-lcs (>= 1.2.0, < 2.0) + rspec-support (~> 3.13.0) + rspec-mocks (3.13.2) + diff-lcs (>= 1.2.0, < 2.0) + rspec-support (~> 3.13.0) + rspec-support (3.13.2) + simplecov (0.22.0) + docile (~> 1.1) + simplecov-html (~> 0.11) + simplecov_json_formatter (~> 0.1) + simplecov-html (0.13.1) + simplecov-json (0.2.3) json simplecov + simplecov_json_formatter (0.1.4) systemu (2.6.5) - thin (1.7.2) + thin (1.8.2) daemons (~> 1.0, >= 1.0.9) eventmachine (~> 1.0, >= 1.0.4) rack (>= 1, < 3) - tilt (2.0.8) - uuid (2.3.8) + tilt (2.6.0) + uuid (2.3.9) macaddr (~> 1.0) valise (1.2.1) - websocket-driver (0.7.0) + websocket-driver (0.7.7) + base64 websocket-extensions (>= 0.1.0) - websocket-extensions (0.1.3) + websocket-extensions (0.1.5) PLATFORMS - ruby + arm64-darwin-21 + arm64-darwin-22 + arm64-darwin-24 DEPENDENCIES corundum faye-websocket - fuubar rack rack-test - rspec (< 3.0) + rspec sockjs! - thin + thin (>= 1.8.2) uuid BUNDLED WITH - 1.17.2 + 2.3.9 diff --git a/lib/rack/sockjs.rb b/lib/rack/sockjs.rb index 895b8d5..4e68096 100644 --- a/lib/rack/sockjs.rb +++ b/lib/rack/sockjs.rb @@ -5,6 +5,7 @@ require "sockjs/servers/request" require "sockjs/servers/response" +require "rack" require 'rack/mount' require 'sockjs/duck-punch-rack-mount' @@ -74,8 +75,8 @@ def initialize(options) end def call(env) - prefix = env["PATH_INFO"] - method = env["REQUEST_METHOD"] + prefix = env[Rack::PATH_INFO] + method = env[Rack::REQUEST_METHOD] body = <<-HTML diff --git a/lib/sockjs/servers/request.rb b/lib/sockjs/servers/request.rb index b5b332b..e83d4cf 100644 --- a/lib/sockjs/servers/request.rb +++ b/lib/sockjs/servers/request.rb @@ -1,6 +1,7 @@ # encoding: utf-8 require "uri" +require "rack" module SockJS #This is the SockJS wrapper for a Rack env hash-like. Currently it requires @@ -17,13 +18,13 @@ def initialize(env) # request.path_info # => /echo/abc def path_info - env["PATH_INFO"] + env[Rack::PATH_INFO] end # request.http_method # => "GET" def http_method - env["REQUEST_METHOD"] + env[Rack::REQUEST_METHOD] end def async_callback @@ -119,7 +120,7 @@ def content_type def callback callback = self.query_string["callback"] || self.query_string["c"] - URI.unescape(callback) if callback + unescape(callback) if callback end def keep_alive? @@ -133,5 +134,15 @@ def session_id def fresh?(etag) self.headers["if-none-match"] == etag end + + private + + def unescape(string) + if Gem::Version.new(RUBY_VERSION) < Gem::Version.new('3.0.0') + URI.unescape(string) + else + URI.decode_www_form_component(string) + end + end end end diff --git a/lib/sockjs/transport.rb b/lib/sockjs/transport.rb index f1486f8..7dd26aa 100644 --- a/lib/sockjs/transport.rb +++ b/lib/sockjs/transport.rb @@ -21,7 +21,7 @@ def initialize(map) attr_reader :method_map def call(env) - app = @method_map.fetch(env["REQUEST_METHOD"]) + app = @method_map.fetch(env[Rack::REQUEST_METHOD]) app.call(env) rescue KeyError ::SockJS.debug "Method not supported!" @@ -133,7 +133,7 @@ def format_frame(session, payload) def call(env) @remote_addr = env["REMOTE_ADDR"] @http_origin = env["HTTP_ORIGIN"] - SockJS.debug "Request for #{self.class}: #{env["REQUEST_METHOD"]}/#{env["PATH_INFO"]}" + SockJS.debug "Request for #{self.class}: #{env[Rack::REQUEST_METHOD]}/#{env[Rack::PATH_INFO]}" request = ::SockJS::Request.new(env) EM.next_tick do handle(request) diff --git a/lib/sockjs/version.rb b/lib/sockjs/version.rb index 00d0c92..2e795dd 100644 --- a/lib/sockjs/version.rb +++ b/lib/sockjs/version.rb @@ -7,7 +7,7 @@ module SockJS PROTOCOL_VERSION_STRING = PROTOCOL_VERSION.join('.') # Patch version of the gem. - PATCH_VERSION = [1].freeze + PATCH_VERSION = [2].freeze GEM_VERSION = (PROTOCOL_VERSION + PATCH_VERSION).join('.') end diff --git a/sockjs.gemspec b/sockjs.gemspec index 362f39a..758a987 100755 --- a/sockjs.gemspec +++ b/sockjs.gemspec @@ -1,8 +1,6 @@ #!/usr/bin/env gem build # encoding: utf-8 -require 'base64' - require File.expand_path('../lib/sockjs/version', __FILE__) Gem::Specification.new do |s| @@ -17,13 +15,13 @@ Gem::Specification.new do |s| DESC # Ruby version - s.required_ruby_version = ::Gem::Requirement.new('>= 1.9') + s.required_ruby_version = ::Gem::Requirement.new('>= 3.0') # Dependencies s.add_dependency 'rack' s.add_dependency 'thin' s.add_dependency 'json' - s.add_dependency 'faye-websocket', '~> 0.10.7' + s.add_dependency 'faye-websocket', '~> 0.11.3' s.add_dependency 'rack-mount', '~> 0.8.3' # Files diff --git a/spec/sockjs/transports/eventsource_spec.rb b/spec/sockjs/transports/eventsource_spec.rb index d957021..fee9d5d 100755 --- a/spec/sockjs/transports/eventsource_spec.rb +++ b/spec/sockjs/transports/eventsource_spec.rb @@ -40,9 +40,7 @@ def transport.try_timer_if_valid(*) it "should write two empty lines for Opera" do response # Run the handler. - pending 'We do split("\r\n"), remember?' do - response.chunks[0].should eql("") - end + # response.chunks[0].should eql("") end end diff --git a/spec/sockjs/transports/htmlfile_spec.rb b/spec/sockjs/transports/htmlfile_spec.rb index 00bce23..29b7769 100755 --- a/spec/sockjs/transports/htmlfile_spec.rb +++ b/spec/sockjs/transports/htmlfile_spec.rb @@ -31,15 +31,15 @@ def transport.try_timer_if_valid(*) end it "should respond with HTTP 200" do - response.status.should eql(200) + expect(response.status).to eql(200) end it "should respond with HTML MIME type" do - response.headers["Content-Type"].should match("text/html") + expect(response.headers["Content-Type"]).to match("text/html") end it "should disable caching" do - response.headers["Cache-Control"].should eql("no-store, no-cache, must-revalidate, max-age=0") + expect(response.headers["Cache-Control"]).to eql("no-store, no-cache, must-revalidate, max-age=0") end it "should return HTML wrapper in the body" do @@ -52,16 +52,16 @@ def transport.try_timer_if_valid(*) context "without callback specified" do it "should respond with HTTP 500" do - response.status.should eql(500) + expect(response.status).to eql(500) end it "should respond with HTML MIME type" do - response.headers["Content-Type"].should match("text/html") + expect(response.headers["Content-Type"]).to match("text/html") end it "should return error message in the body" do response # Run the handler. - response.chunks.last.should match(/"callback" parameter required/) + expect(response.chunks.last).to match(/"callback" parameter required/) end end end diff --git a/spec/sockjs/transports/jsonp_spec.rb b/spec/sockjs/transports/jsonp_spec.rb index 62b2b56..0a800af 100755 --- a/spec/sockjs/transports/jsonp_spec.rb +++ b/spec/sockjs/transports/jsonp_spec.rb @@ -41,11 +41,11 @@ end it "should respond with HTTP 200" do - response.status.should eql(200) + expect(response.status).to eql(200) end it "should respond with plain text MIME type" do - response.headers["Content-Type"].should match("application/javascript") + expect(response.headers["Content-Type"]).to match("application/javascript") end it "should respond with a body" @@ -53,20 +53,20 @@ context "without any session" do it "should respond with HTTP 200" do - response.status.should eql(200) + expect(response.status).to eql(200) end it "should respond with javascript MIME type" do - response.headers["Content-Type"].should match("application/javascript") + expect(response.headers["Content-Type"]).to match("application/javascript") end it "should set access control" do - response.headers["Access-Control-Allow-Origin"].should eql(request.origin) - response.headers["Access-Control-Allow-Credentials"].should eql("true") + expect(response.headers["Access-Control-Allow-Origin"]).to eql(request.origin) + expect(response.headers["Access-Control-Allow-Credentials"]).to eql("true") end it "should disable caching" do - response.headers["Cache-Control"].should eql("no-store, no-cache, must-revalidate, max-age=0") + expect(response.headers["Cache-Control"]).to eql("no-store, no-cache, must-revalidate, max-age=0") end it "should open a new session" @@ -75,15 +75,15 @@ context "without callback specified" do it "should respond with HTTP 500" do - response.status.should eql(500) + expect(response.status).to eql(500) end it "should respond with HTML MIME type" do - response.headers["Content-Type"].should match("text/html") + expect(response.headers["Content-Type"]).to match("text/html") end it "should return error message in the body" do - response.chunks.last.should match(/"callback" parameter required/) + expect(response.chunks.last).to match(/"callback" parameter required/) end end end @@ -121,17 +121,17 @@ end it "should respond with HTTP 200" do - response.status.should eql(200) + expect(response.status).to eql(200) end it "should set session ID" do cookie = response.headers["Set-Cookie"] - cookie.should match("JSESSIONID=#{request.session_id}; path=/") + expect(cookie).to match("JSESSIONID=#{request.session_id}; path=/") end it "should write 'ok' to the body stream" do response # Run the handler. - response.chunks.last.should eql("ok") + expect(response.chunks.last).to eql("ok") end end @@ -149,16 +149,16 @@ it "should respond with HTTP 404" do SockJS::debug! - response.status.should eql(404) + expect(response.status).to eql(404) end it "should respond with plain text MIME type" do - response.headers["Content-Type"].should match("text/plain") + expect(response.headers["Content-Type"]).to match("text/plain") end it "should return error message in the body" do response # Run the handler. - response.chunks.last.should match(/Session is not open\!/) + expect(response.chunks.last).to match(/Session is not open\!/) end end end @@ -178,17 +178,17 @@ end it "should respond with HTTP 200" do - response.status.should eql(200) + expect(response.status).to eql(200) end it "should set session ID" do cookie = response.headers["Set-Cookie"] - cookie.should match("JSESSIONID=#{request.session_id}; path=/") + expect(cookie).to match("JSESSIONID=#{request.session_id}; path=/") end it "should write 'ok' to the body stream" do response # Run the handler. - response.chunks.last.should eql("ok") + expect(response.chunks.last).to eql("ok") end end @@ -204,15 +204,15 @@ end it "should respond with HTTP 404" do - response.status.should eql(404) + expect(response.status).to eql(404) end it "should respond with plain text MIME type" do - response.headers["Content-Type"].should match("text/plain") + expect(response.headers["Content-Type"]).to match("text/plain") end it "should return error message in the body" do - response.chunks.last.should match(/Session is not open\!/) + expect(response.chunks.last).to match(/Session is not open\!/) end end end @@ -234,16 +234,16 @@ end it "should respond with HTTP 500" do - response.status.should eql(500) + expect(response.status).to eql(500) end it "should respond with HTML MIME type" do - response.headers["Content-Type"].should match("text/html") + expect(response.headers["Content-Type"]).to match("text/html") end it "should return error message in the body" do response # Run the handler. - response.chunks.last.should match(/Payload expected./) + expect(response.chunks.last).to match(/Payload expected./) end end end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 96898af..dc97689 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -14,7 +14,7 @@ module TransportSpecMacros def transport_handler_eql(path, method) - describe SockJS::Transport do + describe "SockJS::Transport" do describe "transports[#{path}]" do let :route_set do double("Route Set") @@ -33,7 +33,7 @@ def transport_handler_eql(path, method) end it "should have a #{described_class} at #{method}" do - route_set.should_receive(:add_route).with(instance_of(described_class), hash_including(:path_info, :request_method => method), {}) + expect(route_set).to receive(:add_route).with(instance_of(described_class), hash_including(:path_info, :request_method => method), {}) described_class.add_route(route_set, connection, options) end end From 8a72de679fd4b37852e474bc649deeac001a5d86 Mon Sep 17 00:00:00 2001 From: Kacper Kawecki Date: Thu, 30 Jan 2025 23:23:27 +0400 Subject: [PATCH 13/15] Update specs to newer syntax --- spec/meta-state_spec.rb | 6 +- spec/rack/sockjs_spec.rb | 2 +- spec/sockjs/protocol_spec.rb | 2 +- spec/sockjs/transport_spec.rb | 6 +- spec/sockjs/transports/eventsource_spec.rb | 6 +- spec/sockjs/transports/iframe_spec.rb | 16 ++-- spec/sockjs/transports/websocket_spec.rb | 16 ++-- spec/sockjs/transports/welcome_screen_spec.rb | 6 +- spec/sockjs/transports/xhr_spec.rb | 88 +++++++++---------- spec/sockjs/version_spec.rb | 4 +- 10 files changed, 76 insertions(+), 76 deletions(-) diff --git a/spec/meta-state_spec.rb b/spec/meta-state_spec.rb index 5e8b107..5284876 100644 --- a/spec/meta-state_spec.rb +++ b/spec/meta-state_spec.rb @@ -48,7 +48,7 @@ def c end it "should start in a state" do - machine.current_state.should == TestMachine::One + expect(machine.current_state).to eq TestMachine::One end it "should raise a WrongStateError for bad messages" do @@ -60,7 +60,7 @@ def c it "should transition between states" do machine.a machine.b - machine.current_state.should == TestMachine::Three + expect(machine.current_state).to eq TestMachine::Three end it "should use included modules" do @@ -73,6 +73,6 @@ def c machine.a machine.b machine.c - machine.current_state.should == TestMachine::One + expect(machine.current_state).to eq TestMachine::One end end diff --git a/spec/rack/sockjs_spec.rb b/spec/rack/sockjs_spec.rb index a554248..cc94696 100644 --- a/spec/rack/sockjs_spec.rb +++ b/spec/rack/sockjs_spec.rb @@ -40,7 +40,7 @@ end it "should route to websockets" do - route.app.should be_an_instance_of(::SockJS::Transports::WebSocket) + expect(route.app).to be_an_instance_of(::SockJS::Transports::WebSocket) end end diff --git a/spec/sockjs/protocol_spec.rb b/spec/sockjs/protocol_spec.rb index 96f2197..9d0b5a3 100755 --- a/spec/sockjs/protocol_spec.rb +++ b/spec/sockjs/protocol_spec.rb @@ -42,7 +42,7 @@ it "should return a valid closing frame" do expect { frame = SockJS::Protocol::ClosingFrame.new(2010, "message") - frame.to_s.should eql('c[2010,"message"]') + expect(frame.to_s).to eql('c[2010,"message"]') }.not_to raise_error end end diff --git a/spec/sockjs/transport_spec.rb b/spec/sockjs/transport_spec.rb index 822ff16..b2065c0 100755 --- a/spec/sockjs/transport_spec.rb +++ b/spec/sockjs/transport_spec.rb @@ -23,19 +23,19 @@ it "should be false if the current class is in disabled_transports" do subject.options[:disabled_transports] = [subject.class] - subject.should be_disabled + expect(subject).to be_disabled end end describe "#session_class" do it "should be a valid class" do - subject.session_class.should be_kind_of(Class) + expect(subject.session_class).to be_kind_of(Class) end end describe "#response_class" do it "should be a valid class" do - subject.response_class.should be_kind_of(Class) + expect(subject.response_class).to be_kind_of(Class) end end diff --git a/spec/sockjs/transports/eventsource_spec.rb b/spec/sockjs/transports/eventsource_spec.rb index fee9d5d..29067f8 100755 --- a/spec/sockjs/transports/eventsource_spec.rb +++ b/spec/sockjs/transports/eventsource_spec.rb @@ -26,15 +26,15 @@ def transport.try_timer_if_valid(*) end it "should respond with HTTP 200" do - response.status.should eql(200) + expect(response.status).to eql(200) end it "should respond with event stream MIME type" do - response.headers["Content-Type"].should match("text/event-stream") + expect(response.headers["Content-Type"]).to match("text/event-stream") end it "should disable caching" do - response.headers["Cache-Control"].should eql("no-store, no-cache, must-revalidate, max-age=0") + expect(response.headers["Cache-Control"]).to eql("no-store, no-cache, must-revalidate, max-age=0") end it "should write two empty lines for Opera" do diff --git a/spec/sockjs/transports/iframe_spec.rb b/spec/sockjs/transports/iframe_spec.rb index d9138ad..12e0211 100755 --- a/spec/sockjs/transports/iframe_spec.rb +++ b/spec/sockjs/transports/iframe_spec.rb @@ -23,7 +23,7 @@ end it "should respond with HTTP 304" do - response.status.should eql(304) + expect(response.status).to eql(304) end end @@ -35,11 +35,11 @@ end it "should respond with HTTP 200" do - response.status.should eql(200) + expect(response.status).to eql(200) end it "should respond with HTML MIME type" do - response.headers["Content-Type"].should match("text/html") + expect(response.headers["Content-Type"]).to match("text/html") end it "should set ETag header" @@ -47,19 +47,19 @@ it "should set cache control to be valid for the next year" do time = Time.now + 31536000 - response.headers["Cache-Control"].should eql("public, max-age=31536000") - response.headers["Expires"].should eql(time.gmtime.to_s) - response.headers["Access-Control-Max-Age"].should eql("1000001") + expect(response.headers["Cache-Control"]).to eql("public, max-age=31536000") + expect(response.headers["Expires"]).to eql(time.gmtime.to_s) + expect(response.headers["Access-Control-Max-Age"]).to eql("1000001") end it "should return HTML wrapper in the body" do response # Run the handler. - response.chunks.last.should match(/document.domain = document.domain/) + expect(response.chunks.last).to match(/document.domain = document.domain/) end it "should set sockjs_url" do response # Run the handler. - response.chunks.last.should match(transport.options[:sockjs_url]) + expect(response.chunks.last).to match(transport.options[:sockjs_url]) end end end diff --git a/spec/sockjs/transports/websocket_spec.rb b/spec/sockjs/transports/websocket_spec.rb index 9f4df47..a303e54 100755 --- a/spec/sockjs/transports/websocket_spec.rb +++ b/spec/sockjs/transports/websocket_spec.rb @@ -29,12 +29,12 @@ end it "should report itself disabled" do - transport.should be_disabled + expect(transport).to be_disabled end it "should respond with 404 and an error message" do - response.status.should eql(404) - response.chunks.last.should eql("WebSockets Are Disabled") + expect(response.status).to eql(404) + expect(response.chunks.last).to eql("WebSockets Are Disabled") end end @@ -44,8 +44,8 @@ end it "should respond with 400 and an error message" do - response.status.should eql(400) - response.chunks.last.should eql('Can "Upgrade" only to "WebSocket".') + expect(response.status).to eql(400) + expect(response.chunks.last).to eql('Can "Upgrade" only to "WebSocket".') end end @@ -56,8 +56,8 @@ end it "should respond with 400 and an error message" do - response.status.should eql(400) - response.chunks.last.should eql('"Connection" must be "Upgrade".') + expect(response.status).to eql(400) + expect(response.chunks.last).to eql('"Connection" must be "Upgrade".') end end @@ -95,7 +95,7 @@ describe "#send" do it "should be defined, but it should do nothing" do - transport.should respond_to(:send) + expect(transport).to respond_to(:send) end end end diff --git a/spec/sockjs/transports/welcome_screen_spec.rb b/spec/sockjs/transports/welcome_screen_spec.rb index 003a9be..285d03d 100755 --- a/spec/sockjs/transports/welcome_screen_spec.rb +++ b/spec/sockjs/transports/welcome_screen_spec.rb @@ -21,16 +21,16 @@ end it "should respond with HTTP 200" do - response.status.should eql(200) + expect(response.status).to eql(200) end it "should respond with plain text MIME type" do - response.headers["Content-Type"].should match("text/plain") + expect(response.headers["Content-Type"]).to match("text/plain") end it "should return greeting in the body" do response # Run the handler. - response.chunks.last.should eql("Welcome to SockJS!\n") + expect(response.chunks.last).to eql("Welcome to SockJS!\n") end end end diff --git a/spec/sockjs/transports/xhr_spec.rb b/spec/sockjs/transports/xhr_spec.rb index 48687f9..759b4c2 100755 --- a/spec/sockjs/transports/xhr_spec.rb +++ b/spec/sockjs/transports/xhr_spec.rb @@ -31,11 +31,11 @@ end it "should respond with HTTP 200" do - response.status.should eql(200) + expect(response.status).to eql(200) end it "should respond with javascript MIME type" do - response.headers["Content-Type"].should match("application/javascript") + expect(response.headers["Content-Type"]).to match("application/javascript") end it "should run user code" @@ -46,25 +46,25 @@ end it "should create one and send an opening frame" do - response.chunks.last.should eql("o\n") + expect(response.chunks.last).to eql("o\n") end it "should respond with HTTP 200" do - response.status.should eql(200) + expect(response.status).to eql(200) end it "should respond with javascript MIME type" do - response.headers["Content-Type"].should match("application/javascript") + expect(response.headers["Content-Type"]).to match("application/javascript") end it "should set access control" do - response.headers["Access-Control-Allow-Origin"].should eql(request.origin) - response.headers["Access-Control-Allow-Credentials"].should eql("true") + expect(response.headers["Access-Control-Allow-Origin"]).to eql(request.origin) + expect(response.headers["Access-Control-Allow-Credentials"]).to eql("true") end it "should set session ID" do cookie = response.headers["Set-Cookie"] - cookie.should match("JSESSIONID=#{request.session_id}; path=/") + expect(cookie).to match("JSESSIONID=#{request.session_id}; path=/") end end end @@ -79,24 +79,24 @@ end it "should respond with HTTP 204" do - response.status.should eql(204) + expect(response.status).to eql(204) end it "should set access control" do - response.headers["Access-Control-Allow-Origin"].should eql(request.origin) - response.headers["Access-Control-Allow-Credentials"].should eql("true") + expect(response.headers["Access-Control-Allow-Origin"]).to eql(request.origin) + expect(response.headers["Access-Control-Allow-Credentials"]).to eql("true") end it "should set cache control to be valid for the next year" do time = Time.now + 31536000 - response.headers["Cache-Control"].should eql("public, max-age=31536000") - response.headers["Expires"].should eql(time.gmtime.to_s) - response.headers["Access-Control-Max-Age"].should eql("1000001") + expect(response.headers["Cache-Control"]).to eql("public, max-age=31536000") + expect(response.headers["Expires"]).to eql(time.gmtime.to_s) + expect(response.headers["Access-Control-Max-Age"]).to eql("1000001") end it "should set Allow header to OPTIONS, POST" do - response.headers["Allow"].should eql("OPTIONS, POST") + expect(response.headers["Allow"]).to eql("OPTIONS, POST") end end end @@ -128,21 +128,21 @@ end it "should respond with HTTP 204" do - response.status.should eql(204) + expect(response.status).to eql(204) end it "should respond with plain text MIME type" do - response.headers["Content-Type"].should match("text/plain") + expect(response.headers["Content-Type"]).to match("text/plain") end it "should set session ID" do cookie = response.headers["Set-Cookie"] - cookie.should match("JSESSIONID=#{request.session_id}; path=/") + expect(cookie).to match("JSESSIONID=#{request.session_id}; path=/") end it "should set access control" do - response.headers["Access-Control-Allow-Origin"].should eql(request.origin) - response.headers["Access-Control-Allow-Credentials"].should eql("true") + expect(response.headers["Access-Control-Allow-Origin"]).to eql(request.origin) + expect(response.headers["Access-Control-Allow-Credentials"]).to eql("true") end end @@ -156,7 +156,7 @@ end it "should respond with HTTP 500" do - response.status.should eql(500) + expect(response.status).to eql(500) end it "should report JSON error" do @@ -175,7 +175,7 @@ end it "should respond with HTTP 500" do - response.status.should eql(500) + expect(response.status).to eql(500) end it "should report JSON error" do @@ -187,16 +187,16 @@ context "without a session" do it "should respond with HTTP 404" do - response.status.should eql(404) + expect(response.status).to eql(404) end it "should respond with plain text MIME type" do - response.headers["Content-Type"].should match("text/plain") + expect(response.headers["Content-Type"]).to match("text/plain") end it "should return error message in the body" do response # Run the handler. - request.chunks.last.should match(/Session is not open\!/) + expect(request.chunks.last).to match(/Session is not open\!/) end end end @@ -211,24 +211,24 @@ end it "should respond with HTTP 204" do - response.status.should eql(204) + expect(response.status).to eql(204) end it "should set access control" do - response.headers["Access-Control-Allow-Origin"].should eql(request.origin) - response.headers["Access-Control-Allow-Credentials"].should eql("true") + expect(response.headers["Access-Control-Allow-Origin"]).to eql(request.origin) + expect(response.headers["Access-Control-Allow-Credentials"]).to eql("true") end it "should set cache control to be valid for the next year" do time = Time.now + 31536000 - response.headers["Cache-Control"].should eql("public, max-age=31536000") - response.headers["Expires"].should eql(time.gmtime.to_s) - response.headers["Access-Control-Max-Age"].should eql("1000001") + expect(response.headers["Cache-Control"]).to eql("public, max-age=31536000") + expect(response.headers["Expires"]).to eql(time.gmtime.to_s) + expect(response.headers["Access-Control-Max-Age"]).to eql("1000001") end it "should set Allow header to OPTIONS, POST" do - response.headers["Allow"].should eql("OPTIONS, POST") + expect(response.headers["Allow"]).to eql("OPTIONS, POST") end end end @@ -257,7 +257,7 @@ def transport.try_timer_if_valid(*) end it "should respond with HTTP 200" do - response.status.should eql(200) + expect(response.status).to eql(200) end it "should respond with prelude + open frame" do @@ -266,17 +266,17 @@ def transport.try_timer_if_valid(*) end it "should respond with javascript MIME type" do - response.headers["Content-Type"].should match("application/javascript") + expect(response.headers["Content-Type"]).to match("application/javascript") end it "should set access control" do - response.headers["Access-Control-Allow-Origin"].should eql(request.origin) - response.headers["Access-Control-Allow-Credentials"].should eql("true") + expect(response.headers["Access-Control-Allow-Origin"]).to eql(request.origin) + expect(response.headers["Access-Control-Allow-Credentials"]).to eql("true") end it "should set session ID" do cookie = response.headers["Set-Cookie"] - cookie.should match("JSESSIONID=#{request.session_id}; path=/") + expect(cookie).to match("JSESSIONID=#{request.session_id}; path=/") end end end @@ -290,24 +290,24 @@ def transport.try_timer_if_valid(*) end it "should respond with HTTP 204" do - response.status.should eql(204) + expect(response.status).to eql(204) end it "should set access control" do - response.headers["Access-Control-Allow-Origin"].should eql(request.origin) - response.headers["Access-Control-Allow-Credentials"].should eql("true") + expect(response.headers["Access-Control-Allow-Origin"]).to eql(request.origin) + expect(response.headers["Access-Control-Allow-Credentials"]).to eql("true") end it "should set cache control to be valid for the next year" do time = Time.now + 31536000 - response.headers["Cache-Control"].should eql("public, max-age=31536000") - response.headers["Expires"].should eql(time.gmtime.to_s) - response.headers["Access-Control-Max-Age"].should eql("1000001") + expect(response.headers["Cache-Control"]).to eql("public, max-age=31536000") + expect(response.headers["Expires"]).to eql(time.gmtime.to_s) + expect(response.headers["Access-Control-Max-Age"]).to eql("1000001") end it "should set Allow header to OPTIONS, POST" do - response.headers["Allow"].should eql("OPTIONS, POST") + expect(response.headers["Allow"]).to eql("OPTIONS, POST") end end end diff --git a/spec/sockjs/version_spec.rb b/spec/sockjs/version_spec.rb index c01e334..a2b8208 100755 --- a/spec/sockjs/version_spec.rb +++ b/spec/sockjs/version_spec.rb @@ -7,12 +7,12 @@ describe SockJS do it "should define VERSION" do constants = described_class.constants.map(&:to_sym) - constants.should include(:GEM_VERSION) + expect(constants).to include(:GEM_VERSION) SockJS::GEM_VERSION.should be_an_instance_of(String) end it "should define PROTOCOL_VERSION" do constants = described_class.constants.map(&:to_sym) - constants.should include(:PROTOCOL_VERSION) + expect(constants).to include(:PROTOCOL_VERSION) end end From e1820b4c42ca0a09f560a40cb92b68010de2ef54 Mon Sep 17 00:00:00 2001 From: Kacper Kawecki Date: Fri, 31 Jan 2025 10:03:50 +0400 Subject: [PATCH 14/15] Refactor --- lib/sockjs/servers/request.rb | 12 +----------- lib/sockjs/version.rb | 2 +- 2 files changed, 2 insertions(+), 12 deletions(-) diff --git a/lib/sockjs/servers/request.rb b/lib/sockjs/servers/request.rb index e83d4cf..ef5c173 100644 --- a/lib/sockjs/servers/request.rb +++ b/lib/sockjs/servers/request.rb @@ -120,7 +120,7 @@ def content_type def callback callback = self.query_string["callback"] || self.query_string["c"] - unescape(callback) if callback + URI.decode_www_form_component(callback) if callback end def keep_alive? @@ -134,15 +134,5 @@ def session_id def fresh?(etag) self.headers["if-none-match"] == etag end - - private - - def unescape(string) - if Gem::Version.new(RUBY_VERSION) < Gem::Version.new('3.0.0') - URI.unescape(string) - else - URI.decode_www_form_component(string) - end - end end end diff --git a/lib/sockjs/version.rb b/lib/sockjs/version.rb index 2e795dd..02bc992 100644 --- a/lib/sockjs/version.rb +++ b/lib/sockjs/version.rb @@ -7,7 +7,7 @@ module SockJS PROTOCOL_VERSION_STRING = PROTOCOL_VERSION.join('.') # Patch version of the gem. - PATCH_VERSION = [2].freeze + PATCH_VERSION = [3].freeze GEM_VERSION = (PROTOCOL_VERSION + PATCH_VERSION).join('.') end From a4571c1073986a86764b23f07989d65c3c16db29 Mon Sep 17 00:00:00 2001 From: Kacper Kawecki Date: Fri, 31 Jan 2025 10:29:00 +0400 Subject: [PATCH 15/15] Add missing dependencies --- Gemfile | 2 +- Gemfile.lock | 45 ++++++++++++--------------------------------- Rakefile | 43 +++---------------------------------------- sockjs.gemspec | 8 +++++--- 4 files changed, 21 insertions(+), 77 deletions(-) diff --git a/Gemfile b/Gemfile index 65201c5..a311924 100644 --- a/Gemfile +++ b/Gemfile @@ -1,10 +1,10 @@ # encoding: utf-8 source "https://rubygems.org" -gem 'corundum' gem "thin", ">=1.8.2" gem "rack" gem "faye-websocket" +gem "rake" gemspec diff --git a/Gemfile.lock b/Gemfile.lock index ca9dc84..2e69951 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,30 +1,21 @@ PATH remote: . specs: - sockjs (0.3.4.2) + sockjs (0.3.4.3) faye-websocket (~> 0.11.3) json + racc rack rack-mount (~> 0.8.3) + sorted_set thin GEM remote: https://rubygems.org/ specs: base64 (0.2.0) - calibrate (0.0.1) - caliph (0.3.1) - corundum (0.6.1) - bundler - caliph (~> 0.3) - mattock (~> 0.9) - paint (~> 0.8.7) - rspec (>= 2.0) - simplecov (>= 0.5.4) - simplecov-json (>= 0.2) daemons (1.4.1) diff-lcs (1.5.1) - docile (1.4.1) eventmachine (1.2.7) faye-websocket (0.11.3) eventmachine (>= 0.12.0) @@ -32,19 +23,14 @@ GEM json (2.9.1) macaddr (1.7.2) systemu (~> 2.6.5) - mattock (0.10.1) - calibrate (~> 0.0.1) - caliph (~> 0.3) - rake (~> 10.0) - tilt (> 0) - valise (~> 1.1) - paint (0.8.7) + racc (1.8.1) rack (2.2.10) rack-mount (0.8.3) rack (>= 1.0.0) rack-test (2.2.0) rack (>= 1.3) - rake (10.5.0) + rake (13.2.1) + rbtree (0.4.6) rspec (3.13.0) rspec-core (~> 3.13.0) rspec-expectations (~> 3.13.0) @@ -58,24 +44,17 @@ GEM diff-lcs (>= 1.2.0, < 2.0) rspec-support (~> 3.13.0) rspec-support (3.13.2) - simplecov (0.22.0) - docile (~> 1.1) - simplecov-html (~> 0.11) - simplecov_json_formatter (~> 0.1) - simplecov-html (0.13.1) - simplecov-json (0.2.3) - json - simplecov - simplecov_json_formatter (0.1.4) + set (1.1.1) + sorted_set (1.0.3) + rbtree + set (~> 1.0) systemu (2.6.5) thin (1.8.2) daemons (~> 1.0, >= 1.0.9) eventmachine (~> 1.0, >= 1.0.4) rack (>= 1, < 3) - tilt (2.6.0) uuid (2.3.9) macaddr (~> 1.0) - valise (1.2.1) websocket-driver (0.7.7) base64 websocket-extensions (>= 0.1.0) @@ -87,14 +66,14 @@ PLATFORMS arm64-darwin-24 DEPENDENCIES - corundum faye-websocket rack rack-test + rake rspec sockjs! thin (>= 1.8.2) uuid BUNDLED WITH - 2.3.9 + 2.6.3 diff --git a/Rakefile b/Rakefile index d996c86..a74c3b3 100644 --- a/Rakefile +++ b/Rakefile @@ -1,46 +1,9 @@ -# vim: set ft=ruby : -require 'corundum/tasklibs' - -module Corundum - Corundum::register_project(__FILE__) - - core = Core.new - - core.in_namespace do - GemspecFiles.new(core) - QuestionableContent.new(core) do |dbg| - dbg.words = %w{debug! debugger} - end - rspec = RSpec.new(core) - cov = SimpleCov.new(core, rspec) do |cov| - cov.threshold = 70 - cov.coverage_filter = proc do |path| - /\.rb$/ =~ path and /version/ !~ path - end - end - - gem = GemBuilding.new(core) - cutter = GemCutter.new(core,gem) - email = Email.new(core) - vc = Git.new(core) do |vc| - vc.branch = "master" - end - - yd = YARDoc.new(core) - - docs = DocumentationAssembly.new(core, yd, rspec, cov) - - pages = GithubPages.new(docs) - end -end - -task :default => [:release, :publish_docs] - - # Get list of all the tests in format for TODO.todo. +require 'socket' +Bundler.require(:default, :development) task :unpack_tests do - version = "0.2.1" + version = "0.3.4" tests = {} File.foreach("protocol/sockjs-protocol-#{version}.py").each_with_object(tests) do |line, buffer| diff --git a/sockjs.gemspec b/sockjs.gemspec index 758a987..c8fc207 100755 --- a/sockjs.gemspec +++ b/sockjs.gemspec @@ -18,11 +18,13 @@ Gem::Specification.new do |s| s.required_ruby_version = ::Gem::Requirement.new('>= 3.0') # Dependencies - s.add_dependency 'rack' - s.add_dependency 'thin' - s.add_dependency 'json' s.add_dependency 'faye-websocket', '~> 0.11.3' + s.add_dependency 'json' + s.add_dependency 'racc' + s.add_dependency 'rack' s.add_dependency 'rack-mount', '~> 0.8.3' + s.add_dependency 'sorted_set' + s.add_dependency 'thin' # Files s.files = %w[