Skip to content

Commit 81bb779

Browse files
author
Samuel McKendrick
committed
fix: pact-foundation#184 Escape username before asigning it to URI userinfo attribute
1 parent 8e45062 commit 81bb779

File tree

2 files changed

+20
-8
lines changed

2 files changed

+20
-8
lines changed

lib/pact_broker/domain/webhook_request.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ def build_uri pact
159159

160160
def url_with_credentials pact
161161
u = build_uri(pact)
162-
u.userinfo = "#{username}:#{display_password}" if username
162+
u.userinfo = "#{CGI::escape username}:#{display_password}" if username
163163
u
164164
end
165165

spec/lib/pact_broker/domain/webhook_request_spec.rb

+19-7
Original file line numberDiff line numberDiff line change
@@ -175,10 +175,7 @@ module Domain
175175
end
176176
end
177177

178-
context "when a username and password are specified" do
179-
180-
let(:username) { 'username' }
181-
let(:password) { 'password' }
178+
describe "when a username and password are specified" do
182179

183180
let!(:http_request_with_basic_auth) do
184181
stub_request(:post, "http://example.org/hook").
@@ -189,9 +186,24 @@ module Domain
189186
to_return(:status => 200, :body => "respbod", :headers => {'Content-Type' => 'text/foo, blah'})
190187
end
191188

192-
it "uses the credentials" do
193-
subject.execute(pact, options)
194-
expect(http_request_with_basic_auth).to have_been_made
189+
context "with normal characters" do
190+
let(:username) { "username" }
191+
let(:password) { "password" }
192+
193+
it "uses the credentials" do
194+
subject.execute(pact, options)
195+
expect(http_request_with_basic_auth).to have_been_made
196+
end
197+
end
198+
199+
context "with special characters" do
200+
let(:username) { "user_name@site.com" }
201+
let(:password) { "p@$$w0rd!" }
202+
203+
it "uses the credentials" do
204+
subject.execute(pact, options)
205+
expect(http_request_with_basic_auth).to have_been_made
206+
end
195207
end
196208
end
197209

0 commit comments

Comments
 (0)