From 8dea861b24c4b967cacdea51091ecfbe54e8d859 Mon Sep 17 00:00:00 2001 From: sachin shinde Date: Thu, 7 Mar 2024 19:30:38 +0000 Subject: [PATCH 01/19] fixed failing test due to old simplecov dependency --- ably.gemspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ably.gemspec b/ably.gemspec index bbe1dfcb3..da65405a7 100644 --- a/ably.gemspec +++ b/ably.gemspec @@ -38,7 +38,7 @@ Gem::Specification.new do |spec| spec.add_development_dependency 'rspec-instafail', '~> 1.0' spec.add_development_dependency 'bundler', '>= 1.3.0' spec.add_development_dependency 'webmock', '~> 3.11' - spec.add_development_dependency 'simplecov', '~> 0.21.2' + spec.add_development_dependency 'simplecov', '~> 0.22.0' spec.add_development_dependency 'simplecov-lcov', '~> 0.8.0' spec.add_development_dependency 'parallel_tests', '~> 3.8' spec.add_development_dependency 'pry', '~> 0.14.1' From 171075e1ac1f1b4016c403ae205d009be272b811 Mon Sep 17 00:00:00 2001 From: sacOO7 Date: Mon, 22 Apr 2024 20:11:04 +0530 Subject: [PATCH 02/19] Included CI support for ruby 3.2 and 3.3 --- .github/workflows/check.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/check.yml b/.github/workflows/check.yml index c5924660a..f9ebe5225 100644 --- a/.github/workflows/check.yml +++ b/.github/workflows/check.yml @@ -10,7 +10,7 @@ jobs: continue-on-error: true strategy: matrix: - ruby: [ '2.7', '3.0', '3.1' ] + ruby: [ '2.7', '3.0', '3.1', '3.2', '3.3' ] protocol: [ 'json', 'msgpack' ] type: [ 'unit', 'acceptance' ] steps: From e5df18be1d1893f095b469e6421a9b9c29e7c58b Mon Sep 17 00:00:00 2001 From: sacOO7 Date: Mon, 22 Apr 2024 20:11:32 +0530 Subject: [PATCH 03/19] Refactored author emails in the gemspec --- ably.gemspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ably.gemspec b/ably.gemspec index da65405a7..aa461b51c 100644 --- a/ably.gemspec +++ b/ably.gemspec @@ -7,7 +7,7 @@ Gem::Specification.new do |spec| spec.name = 'ably' spec.version = Ably::VERSION spec.authors = ['Lewis Marshall', "Matthew O'Riordan"] - spec.email = ['lewis@lmars.net', 'matt@ably.io'] + spec.email = %w[lewis@lmars.net matt@ably.io] spec.description = %q{A Ruby client library for ably.io realtime messaging} spec.summary = %q{A Ruby client library for ably.io realtime messaging implemented using EventMachine} spec.homepage = 'http://github.com/ably/ably-ruby' From f811abbd21c7fa983442e47d2e344f2728225503 Mon Sep 17 00:00:00 2001 From: sacOO7 Date: Tue, 23 Apr 2024 13:59:27 +0530 Subject: [PATCH 04/19] Updated ably-common git submodules --- lib/submodules/ably-common | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/submodules/ably-common b/lib/submodules/ably-common index 1042fb1c8..04902355d 160000 --- a/lib/submodules/ably-common +++ b/lib/submodules/ably-common @@ -1 +1 @@ -Subproject commit 1042fb1c8f74b2d1aea0ab7c8ea5d59ed60d67f8 +Subproject commit 04902355d9a002f9103531e282911bb6988b9841 From e5a87532dc266aebfb195ed9ad45b01978ea8995 Mon Sep 17 00:00:00 2001 From: sacOO7 Date: Tue, 23 Apr 2024 16:24:49 +0530 Subject: [PATCH 05/19] updated CI to update SSL certificates to fix openSSL errors --- .github/workflows/check.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/check.yml b/.github/workflows/check.yml index f9ebe5225..1cdf688b4 100644 --- a/.github/workflows/check.yml +++ b/.github/workflows/check.yml @@ -29,6 +29,8 @@ jobs: TEST_TYPE: ${{ matrix.type }} RUBY_VERSION: ${{ matrix.ruby }} run: | + sudo apt-get update + sudo apt-get install ca-certificates mkdir junit bundle exec parallel_rspec --prefix-output-with-test-env-number --first-is-1 -- spec/${{ matrix.type }} - uses: actions/upload-artifact@v3 From 627e59de5c78f99aa1ef3abeacfe0a5d8604ff2e Mon Sep 17 00:00:00 2001 From: sacOO7 Date: Mon, 29 Apr 2024 17:28:57 +0530 Subject: [PATCH 06/19] Removed code duplication from ruby encrypt and decrypt string --- spec/unit/util/crypto_spec.rb | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/spec/unit/util/crypto_spec.rb b/spec/unit/util/crypto_spec.rb index bd93b9da1..1cd77e96a 100644 --- a/spec/unit/util/crypto_spec.rb +++ b/spec/unit/util/crypto_spec.rb @@ -74,17 +74,12 @@ context 'encrypts & decrypt' do let(:string) { random_str } - let(:byte_array) { random_str.to_msgpack.unpack('C*') } - specify '#encrypt encrypts a string' do + specify '#encrypts and decrypts a string' do encrypted = subject.encrypt(string) expect(subject.decrypt(encrypted)).to eql(string) end - specify '#decrypt decrypts a string' do - encrypted = subject.encrypt(string) - expect(subject.decrypt(encrypted)).to eql(string) - end end context 'encrypting an empty string' do From 218f120501b151d083141133ca5e8406f2e7aae5 Mon Sep 17 00:00:00 2001 From: sacOO7 Date: Mon, 29 Apr 2024 17:37:05 +0530 Subject: [PATCH 07/19] Refactored empty string encryption/decryption test --- spec/unit/util/crypto_spec.rb | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/spec/unit/util/crypto_spec.rb b/spec/unit/util/crypto_spec.rb index 1cd77e96a..d2ccb5e4b 100644 --- a/spec/unit/util/crypto_spec.rb +++ b/spec/unit/util/crypto_spec.rb @@ -74,20 +74,26 @@ context 'encrypts & decrypt' do let(:string) { random_str } + let(:empty_string) { '' } specify '#encrypts and decrypts a string' do + expect(string).to be_ascii_only encrypted = subject.encrypt(string) - expect(subject.decrypt(encrypted)).to eql(string) + expect(encrypted).to be_truthy + decrypted = subject.decrypt(encrypted) + expect(decrypted).to eql(string) + expect(decrypted).to be_ascii_only end - end - - context 'encrypting an empty string' do - let(:empty_string) { '' } - - it 'raises an ArgumentError' do - expect { subject.encrypt(empty_string) }.to raise_error ArgumentError, /data must not be empty/ + specify '#encrypts and decrypts an empty string' do + expect(empty_string).to be_ascii_only + encrypted = subject.encrypt(empty_string) + expect(encrypted).to be_truthy + decrypted = subject.decrypt(encrypted) + expect(decrypted).to eql(empty_string) + expect(decrypted).to be_ascii_only end + end context 'using shared client lib fixture data' do From a0a3b98c997944abeb8edb7adc5157bf0188c1eb Mon Sep 17 00:00:00 2001 From: sacOO7 Date: Mon, 29 Apr 2024 21:35:39 +0530 Subject: [PATCH 08/19] Fixed empty string encryption using openSSL crypto --- lib/ably/util/crypto.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/ably/util/crypto.rb b/lib/ably/util/crypto.rb index 3635b59a5..7707af93e 100644 --- a/lib/ably/util/crypto.rb +++ b/lib/ably/util/crypto.rb @@ -83,8 +83,8 @@ def encrypt(payload, encrypt_options = {}) cipher.key = key iv = encrypt_options[:iv] || fixed_iv || cipher.random_iv cipher.iv = iv - - iv << cipher.update(payload) << cipher.final + iv << cipher.update(payload) unless payload.empty? + iv << cipher.final end # Decrypt payload using configured Cipher From 46536b12d8eda2705c870c9a6c692a4397281e2b Mon Sep 17 00:00:00 2001 From: sacOO7 Date: Tue, 30 Apr 2024 17:46:33 +0530 Subject: [PATCH 09/19] Added ably em http request as an explicit dependency --- Gemfile | 2 + ably.gemspec | 2 +- lib/ably/realtime/connection.rb | 64 ++++++++++----------- spec/acceptance/realtime/connection_spec.rb | 30 +++++----- 4 files changed, 50 insertions(+), 48 deletions(-) diff --git a/Gemfile b/Gemfile index 5d0856f56..e789e4268 100644 --- a/Gemfile +++ b/Gemfile @@ -2,3 +2,5 @@ source 'https://rubygems.org' # Specify your gem's dependencies in ably.gemspec gemspec +# TODO remove this line once we’ve published our fork to RubyGems +gem 'ably-em-http-request', git: 'https://github.com/ably-forks/em-http-request', ref: '80b79cf6cedc86791b61c5be74a6da3a66ab2ee9' diff --git a/ably.gemspec b/ably.gemspec index aa461b51c..f9ca7c5e0 100644 --- a/ably.gemspec +++ b/ably.gemspec @@ -19,7 +19,7 @@ Gem::Specification.new do |spec| spec.require_paths = ['lib'] spec.add_runtime_dependency 'eventmachine', '~> 1.2.6' - spec.add_runtime_dependency 'em-http-request', '~> 1.1' + spec.add_runtime_dependency 'ably-em-http-request', '~> 1.1' spec.add_runtime_dependency 'statesman', '~> 9.0' spec.add_runtime_dependency 'faraday', '~> 2.2' spec.add_runtime_dependency 'faraday-typhoeus', '~> 0.2.0' diff --git a/lib/ably/realtime/connection.rb b/lib/ably/realtime/connection.rb index 2eeacb12a..e07f33764 100644 --- a/lib/ably/realtime/connection.rb +++ b/lib/ably/realtime/connection.rb @@ -23,26 +23,26 @@ class Connection # or no host is available. The disconnected state is entered if an established connection is dropped, # or if a connection attempt was unsuccessful. In the disconnected state the library will periodically # attempt to open a new connection (approximately every 15 seconds), anticipating that the connection - # will be re-established soon and thus connection and channel continuity will be possible. + # will be re-established soon and thus connection and channel continuity will be possible. # In this state, developers can continue to publish messages as they are automatically placed - # in a local queue, to be sent as soon as a connection is reestablished. Messages published by + # in a local queue, to be sent as soon as a connection is reestablished. Messages published by # other clients while this client is disconnected will be delivered to it upon reconnection, - # so long as the connection was resumed within 2 minutes. After 2 minutes have elapsed, recovery + # so long as the connection was resumed within 2 minutes. After 2 minutes have elapsed, recovery # is no longer possible and the connection will move to the SUSPENDED state. - # SUSPENDED A long term failure condition. No current connection exists because there is no network connectivity - # or no host is available. The suspended state is entered after a failed connection attempt if - # there has then been no connection for a period of two minutes. In the suspended state, the library - # will periodically attempt to open a new connection every 30 seconds. Developers are unable to + # SUSPENDED A long term failure condition. No current connection exists because there is no network connectivity + # or no host is available. The suspended state is entered after a failed connection attempt if + # there has then been no connection for a period of two minutes. In the suspended state, the library + # will periodically attempt to open a new connection every 30 seconds. Developers are unable to # publish messages in this state. A new connection attempt can also be triggered by an explicit - # call to {Ably::Realtime::Connection#connect}. Once the connection has been re-established, - # channels will be automatically re-attached. The client has been disconnected for too long for them - # to resume from where they left off, so if it wants to catch up on messages published by other clients + # call to {Ably::Realtime::Connection#connect}. Once the connection has been re-established, + # channels will be automatically re-attached. The client has been disconnected for too long for them + # to resume from where they left off, so if it wants to catch up on messages published by other clients # while it was disconnected, it needs to use the History API. - # CLOSING An explicit request by the developer to close the connection has been sent to the Ably service. - # If a reply is not received from Ably within a short period of time, the connection is forcibly + # CLOSING An explicit request by the developer to close the connection has been sent to the Ably service. + # If a reply is not received from Ably within a short period of time, the connection is forcibly # terminated and the connection state becomes CLOSED. - # CLOSED The connection has been explicitly closed by the client. In the closed state, no reconnection attempts - # are made automatically by the library, and clients may not publish messages. No connection state is + # CLOSED The connection has been explicitly closed by the client. In the closed state, no reconnection attempts + # are made automatically by the library, and clients may not publish messages. No connection state is # preserved by the service or by the library. A new connection attempt can be triggered by an explicit # call to {Ably::Realtime::Connection#connect}, which results in a new connection. # FAILED This state is entered if the client library encounters a failure condition that it cannot recover from. @@ -55,14 +55,14 @@ class Connection # @return [Ably::Realtime::Connection::STATE] # STATE = ruby_enum('STATE', - :initialized, - :connecting, - :connected, - :disconnected, - :suspended, - :closing, - :closed, - :failed + :initialized, + :connecting, + :connected, + :disconnected, + :suspended, + :closing, + :closed, + :failed ) # Describes the events emitted by a {Ably::Realtime::Connection} object. An event is either an UPDATE or a {Ably::Realtime::Connection::STATE}. @@ -70,7 +70,7 @@ class Connection # UPDATE RTN4h An event for changes to connection conditions for which the {Ably::Realtime::Connection::STATE} does not change. # EVENT = ruby_enum('EVENT', - STATE.to_sym_arr + [:update] + STATE.to_sym_arr + [:update] ) include Ably::Modules::StateEmitter @@ -327,7 +327,7 @@ def ping(&block) def internet_up? url = "http#{'s' if client.use_tls?}:#{Ably::INTERNET_CHECK.fetch(:url)}" EventMachine::DefaultDeferrable.new.tap do |deferrable| - EventMachine::HttpRequest.new(url, tls: { verify_peer: true }).get.tap do |http| + EventMachine::AblyHttpRequest::HttpRequest.new(url, tls: { verify_peer: true }).get.tap do |http| http.errback do yield false if block_given? deferrable.fail Ably::Exceptions::ConnectionFailed.new("Unable to connect to #{url}", nil, Ably::Exceptions::Codes::CONNECTION_FAILED) @@ -407,10 +407,10 @@ def determine_host if should_use_fallback_hosts? internet_up? do |internet_is_up_result| @current_host = if internet_is_up_result - client.fallback_endpoint.host - else - client.endpoint.host - end + client.fallback_endpoint.host + else + client.endpoint.host + end yield current_host end else @@ -478,10 +478,10 @@ def create_websocket_transport # Use native websocket heartbeats if possible, but allow Ably protocol heartbeats url_params['heartbeats'] = if defaults.fetch(:websocket_heartbeats_disabled) - 'true' - else - 'false' - end + 'true' + else + 'false' + end url_params['clientId'] = client.auth.client_id if client.auth.has_client_id? url_params.merge!(client.transport_params) diff --git a/spec/acceptance/realtime/connection_spec.rb b/spec/acceptance/realtime/connection_spec.rb index 4cbc7b405..68ed69b55 100644 --- a/spec/acceptance/realtime/connection_spec.rb +++ b/spec/acceptance/realtime/connection_spec.rb @@ -153,8 +153,8 @@ first_disconnected_at = nil connection.on(:disconnected) do |connection_state_change| first_disconnected_at ||= begin - Time.now.to_f - end + Time.now.to_f + end expect(connection_state_change.reason.code).to eql(40142) # token expired if disconnect_count == 4 # 3 attempts to reconnect after initial # First disconnect reattempts immediately as part of connect sequence @@ -181,9 +181,9 @@ it 'uses the primary host for subsequent connection and auth requests' do connection.once(:disconnected) do expect(client.rest_client.connection).to receive(:post). - with(/requestToken$/, anything). - exactly(:twice). # it retries an expired token request immediately - and_call_original + with(/requestToken$/, anything). + exactly(:twice). # it retries an expired token request immediately + and_call_original expect(client.rest_client).to_not receive(:fallback_connection) expect(client).to_not receive(:fallback_endpoint) @@ -1702,13 +1702,13 @@ def self.available_states end context 'internet up URL protocol' do - let(:http_request) { double('EventMachine::HttpRequest', get: EventMachine::DefaultDeferrable.new) } + let(:http_request) { double('EventMachine::AblyHttpRequest::HttpRequest', get: EventMachine::DefaultDeferrable.new) } context 'when using TLS for the connection' do let(:client_options) { default_options.merge(tls: true) } it 'uses TLS for the Internet check to https://internet-up.ably-realtime.com/is-the-internet-up.txt' do - expect(EventMachine::HttpRequest).to receive(:new).with('https://internet-up.ably-realtime.com/is-the-internet-up.txt', { tls: { verify_peer: true } }).and_return(http_request) + expect(EventMachine::AblyHttpRequest::HttpRequest).to receive(:new).with('https://internet-up.ably-realtime.com/is-the-internet-up.txt', { tls: { verify_peer: true } }).and_return(http_request) connection.internet_up? stop_reactor end @@ -1718,7 +1718,7 @@ def self.available_states let(:client_options) { default_options.merge(tls: false, use_token_auth: true) } it 'uses TLS for the Internet check to http://internet-up.ably-realtime.com/is-the-internet-up.txt' do - expect(EventMachine::HttpRequest).to receive(:new).with('http://internet-up.ably-realtime.com/is-the-internet-up.txt', { tls: { verify_peer: true } }).and_return(http_request) + expect(EventMachine::AblyHttpRequest::HttpRequest).to receive(:new).with('http://internet-up.ably-realtime.com/is-the-internet-up.txt', { tls: { verify_peer: true } }).and_return(http_request) connection.internet_up? stop_reactor end @@ -1732,7 +1732,7 @@ def self.available_states let(:client_options) { default_options.merge(tls: true) } it 'checks the Internet up URL over TLS' do - expect(EventMachine::HttpRequest).to receive(:new).with("https:#{Ably::INTERNET_CHECK.fetch(:url)}", { tls: { verify_peer: true } }).and_return(double('request', get: EventMachine::DefaultDeferrable.new)) + expect(EventMachine::AblyHttpRequest::HttpRequest).to receive(:new).with("https:#{Ably::INTERNET_CHECK.fetch(:url)}", { tls: { verify_peer: true } }).and_return(double('request', get: EventMachine::DefaultDeferrable.new)) connection.internet_up? stop_reactor end @@ -1742,7 +1742,7 @@ def self.available_states let(:client_options) { default_options.merge(tls: false, use_token_auth: true) } it 'checks the Internet up URL over TLS' do - expect(EventMachine::HttpRequest).to receive(:new).with("http:#{Ably::INTERNET_CHECK.fetch(:url)}", { tls: { verify_peer: true } }).and_return(double('request', get: EventMachine::DefaultDeferrable.new)) + expect(EventMachine::AblyHttpRequest::HttpRequest).to receive(:new).with("http:#{Ably::INTERNET_CHECK.fetch(:url)}", { tls: { verify_peer: true } }).and_return(double('request', get: EventMachine::DefaultDeferrable.new)) connection.internet_up? stop_reactor end @@ -2109,12 +2109,12 @@ def self.available_states it 'pases transport_params to query' do expect(EventMachine).to receive(:connect) do |host, port, transport, object, url| - uri = URI.parse(url) - expect(CGI::parse(uri.query)['extra_param'][0]).to eq('extra_param') - stop_reactor - end + uri = URI.parse(url) + expect(CGI::parse(uri.query)['extra_param'][0]).to eq('extra_param') + stop_reactor + end - client + client end context 'when changing default param' do From 22ed1f3826ff032e49b99b9e2378e51bba219898 Mon Sep 17 00:00:00 2001 From: sacOO7 Date: Tue, 30 Apr 2024 18:13:59 +0530 Subject: [PATCH 10/19] Disabled bundler cache for ruby --- .github/workflows/check.yml | 2 +- .github/workflows/docs.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/check.yml b/.github/workflows/check.yml index 1cdf688b4..642505750 100644 --- a/.github/workflows/check.yml +++ b/.github/workflows/check.yml @@ -20,7 +20,7 @@ jobs: - uses: ruby/setup-ruby@v1 with: ruby-version: ${{ matrix.ruby }} - bundler-cache: true + bundler-cache: false - name: 'Run ${{ matrix.type }} tests on ruby ${{ matrix.ruby }} (${{ matrix.protocol }} protocol)' env: PARALLEL_TEST_PROCESSORS: 2 diff --git a/.github/workflows/docs.yml b/.github/workflows/docs.yml index 890e0eab1..4c18f4103 100644 --- a/.github/workflows/docs.yml +++ b/.github/workflows/docs.yml @@ -15,7 +15,7 @@ jobs: - uses: ruby/setup-ruby@v1 with: ruby-version: '2.7' - bundler-cache: true + bundler-cache: false - name: Build Documentation run: | From d93df4f54bc087729525726be54d244cf2c4fbf7 Mon Sep 17 00:00:00 2001 From: sacOO7 Date: Tue, 30 Apr 2024 18:19:36 +0530 Subject: [PATCH 11/19] added bundle install command for parallel_rspec --- .github/workflows/check.yml | 1 + .github/workflows/docs.yml | 1 + ably.gemspec | 1 + 3 files changed, 3 insertions(+) diff --git a/.github/workflows/check.yml b/.github/workflows/check.yml index 642505750..70d8198f5 100644 --- a/.github/workflows/check.yml +++ b/.github/workflows/check.yml @@ -32,6 +32,7 @@ jobs: sudo apt-get update sudo apt-get install ca-certificates mkdir junit + bundle install bundle exec parallel_rspec --prefix-output-with-test-env-number --first-is-1 -- spec/${{ matrix.type }} - uses: actions/upload-artifact@v3 with: diff --git a/.github/workflows/docs.yml b/.github/workflows/docs.yml index 4c18f4103..b967e4b9f 100644 --- a/.github/workflows/docs.yml +++ b/.github/workflows/docs.yml @@ -19,6 +19,7 @@ jobs: - name: Build Documentation run: | + bundle install bundle exec yard --readme INTRO.md --tag "spec:Specification" ls -al doc/ - name: Configure AWS Credentials diff --git a/ably.gemspec b/ably.gemspec index f9ca7c5e0..4d39bc224 100644 --- a/ably.gemspec +++ b/ably.gemspec @@ -41,6 +41,7 @@ Gem::Specification.new do |spec| spec.add_development_dependency 'simplecov', '~> 0.22.0' spec.add_development_dependency 'simplecov-lcov', '~> 0.8.0' spec.add_development_dependency 'parallel_tests', '~> 3.8' + spec.add_development_dependency 'parallel_rspec', '~> 2.4' spec.add_development_dependency 'pry', '~> 0.14.1' spec.add_development_dependency 'pry-byebug', '~> 3.8.0' From 2ebc4aa29da3ba06e4bbf610d7ab6cf693af20ba Mon Sep 17 00:00:00 2001 From: sacOO7 Date: Tue, 30 Apr 2024 18:38:46 +0530 Subject: [PATCH 12/19] Revert "added bundle install command for parallel_rspec" This reverts commit d93df4f54bc087729525726be54d244cf2c4fbf7. --- .github/workflows/check.yml | 1 - .github/workflows/docs.yml | 1 - ably.gemspec | 1 - 3 files changed, 3 deletions(-) diff --git a/.github/workflows/check.yml b/.github/workflows/check.yml index 70d8198f5..642505750 100644 --- a/.github/workflows/check.yml +++ b/.github/workflows/check.yml @@ -32,7 +32,6 @@ jobs: sudo apt-get update sudo apt-get install ca-certificates mkdir junit - bundle install bundle exec parallel_rspec --prefix-output-with-test-env-number --first-is-1 -- spec/${{ matrix.type }} - uses: actions/upload-artifact@v3 with: diff --git a/.github/workflows/docs.yml b/.github/workflows/docs.yml index b967e4b9f..4c18f4103 100644 --- a/.github/workflows/docs.yml +++ b/.github/workflows/docs.yml @@ -19,7 +19,6 @@ jobs: - name: Build Documentation run: | - bundle install bundle exec yard --readme INTRO.md --tag "spec:Specification" ls -al doc/ - name: Configure AWS Credentials diff --git a/ably.gemspec b/ably.gemspec index 4d39bc224..f9ca7c5e0 100644 --- a/ably.gemspec +++ b/ably.gemspec @@ -41,7 +41,6 @@ Gem::Specification.new do |spec| spec.add_development_dependency 'simplecov', '~> 0.22.0' spec.add_development_dependency 'simplecov-lcov', '~> 0.8.0' spec.add_development_dependency 'parallel_tests', '~> 3.8' - spec.add_development_dependency 'parallel_rspec', '~> 2.4' spec.add_development_dependency 'pry', '~> 0.14.1' spec.add_development_dependency 'pry-byebug', '~> 3.8.0' From 3d792ec437207fe6a10a838f728ce05f41ea999e Mon Sep 17 00:00:00 2001 From: sacOO7 Date: Tue, 30 Apr 2024 18:40:03 +0530 Subject: [PATCH 13/19] Fixed ably-em-http-request commit hash --- .github/workflows/check.yml | 2 +- .github/workflows/docs.yml | 2 +- Gemfile | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/check.yml b/.github/workflows/check.yml index 642505750..1cdf688b4 100644 --- a/.github/workflows/check.yml +++ b/.github/workflows/check.yml @@ -20,7 +20,7 @@ jobs: - uses: ruby/setup-ruby@v1 with: ruby-version: ${{ matrix.ruby }} - bundler-cache: false + bundler-cache: true - name: 'Run ${{ matrix.type }} tests on ruby ${{ matrix.ruby }} (${{ matrix.protocol }} protocol)' env: PARALLEL_TEST_PROCESSORS: 2 diff --git a/.github/workflows/docs.yml b/.github/workflows/docs.yml index 4c18f4103..890e0eab1 100644 --- a/.github/workflows/docs.yml +++ b/.github/workflows/docs.yml @@ -15,7 +15,7 @@ jobs: - uses: ruby/setup-ruby@v1 with: ruby-version: '2.7' - bundler-cache: false + bundler-cache: true - name: Build Documentation run: | diff --git a/Gemfile b/Gemfile index e789e4268..ef61220af 100644 --- a/Gemfile +++ b/Gemfile @@ -3,4 +3,4 @@ source 'https://rubygems.org' # Specify your gem's dependencies in ably.gemspec gemspec # TODO remove this line once we’ve published our fork to RubyGems -gem 'ably-em-http-request', git: 'https://github.com/ably-forks/em-http-request', ref: '80b79cf6cedc86791b61c5be74a6da3a66ab2ee9' +gem 'ably-em-http-request', git: 'https://github.com/ably-forks/em-http-request', ref: '9996b7b8db3a8c8f57c56854730a085955a652f0' From bcfebffc276bd715558f84b4e2a7ef61022b6666 Mon Sep 17 00:00:00 2001 From: sacOO7 Date: Wed, 1 May 2024 15:44:24 +0530 Subject: [PATCH 14/19] Added clock skew for renewing token after it expires --- spec/acceptance/realtime/connection_spec.rb | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/spec/acceptance/realtime/connection_spec.rb b/spec/acceptance/realtime/connection_spec.rb index 68ed69b55..c869dec53 100644 --- a/spec/acceptance/realtime/connection_spec.rb +++ b/spec/acceptance/realtime/connection_spec.rb @@ -102,6 +102,7 @@ end let(:ttl) { 2 } + let(:skew) { 0.1 } it 'renews token every time after it expires' do started_at = Time.now.to_f @@ -114,8 +115,8 @@ disconnected_times += 1 if disconnected_times == 3 expect(connected_times).to eql(3) - expect(Time.now.to_f - started_at).to be > ttl * 3 - expect(Time.now.to_f - started_at).to be < (ttl * 2) * 3 + expect((Time.now.to_f - started_at) + skew).to be > ttl * 3 + expect((Time.now.to_f - started_at) + skew).to be < (ttl * 2) * 3 stop_reactor end end From f26dec927c6663e86d0971ba7bd5f80e533eb38d Mon Sep 17 00:00:00 2001 From: sacOO7 Date: Wed, 1 May 2024 16:48:49 +0530 Subject: [PATCH 15/19] Added clock skew for flaky unit test --- spec/unit/models/token_details_spec.rb | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/spec/unit/models/token_details_spec.rb b/spec/unit/models/token_details_spec.rb index c9bdc40d2..76dc05cf5 100644 --- a/spec/unit/models/token_details_spec.rb +++ b/spec/unit/models/token_details_spec.rb @@ -56,6 +56,7 @@ context '#expired?' do let(:expire_time) { Time.now + Ably::Models::TokenDetails::TOKEN_EXPIRY_BUFFER } + let(:clock_skew) { 1 } # clock skew of 1 second context 'once grace period buffer has passed' do subject { Ably::Models::TokenDetails.new(expires: expire_time - 1) } @@ -74,7 +75,7 @@ end context 'when expires is not available (i.e. string tokens)' do - subject { Ably::Models::TokenDetails.new() } + subject { Ably::Models::TokenDetails.new } it 'is always false' do expect(subject.expired?).to eql(false) @@ -91,7 +92,7 @@ end it 'is true' do - expect(subject.expired?(from: Time.now)).to eql(true) + expect(subject.expired?(from: Time.now + clock_skew)).to eql(true) end end end From 754c158358f7ebd6ca27a5253ed1b114720ecbab Mon Sep 17 00:00:00 2001 From: sacOO7 Date: Thu, 2 May 2024 14:48:45 +0530 Subject: [PATCH 16/19] refactored skew ruby constant to clock_skew instead --- spec/acceptance/realtime/connection_spec.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/spec/acceptance/realtime/connection_spec.rb b/spec/acceptance/realtime/connection_spec.rb index c869dec53..1619d6274 100644 --- a/spec/acceptance/realtime/connection_spec.rb +++ b/spec/acceptance/realtime/connection_spec.rb @@ -102,7 +102,7 @@ end let(:ttl) { 2 } - let(:skew) { 0.1 } + let(:clock_skew) { 0.1 } # 0.1 second clock skew it 'renews token every time after it expires' do started_at = Time.now.to_f @@ -115,8 +115,8 @@ disconnected_times += 1 if disconnected_times == 3 expect(connected_times).to eql(3) - expect((Time.now.to_f - started_at) + skew).to be > ttl * 3 - expect((Time.now.to_f - started_at) + skew).to be < (ttl * 2) * 3 + expect((Time.now.to_f - started_at) + clock_skew).to be > ttl * 3 + expect((Time.now.to_f - started_at) + clock_skew).to be < (ttl * 2) * 3 stop_reactor end end From db1ffe91f9e1c0966cddbf79e22065d206ab01f2 Mon Sep 17 00:00:00 2001 From: sacOO7 Date: Thu, 2 May 2024 14:49:32 +0530 Subject: [PATCH 17/19] updated fromSerial param and skipped related test --- lib/ably/realtime/channel.rb | 2 +- spec/acceptance/realtime/channel_history_spec.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/ably/realtime/channel.rb b/lib/ably/realtime/channel.rb index 7fc3ea464..274afc741 100644 --- a/lib/ably/realtime/channel.rb +++ b/lib/ably/realtime/channel.rb @@ -337,7 +337,7 @@ def history(options = {}, &callback) error = Ably::Exceptions::InvalidRequest.new('option :until_attach is invalid as the channel is not attached' ) return Ably::Util::SafeDeferrable.new_and_fail_immediately(logger, error) end - options[:from_serial] = properties.attach_serial + options[:fromSerial] = properties.attach_serial end async_wrap(callback) do diff --git a/spec/acceptance/realtime/channel_history_spec.rb b/spec/acceptance/realtime/channel_history_spec.rb index 222513475..a9caf7fc6 100644 --- a/spec/acceptance/realtime/channel_history_spec.rb +++ b/spec/acceptance/realtime/channel_history_spec.rb @@ -194,7 +194,7 @@ def ensure_message_history_direction_and_paging_is_correct(direction) end end - it 'updates attach_serial' do + xit 'updates attach_serial' do rest_channel.publish event, message_before_attach channel.on(:update) do From ff686cb027835086d5105cb2938e824a5f313b03 Mon Sep 17 00:00:00 2001 From: sacOO7 Date: Thu, 2 May 2024 15:09:46 +0530 Subject: [PATCH 18/19] Refactored check.yml, removed unnecessary commands to install ca certificates --- .github/workflows/check.yml | 2 -- lib/ably/realtime/channel.rb | 1 + 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/check.yml b/.github/workflows/check.yml index 1cdf688b4..f9ebe5225 100644 --- a/.github/workflows/check.yml +++ b/.github/workflows/check.yml @@ -29,8 +29,6 @@ jobs: TEST_TYPE: ${{ matrix.type }} RUBY_VERSION: ${{ matrix.ruby }} run: | - sudo apt-get update - sudo apt-get install ca-certificates mkdir junit bundle exec parallel_rspec --prefix-output-with-test-env-number --first-is-1 -- spec/${{ matrix.type }} - uses: actions/upload-artifact@v3 diff --git a/lib/ably/realtime/channel.rb b/lib/ably/realtime/channel.rb index 274afc741..5f6cba49c 100644 --- a/lib/ably/realtime/channel.rb +++ b/lib/ably/realtime/channel.rb @@ -332,6 +332,7 @@ def presence # @return [Ably::Util::SafeDeferrable] # def history(options = {}, &callback) + # RTL10b if options.delete(:until_attach) unless attached? error = Ably::Exceptions::InvalidRequest.new('option :until_attach is invalid as the channel is not attached' ) From 48d4d9ab38e45c9f80b14643f60a80a15a1f71ff Mon Sep 17 00:00:00 2001 From: Lawrence Forooghian Date: Thu, 25 Apr 2024 11:30:37 -0300 Subject: [PATCH 19/19] Fix server certificate validation for HTTP in Realtime See https://github.com/ably-forks/em-http-request/pull/2. This fixes the internet-up check and hence the fallback hosts mechanism. Resolves #396. --- ably.gemspec | 2 +- lib/ably/realtime/connection.rb | 2 +- spec/acceptance/realtime/connection_spec.rb | 10 +++++----- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/ably.gemspec b/ably.gemspec index bbe1dfcb3..10bc0e170 100644 --- a/ably.gemspec +++ b/ably.gemspec @@ -19,7 +19,7 @@ Gem::Specification.new do |spec| spec.require_paths = ['lib'] spec.add_runtime_dependency 'eventmachine', '~> 1.2.6' - spec.add_runtime_dependency 'em-http-request', '~> 1.1' + spec.add_runtime_dependency 'ably-em-http-request', '~> 1.1.8' spec.add_runtime_dependency 'statesman', '~> 9.0' spec.add_runtime_dependency 'faraday', '~> 2.2' spec.add_runtime_dependency 'faraday-typhoeus', '~> 0.2.0' diff --git a/lib/ably/realtime/connection.rb b/lib/ably/realtime/connection.rb index 2eeacb12a..3cf106a79 100644 --- a/lib/ably/realtime/connection.rb +++ b/lib/ably/realtime/connection.rb @@ -327,7 +327,7 @@ def ping(&block) def internet_up? url = "http#{'s' if client.use_tls?}:#{Ably::INTERNET_CHECK.fetch(:url)}" EventMachine::DefaultDeferrable.new.tap do |deferrable| - EventMachine::HttpRequest.new(url, tls: { verify_peer: true }).get.tap do |http| + EventMachine::AblyHttpRequest::HttpRequest.new(url, tls: { verify_peer: true }).get.tap do |http| http.errback do yield false if block_given? deferrable.fail Ably::Exceptions::ConnectionFailed.new("Unable to connect to #{url}", nil, Ably::Exceptions::Codes::CONNECTION_FAILED) diff --git a/spec/acceptance/realtime/connection_spec.rb b/spec/acceptance/realtime/connection_spec.rb index 4cbc7b405..4d16d79b3 100644 --- a/spec/acceptance/realtime/connection_spec.rb +++ b/spec/acceptance/realtime/connection_spec.rb @@ -1702,13 +1702,13 @@ def self.available_states end context 'internet up URL protocol' do - let(:http_request) { double('EventMachine::HttpRequest', get: EventMachine::DefaultDeferrable.new) } + let(:http_request) { double('EventMachine::AblyHttpRequest::HttpRequest', get: EventMachine::DefaultDeferrable.new) } context 'when using TLS for the connection' do let(:client_options) { default_options.merge(tls: true) } it 'uses TLS for the Internet check to https://internet-up.ably-realtime.com/is-the-internet-up.txt' do - expect(EventMachine::HttpRequest).to receive(:new).with('https://internet-up.ably-realtime.com/is-the-internet-up.txt', { tls: { verify_peer: true } }).and_return(http_request) + expect(EventMachine::AblyHttpRequest::HttpRequest).to receive(:new).with('https://internet-up.ably-realtime.com/is-the-internet-up.txt', { tls: { verify_peer: true } }).and_return(http_request) connection.internet_up? stop_reactor end @@ -1718,7 +1718,7 @@ def self.available_states let(:client_options) { default_options.merge(tls: false, use_token_auth: true) } it 'uses TLS for the Internet check to http://internet-up.ably-realtime.com/is-the-internet-up.txt' do - expect(EventMachine::HttpRequest).to receive(:new).with('http://internet-up.ably-realtime.com/is-the-internet-up.txt', { tls: { verify_peer: true } }).and_return(http_request) + expect(EventMachine::AblyHttpRequest::HttpRequest).to receive(:new).with('http://internet-up.ably-realtime.com/is-the-internet-up.txt', { tls: { verify_peer: true } }).and_return(http_request) connection.internet_up? stop_reactor end @@ -1732,7 +1732,7 @@ def self.available_states let(:client_options) { default_options.merge(tls: true) } it 'checks the Internet up URL over TLS' do - expect(EventMachine::HttpRequest).to receive(:new).with("https:#{Ably::INTERNET_CHECK.fetch(:url)}", { tls: { verify_peer: true } }).and_return(double('request', get: EventMachine::DefaultDeferrable.new)) + expect(EventMachine::AblyHttpRequest::HttpRequest).to receive(:new).with("https:#{Ably::INTERNET_CHECK.fetch(:url)}", { tls: { verify_peer: true } }).and_return(double('request', get: EventMachine::DefaultDeferrable.new)) connection.internet_up? stop_reactor end @@ -1742,7 +1742,7 @@ def self.available_states let(:client_options) { default_options.merge(tls: false, use_token_auth: true) } it 'checks the Internet up URL over TLS' do - expect(EventMachine::HttpRequest).to receive(:new).with("http:#{Ably::INTERNET_CHECK.fetch(:url)}", { tls: { verify_peer: true } }).and_return(double('request', get: EventMachine::DefaultDeferrable.new)) + expect(EventMachine::AblyHttpRequest::HttpRequest).to receive(:new).with("http:#{Ably::INTERNET_CHECK.fetch(:url)}", { tls: { verify_peer: true } }).and_return(double('request', get: EventMachine::DefaultDeferrable.new)) connection.internet_up? stop_reactor end