Skip to content

Commit d483fa5

Browse files
committed
Add test for basicauth+proxy case
1 parent 5fccec3 commit d483fa5

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

spec/http_proxy_spec.rb

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,23 @@
5252
}
5353
end
5454

55+
it "should strip basic auth from before the host in URI sent to proxy" do
56+
EventMachine.run {
57+
58+
http = EventMachine::HttpRequest.new('http://user:pass@127.0.0.1:8090/echo_authorization_header', proxy).get
59+
60+
http.errback { failed(http) }
61+
http.callback {
62+
http.response_header.status.should == 200
63+
# The test proxy server gives the requested uri back in this header
64+
http.response_header['X_THE_REQUESTED_URI'].should == 'http://127.0.0.1:8090/echo_authorization_header'
65+
# Ensure the basic auth was converted to a header correctly
66+
http.response.should match('authorization:Basic dXNlcjpwYXNz')
67+
EventMachine.stop
68+
}
69+
}
70+
end
71+
5572
it "should include query parameters specified in the options" do
5673
EventMachine.run {
5774
http = EventMachine::HttpRequest.new('http://127.0.0.1:8090/', proxy).get :query => { 'q' => 'test' }

spec/stallion.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,9 @@ def self.call(env)
9696
elsif stable.request.path_info == '/echo_content_length_from_header'
9797
stable.response.write "content-length:#{stable.request.env["CONTENT_LENGTH"]}"
9898

99+
elsif stable.request.path_info == '/echo_authorization_header'
100+
stable.response.write "authorization:#{stable.request.env["HTTP_AUTHORIZATION"]}"
101+
99102
elsif stable.request.head? && stable.request.path_info == '/'
100103
stable.response.status = 200
101104

0 commit comments

Comments
 (0)