lib/submodules/ably-ruby/spec/acceptance/rest/client_spec.rb in ably-rest-0.8.15 vs lib/submodules/ably-ruby/spec/acceptance/rest/client_spec.rb in ably-rest-0.9.0

- old
+ new

@@ -109,12 +109,11 @@ context 'with basic auth', webmock: true do let(:client_options) { default_options.merge(key: api_key) } let!(:get_message_history_stub) do - stub_request(:get, "https://#{environment}-#{Ably::Rest::Client::DOMAIN}/channels/#{channel_name}/messages?#{history_querystring}"). - with(basic_auth: [key_name, key_secret]). + stub_request(:get, "https://#{api_key}@#{environment}-#{Ably::Rest::Client::DOMAIN}/channels/#{channel_name}/messages?#{history_querystring}"). to_return(body: [], headers: { 'Content-Type' => 'application/json' }) end it 'sends the API key in authentication part of the secure URL (the Authorization: Basic header is not used with the Faraday HTTP library by default)' do client.channel(channel_name).history history_params @@ -283,13 +282,11 @@ end context 'when environment is NOT production' do let(:client_options) { default_options.merge(environment: 'sandbox', key: api_key) } let!(:default_host_request_stub) do - stub_request(:post, "https://#{environment}-#{Ably::Rest::Client::DOMAIN}#{path}"). - with(basic_auth: [key_name, key_secret]). - to_return do + stub_request(:post, "https://#{api_key}@#{environment}-#{Ably::Rest::Client::DOMAIN}#{path}").to_return do raise Faraday::TimeoutError.new('timeout error message') end end it 'does not retry failed requests with fallback hosts when there is a connection error' do @@ -314,20 +311,20 @@ before do stub_const 'Ably::FALLBACK_HOSTS', custom_hosts end let!(:first_fallback_request_stub) do - stub_request(:post, "https://#{custom_hosts[0]}#{path}").with(basic_auth: [key_name, key_secret]).to_return(&fallback_block) + stub_request(:post, "https://#{api_key}@#{custom_hosts[0]}#{path}").to_return(&fallback_block) end let!(:second_fallback_request_stub) do - stub_request(:post, "https://#{custom_hosts[1]}#{path}").with(basic_auth: [key_name, key_secret]).to_return(&fallback_block) + stub_request(:post, "https://#{api_key}@#{custom_hosts[1]}#{path}").to_return(&fallback_block) end context 'and connection times out' do let!(:default_host_request_stub) do - stub_request(:post, "https://#{Ably::Rest::Client::DOMAIN}#{path}").with(basic_auth: [key_name, key_secret]).to_return do + stub_request(:post, "https://#{api_key}@#{Ably::Rest::Client::DOMAIN}#{path}").to_return do raise Faraday::TimeoutError.new('timeout error message') end end it "tries fallback hosts #{http_defaults.fetch(:max_retry_count)} times" do @@ -337,11 +334,11 @@ expect(second_fallback_request_stub).to have_been_requested end context "and the total request time exeeds #{http_defaults.fetch(:max_retry_duration)} seconds" do let!(:default_host_request_stub) do - stub_request(:post, "https://#{Ably::Rest::Client::DOMAIN}#{path}").with(basic_auth: [key_name, key_secret]).to_return do + stub_request(:post, "https://#{api_key}@#{Ably::Rest::Client::DOMAIN}#{path}").to_return do sleep max_retry_duration * 1.5 raise Faraday::TimeoutError.new('timeout error message') end end @@ -354,11 +351,11 @@ end end context 'and connection fails' do let!(:default_host_request_stub) do - stub_request(:post, "https://#{Ably::Rest::Client::DOMAIN}#{path}").with(basic_auth: [key_name, key_secret]).to_return do + stub_request(:post, "https://#{api_key}@#{Ably::Rest::Client::DOMAIN}#{path}").to_return do raise Faraday::ConnectionFailed.new('connection failure error message') end end it "tries fallback hosts #{http_defaults.fetch(:max_retry_count)} times" do @@ -370,11 +367,11 @@ end context 'and basic authentication fails' do let(:status) { 401 } let!(:default_host_request_stub) do - stub_request(:post, "https://#{Ably::Rest::Client::DOMAIN}#{path}").with(basic_auth: [key_name, key_secret]).to_return( + stub_request(:post, "https://#{api_key}@#{Ably::Rest::Client::DOMAIN}#{path}").to_return( headers: { 'Content-Type' => 'application/json' }, status: status, body: { "error" => { "statusCode" => 401, @@ -402,11 +399,11 @@ status: status } end end let!(:default_host_request_stub) do - stub_request(:post, "https://#{Ably::Rest::Client::DOMAIN}#{path}").with(basic_auth: [key_name, key_secret]).to_return(&fallback_block) + stub_request(:post, "https://#{api_key}@#{Ably::Rest::Client::DOMAIN}#{path}").to_return(&fallback_block) end it 'attempts the fallback hosts as this is an authentication failure' do expect { publish_block.call }.to raise_error(Ably::Exceptions::ServerError) expect(default_host_request_stub).to have_been_requested @@ -438,24 +435,24 @@ status: status } end end let!(:default_host_request_stub) do - stub_request(:post, "https://#{Ably::Rest::Client::DOMAIN}#{path}").with(basic_auth: [key_name, key_secret]).to_return(&fallback_block) + stub_request(:post, "https://#{api_key}@#{Ably::Rest::Client::DOMAIN}#{path}").to_return(&fallback_block) end context 'with custom fallback hosts provided' do let!(:first_fallback_request_stub) do - stub_request(:post, "https://#{custom_hosts[0]}#{path}").with(basic_auth: [key_name, key_secret]).to_return(&fallback_block) + stub_request(:post, "https://#{api_key}@#{custom_hosts[0]}#{path}").to_return(&fallback_block) end let!(:second_fallback_request_stub) do - stub_request(:post, "https://#{custom_hosts[1]}#{path}").with(basic_auth: [key_name, key_secret]).to_return(&fallback_block) + stub_request(:post, "https://#{api_key}@#{custom_hosts[1]}#{path}").to_return(&fallback_block) end let(:client_options) { - production_options.merge(fallback_hosts: custom_hosts, log_level: :error) + production_options.merge(fallback_hosts: custom_hosts) } it 'attempts the fallback hosts as this is an authentication failure (#RSC15b, #TO3k6)' do expect { publish_block.call }.to raise_error(Ably::Exceptions::ServerError) expect(default_host_request_stub).to have_been_requested @@ -517,12 +514,11 @@ fallback_hosts: fallbacks, token: 'fake.token', port: port, tls: false, http_request_timeout: request_timeout, - max_retry_duration: request_timeout * 3, - log_level: :error + max_retry_duration: request_timeout * 3 ) end let(:fail_fallback_request_count) { 1 } it 'tries one of the fallback hosts' do @@ -621,20 +617,20 @@ status: status } end end let!(:default_host_request_stub) do - stub_request(:post, "https://#{env}-#{Ably::Rest::Client::DOMAIN}#{path}").with(basic_auth: [key_name, key_secret]).to_return(&fallback_block) + stub_request(:post, "https://#{api_key}@#{env}-#{Ably::Rest::Client::DOMAIN}#{path}").to_return(&fallback_block) end context 'with custom fallback hosts provided (#RSC15b, #TO3k6)' do let!(:first_fallback_request_stub) do - stub_request(:post, "https://#{custom_hosts[0]}#{path}").with(basic_auth: [key_name, key_secret]).to_return(&fallback_block) + stub_request(:post, "https://#{api_key}@#{custom_hosts[0]}#{path}").to_return(&fallback_block) end let!(:second_fallback_request_stub) do - stub_request(:post, "https://#{custom_hosts[1]}#{path}").with(basic_auth: [key_name, key_secret]).to_return(&fallback_block) + stub_request(:post, "https://#{api_key}@#{custom_hosts[1]}#{path}").to_return(&fallback_block) end let(:client_options) { production_options.merge(fallback_hosts: custom_hosts) } @@ -668,15 +664,15 @@ let(:client_options) { production_options.merge(fallback_hosts_use_default: true) } let!(:first_fallback_request_stub) do - stub_request(:post, "https://#{Ably::FALLBACK_HOSTS[0]}#{path}").with(basic_auth: [key_name, key_secret]).to_return(&fallback_block) + stub_request(:post, "https://#{api_key}@#{Ably::FALLBACK_HOSTS[0]}#{path}").to_return(&fallback_block) end let!(:second_fallback_request_stub) do - stub_request(:post, "https://#{Ably::FALLBACK_HOSTS[1]}#{path}").with(basic_auth: [key_name, key_secret]).to_return(&fallback_block) + stub_request(:post, "https://#{api_key}@#{Ably::FALLBACK_HOSTS[1]}#{path}").to_return(&fallback_block) end let(:client_options) { production_options.merge(fallback_hosts: custom_hosts) } @@ -703,11 +699,11 @@ context 'fallback hosts', :webmock do let(:path) { '/channels/test/publish' } let!(:custom_host_request_stub) do - stub_request(:post, "https://#{custom_host}#{path}").with(basic_auth: [key_name, key_secret]).to_return do + stub_request(:post, "https://#{api_key}@#{custom_host}#{path}").to_return do raise Faraday::ConnectionFailed.new('connection failure error message') end end before do @@ -842,15 +838,14 @@ lib = ['ruby'] lib << variant if variant lib << Ably::VERSION - stub_request(:post, "#{client.endpoint.to_s.gsub('://', "://")}/channels/foo/publish"). + stub_request(:post, "#{client.endpoint.to_s.gsub('://', "://#{api_key}@")}/channels/foo/publish"). with(headers: { 'X-Ably-Version' => Ably::PROTOCOL_VERSION, 'X-Ably-Lib' => lib.join('-') }). - with(basic_auth: [key_name, key_secret]). to_return(status: 201, body: '{}', headers: { 'Content-Type' => 'application/json' }) end it 'sends a protocol version and lib version header' do client.channels.get('foo').publish("event")