spec/elasticsearch/transport/client_spec.rb in elasticsearch-transport-7.10.0 vs spec/elasticsearch/transport/client_spec.rb in elasticsearch-transport-7.10.1

- old
+ new

@@ -342,40 +342,35 @@ it 'extracts the cloud credentials' do expect(hosts[0][:host]).to eq('abcd.localhost') expect(hosts[0][:protocol]).to eq('https') expect(hosts[0][:user]).to eq('elastic') expect(hosts[0][:password]).to eq('changeme') - expect(hosts[0][:port]).to eq(9243) + expect(hosts[0][:port]).to eq(443) end it 'creates the correct full url' do expect( client.transport.__full_url(client.transport.hosts[0]) - ).to eq('https://elastic:changeme@abcd.localhost:9243') + ).to eq('https://elastic:changeme@abcd.localhost:443') end context 'when a port is specified' do let(:client) do - described_class.new( - cloud_id: 'name:bG9jYWxob3N0JGFiY2QkZWZnaA==', - user: 'elastic', - password: 'changeme', - port: 9200 - ) + described_class.new(cloud_id: 'name:bG9jYWxob3N0JGFiY2QkZWZnaA==', user: 'elastic', password: 'changeme', port: 9250) end it 'sets the specified port along with the cloud credentials' do expect(hosts[0][:host]).to eq('abcd.localhost') expect(hosts[0][:protocol]).to eq('https') expect(hosts[0][:user]).to eq('elastic') expect(hosts[0][:password]).to eq('changeme') - expect(hosts[0][:port]).to eq(9200) + expect(hosts[0][:port]).to eq(9250) end it 'creates the correct full url' do - expect(client.transport.__full_url(client.transport.hosts[0])).to eq('https://elastic:changeme@abcd.localhost:9200') + expect(client.transport.__full_url(client.transport.hosts[0])).to eq('https://elastic:changeme@abcd.localhost:9250') end end context 'when the cluster has alternate names' do @@ -394,17 +389,17 @@ it 'extracts the cloud credentials' do expect(hosts[0][:host]).to eq('abcd.localhost') expect(hosts[0][:protocol]).to eq('https') expect(hosts[0][:user]).to eq('elasticfantastic') expect(hosts[0][:password]).to eq('tobechanged') - expect(hosts[0][:port]).to eq(9243) + expect(hosts[0][:port]).to eq(443) end it 'creates the correct full url' do expect( client.transport.__full_url(client.transport.hosts[0]) - ).to eq('https://elasticfantastic:tobechanged@abcd.localhost:9243') + ).to eq('https://elasticfantastic:tobechanged@abcd.localhost:443') end end context 'when decoded cloud id has a trailing dollar sign' do let(:client) do @@ -422,17 +417,17 @@ it 'extracts the cloud credentials' do expect(hosts[0][:host]).to eq('abcd.localhost') expect(hosts[0][:protocol]).to eq('https') expect(hosts[0][:user]).to eq('elasticfantastic') expect(hosts[0][:password]).to eq('changeme') - expect(hosts[0][:port]).to eq(9243) + expect(hosts[0][:port]).to eq(443) end it 'creates the correct full url' do expect( client.transport.__full_url(client.transport.hosts[0]) - ).to eq('https://elasticfantastic:changeme@abcd.localhost:9243') + ).to eq('https://elasticfantastic:changeme@abcd.localhost:443') end end context 'when the cloud host provides a port' do let(:client) do @@ -480,124 +475,266 @@ end end shared_examples_for 'a client that extracts hosts' do - context 'when the hosts are a String' do + context 'when the host is a String' do - let(:host) do - 'myhost' - end + context 'when there is a protocol specified' do - it 'extracts the host' do - expect(hosts[0][:host]).to eq('myhost') - expect(hosts[0][:protocol]).to eq('http') - expect(hosts[0][:port]).to be(9200) - end + context 'when credentials are specified \'http://USERNAME:PASSWORD@myhost:8080\'' do - context 'when IPv6 format is used' do + let(:host) do + 'http://USERNAME:PASSWORD@myhost:8080' + end - around do |example| - original_setting = Faraday.ignore_env_proxy - Faraday.ignore_env_proxy = true - example.run - Faraday.ignore_env_proxy = original_setting - end + it 'extracts the credentials' do + expect(hosts[0][:user]).to eq('USERNAME') + expect(hosts[0][:password]).to eq('PASSWORD') + end - let(:host) do - 'https://[2090:db8:85a3:9811::1f]:8080' - end + it 'extracts the host' do + expect(hosts[0][:host]).to eq('myhost') + end - it 'extracts the host' do - expect(hosts[0][:host]).to eq('[2090:db8:85a3:9811::1f]') - expect(hosts[0][:scheme]).to eq('https') - expect(hosts[0][:port]).to be(8080) + it 'extracts the port' do + expect(hosts[0][:port]).to be(8080) + end end - it 'creates the correct full url' do - expect(client.transport.__full_url(client.transport.hosts[0])).to eq('https://[2090:db8:85a3:9811::1f]:8080') - end - end + context 'when there is a trailing slash \'http://myhost/\'' do - context 'when a path is specified' do + let(:host) do + 'http://myhost/' + end - let(:host) do - 'https://myhost:8080/api' - end + it 'extracts the host' do + expect(hosts[0][:host]).to eq('myhost') + expect(hosts[0][:scheme]).to eq('http') + expect(hosts[0][:path]).to eq('') + end - it 'extracts the host' do - expect(hosts[0][:host]).to eq('myhost') - expect(hosts[0][:scheme]).to eq('https') - expect(hosts[0][:path]).to eq('/api') - expect(hosts[0][:port]).to be(8080) + it 'extracts the scheme' do + expect(hosts[0][:scheme]).to eq('http') + end + + it 'extracts the path' do + expect(hosts[0][:path]).to eq('') + end end - end - context 'when a scheme is specified' do + context 'when there is a trailing slash with a path \'http://myhost/foo/bar/\'' do - let(:host) do - 'https://myhost:8080' - end + let(:host) do + 'http://myhost/foo/bar/' + end - it 'extracts the host' do - expect(hosts[0][:host]).to eq('myhost') - expect(hosts[0][:scheme]).to eq('https') - expect(hosts[0][:port]).to be(8080) + it 'extracts the host' do + expect(hosts[0][:host]).to eq('myhost') + expect(hosts[0][:scheme]).to eq('http') + expect(hosts[0][:path]).to eq('/foo/bar') + end end - end - context 'when credentials are specified' do + context 'when the protocol is http' do - let(:host) do - 'http://USERNAME:PASSWORD@myhost:8080' - end + context 'when there is no port specified \'http://myhost\'' do - it 'extracts the host' do - expect(hosts[0][:host]).to eq('myhost') - expect(hosts[0][:scheme]).to eq('http') - expect(hosts[0][:user]).to eq('USERNAME') - expect(hosts[0][:password]).to eq('PASSWORD') - expect(hosts[0][:port]).to be(8080) - end - end + let(:host) do + 'http://myhost' + end - context 'when there is a trailing slash' do + it 'extracts the host' do + expect(hosts[0][:host]).to eq('myhost') + end - let(:host) do - 'http://myhost/' + it 'extracts the protocol' do + expect(hosts[0][:protocol]).to eq('http') + end + + it 'defaults to port 9200' do + expect(hosts[0][:port]).to be(9200) + end + end + + context 'when there is a port specified \'http://myhost:7101\'' do + + let(:host) do + 'http://myhost:7101' + end + + it 'extracts the host' do + expect(hosts[0][:host]).to eq('myhost') + end + + it 'extracts the protocol' do + expect(hosts[0][:protocol]).to eq('http') + end + + it 'extracts the port' do + expect(hosts[0][:port]).to be(7101) + end + + context 'when there is a path specified \'http://myhost:7101/api\'' do + + let(:host) do + 'http://myhost:7101/api' + end + + it 'sets the path' do + expect(hosts[0][:host]).to eq('myhost') + expect(hosts[0][:protocol]).to eq('http') + expect(hosts[0][:path]).to eq('/api') + expect(hosts[0][:port]).to be(7101) + end + + it 'extracts the host' do + expect(hosts[0][:host]).to eq('myhost') + end + + it 'extracts the protocol' do + expect(hosts[0][:protocol]).to eq('http') + end + + it 'extracts the port' do + expect(hosts[0][:port]).to be(7101) + end + + it 'extracts the path' do + expect(hosts[0][:path]).to eq('/api') + end + end + end end - it 'extracts the host' do - expect(hosts[0][:host]).to eq('myhost') - expect(hosts[0][:scheme]).to eq('http') - expect(hosts[0][:path]).to eq('') + context 'when the protocol is https' do + + context 'when there is no port specified \'https://myhost\'' do + + let(:host) do + 'https://myhost' + end + + it 'extracts the host' do + expect(hosts[0][:host]).to eq('myhost') + end + + it 'extracts the protocol' do + expect(hosts[0][:protocol]).to eq('https') + end + + it 'defaults to port 443' do + expect(hosts[0][:port]).to be(443) + end + end + + context 'when there is a port specified \'https://myhost:7101\'' do + + let(:host) do + 'https://myhost:7101' + end + + it 'extracts the host' do + expect(hosts[0][:host]).to eq('myhost') + end + + it 'extracts the protocol' do + expect(hosts[0][:protocol]).to eq('https') + end + + it 'extracts the port' do + expect(hosts[0][:port]).to be(7101) + end + + context 'when there is a path specified \'https://myhost:7101/api\'' do + + let(:host) do + 'https://myhost:7101/api' + end + + it 'extracts the host' do + expect(hosts[0][:host]).to eq('myhost') + end + + it 'extracts the protocol' do + expect(hosts[0][:protocol]).to eq('https') + end + + it 'extracts the port' do + expect(hosts[0][:port]).to be(7101) + end + + it 'extracts the path' do + expect(hosts[0][:path]).to eq('/api') + end + end + end + + context 'when IPv6 format is used' do + + around do |example| + original_setting = Faraday.ignore_env_proxy + Faraday.ignore_env_proxy = true + example.run + Faraday.ignore_env_proxy = original_setting + end + + let(:host) do + 'https://[2090:db8:85a3:9811::1f]:8080' + end + + it 'extracts the host' do + expect(hosts[0][:host]).to eq('[2090:db8:85a3:9811::1f]') + end + + it 'extracts the protocol' do + expect(hosts[0][:protocol]).to eq('https') + end + + it 'extracts the port' do + expect(hosts[0][:port]).to be(8080) + end + + it 'creates the correct full url' do + expect(client.transport.__full_url(client.transport.hosts[0])).to eq('https://[2090:db8:85a3:9811::1f]:8080') + end + end end end - context 'when there is a trailing slash with a path' do + context 'when no protocol is specified \'myhost\'' do let(:host) do - 'http://myhost/foo/bar/' + 'myhost' end - it 'extracts the host' do + it 'defaults to http' do expect(hosts[0][:host]).to eq('myhost') - expect(hosts[0][:scheme]).to eq('http') - expect(hosts[0][:path]).to eq('/foo/bar') + expect(hosts[0][:protocol]).to eq('http') end + + it 'uses port 9200' do + expect(hosts[0][:port]).to be(9200) + end end end - context 'when the hosts are a Hash' do + context 'when the host is a Hash' do let(:host) do { :host => 'myhost', :scheme => 'https' } end it 'extracts the host' do expect(hosts[0][:host]).to eq('myhost') - expect(hosts[0][:scheme]).to eq('https') + end + + it 'extracts the protocol' do + expect(hosts[0][:protocol]).to eq('https') + end + + it 'extracts the port' do expect(hosts[0][:port]).to be(9200) end context 'when IPv6 format is used' do @@ -652,11 +789,17 @@ { host: 'myhost', scheme: 'https', port: '443' } end it 'extracts the host' do expect(hosts[0][:host]).to eq('myhost') + end + + it 'extracts the protocol' do expect(hosts[0][:scheme]).to eq('https') + end + + it 'converts the port to an integer' do expect(hosts[0][:port]).to be(443) end end context 'when the port is specified as an Integer' do @@ -665,11 +808,17 @@ { host: 'myhost', scheme: 'https', port: 443 } end it 'extracts the host' do expect(hosts[0][:host]).to eq('myhost') + end + + it 'extracts the protocol' do expect(hosts[0][:scheme]).to eq('https') + end + + it 'extracts port as an integer' do expect(hosts[0][:port]).to be(443) end end end @@ -679,11 +828,17 @@ Hashie::Mash.new(host: 'myhost', scheme: 'https') end it 'extracts the host' do expect(hosts[0][:host]).to eq('myhost') + end + + it 'extracts the protocol' do expect(hosts[0][:scheme]).to eq('https') + end + + it 'converts the port to an integer' do expect(hosts[0][:port]).to be(9200) end context 'when the port is specified as a String' do @@ -691,11 +846,17 @@ Hashie::Mash.new(host: 'myhost', scheme: 'https', port: '443') end it 'extracts the host' do expect(hosts[0][:host]).to eq('myhost') + end + + it 'extracts the protocol' do expect(hosts[0][:scheme]).to eq('https') + end + + it 'converts the port to an integer' do expect(hosts[0][:port]).to be(443) end end context 'when the port is specified as an Integer' do @@ -704,11 +865,17 @@ Hashie::Mash.new(host: 'myhost', scheme: 'https', port: 443) end it 'extracts the host' do expect(hosts[0][:host]).to eq('myhost') + end + + it 'extracts the protocol' do expect(hosts[0][:scheme]).to eq('https') + end + + it 'extracts port as an integer' do expect(hosts[0][:port]).to be(443) end end end @@ -720,11 +887,17 @@ ['myhost'] end it 'extracts the host' do expect(hosts[0][:host]).to eq('myhost') + end + + it 'extracts the protocol' do expect(hosts[0][:protocol]).to eq('http') + end + + it 'defaults to port 9200' do expect(hosts[0][:port]).to be(9200) end end context 'when there is one host with a protocol and no port' do @@ -733,24 +906,17 @@ ['http://myhost'] end it 'extracts the host' do expect(hosts[0][:host]).to eq('myhost') - expect(hosts[0][:protocol]).to eq('http') - expect(hosts[0][:port]).to be(9200) end - end - context 'when there is one host with a protocol and no port' do - - let(:host) do - ['http://myhost'] + it 'extracts the protocol' do + expect(hosts[0][:scheme]).to eq('http') end - it 'extracts the host' do - expect(hosts[0][:host]).to eq('myhost') - expect(hosts[0][:protocol]).to eq('http') + it 'defaults to port 9200' do expect(hosts[0][:port]).to be(9200) end end context 'when there is one host with a protocol and the default http port explicitly provided' do @@ -771,44 +937,59 @@ it 'respects the explicit port' do expect(hosts[0][:port]).to be(443) end end - context 'when there is one host with a scheme, protocol and no port' do + context 'when there is one host with a protocol and no port' do let(:host) do ['https://myhost'] end it 'extracts the host' do expect(hosts[0][:host]).to eq('myhost') - expect(hosts[0][:protocol]).to eq('https') - expect(hosts[0][:port]).to be(9200) end + + it 'extracts the protocol' do + expect(hosts[0][:scheme]).to eq('https') + end + + it 'defaults to port 443' do + expect(hosts[0][:port]).to be(443) + end end - context 'when there is one host with a scheme, protocol, path, and no port' do + context 'when there is one host with a protocol, path, and no port' do let(:host) do ['http://myhost/foo/bar'] end it 'extracts the host' do expect(hosts[0][:host]).to eq('myhost') - expect(hosts[0][:protocol]).to eq('http') + end + + it 'extracts the protocol' do + expect(hosts[0][:scheme]).to eq('http') + end + + it 'defaults to port 9200' do expect(hosts[0][:port]).to be(9200) - expect(hosts[0][:path]).to eq("/foo/bar") end + + it 'extracts the path' do + expect(hosts[0][:path]).to eq('/foo/bar') + end end context 'when there is more than one host' do let(:host) do ['host1', 'host2'] end - it 'extracts the host' do + it 'extracts the hosts' do expect(hosts[0][:host]).to eq('host1') expect(hosts[0][:protocol]).to eq('http') expect(hosts[0][:port]).to be(9200) expect(hosts[1][:host]).to eq('host2') expect(hosts[1][:protocol]).to eq('http') @@ -820,10 +1001,10 @@ let(:host) do ['host1:1000', 'host2:2000'] end - it 'extracts the host' do + it 'extracts the hosts' do expect(hosts[0][:host]).to eq('host1') expect(hosts[0][:protocol]).to eq('http') expect(hosts[0][:port]).to be(1000) expect(hosts[1][:host]).to eq('host2') expect(hosts[1][:protocol]).to eq('http')