Skip to content

Commit c8d7ab6

Browse files
committed
Add support for more complex passwords used in URL configuration
userinfo part of URI allows to use percent-encoded characters, which should be decoded. It is important in cases when the password is randomly-generated and includes characters which are allowed as influxdb password but are reserved characters in URI.
1 parent 8df479a commit c8d7ab6

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

lib/influxdb/config.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,8 +148,8 @@ def opts_from_non_params(url)
148148
{}.tap do |o|
149149
o[:host] = url.host if url.host
150150
o[:port] = url.port if url.port
151-
o[:username] = url.user if url.user
152-
o[:password] = url.password if url.password
151+
o[:username] = URI.decode_www_form_component(url.user) if url.user
152+
o[:password] = URI.decode_www_form_component(url.password) if url.password
153153
o[:database] = url.path[1..-1] if url.path.length > 1
154154
o[:use_ssl] = url.scheme == "https".freeze
155155

spec/influxdb/config_spec.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,15 @@
159159
expect(conf).not_to be_async
160160
end
161161

162+
context "with encoded values" do
163+
let(:url) { "https://weird%24user:weird%25pass@influx.example.com:8765/testdb" }
164+
165+
it "decode encoded values" do
166+
expect(conf.username).to eq "weird$user"
167+
expect(conf.password).to eq "weird%pass"
168+
end
169+
end
170+
162171
context "UDP" do
163172
let(:url) { "udp://test.localhost:2345?discard_write_errors=1" }
164173
specify { expect(conf).to be_udp }

0 commit comments

Comments
 (0)