Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions lib/opensearch/transport/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -318,8 +318,8 @@ def __parse_host(host)
default_port = uri.scheme == 'https' ? 443 : DEFAULT_PORT
{
scheme: uri.scheme,
user: uri.user,
password: uri.password,
user: uri.user && CGI.unescape(uri.user),
password: uri.password && CGI.unescape(uri.password),
host: uri.host,
path: uri.path,
port: uri.port || default_port
Expand All @@ -331,8 +331,8 @@ def __parse_host(host)
when URI
{
scheme: host.scheme,
user: host.user,
password: host.password,
user: host.user && CGI.unescape(host.user),
password: host.password && CGI.unescape(host.password),
host: host.host,
path: host.path,
port: host.port
Expand Down
24 changes: 24 additions & 0 deletions spec/opensearch/transport/client_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,18 @@
end
end

context 'when credentials contain URL-encoded characters \'http://user:pass%7D%7Dword@myhost:8080\'' do

let(:host) do
'http://user:pass%7D%7Dword@myhost:8080'
end

it 'decodes the credentials' do
expect(hosts[0][:user]).to eq('user')
expect(hosts[0][:password]).to eq('pass}}word')
end
end

context 'when there is a trailing slash \'http://myhost/\'' do

let(:host) do
Expand Down Expand Up @@ -888,6 +900,18 @@
end
end

context 'when the hosts is an instance of URI with URL-encoded credentials' do

let(:host) do
URI.parse('https://user:pass%7D%7Dword@myhost:4430')
end

it 'decodes the credentials' do
expect(hosts[0][:user]).to eq('user')
expect(hosts[0][:password]).to eq('pass}}word')
end
end

context 'when the hosts is invalid' do

let(:host) do
Expand Down