You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@buildr.apache.org by as...@apache.org on 2009/03/13 00:42:38 UTC
svn commit: r753060 - in /buildr/trunk: CHANGELOG
lib/buildr/core/transports.rb spec/core/transport_spec.rb
Author: assaf
Date: Thu Mar 12 23:42:37 2009
New Revision: 753060
URL: http://svn.apache.org/viewvc?rev=753060&view=rev
Log:
Fixed: BUILDR-239 HTTP redirects lose authentication information (Joel Muzzerall).
Modified:
buildr/trunk/CHANGELOG
buildr/trunk/lib/buildr/core/transports.rb
buildr/trunk/spec/core/transport_spec.rb
Modified: buildr/trunk/CHANGELOG
URL: http://svn.apache.org/viewvc/buildr/trunk/CHANGELOG?rev=753060&r1=753059&r2=753060&view=diff
==============================================================================
--- buildr/trunk/CHANGELOG (original)
+++ buildr/trunk/CHANGELOG Thu Mar 12 23:42:37 2009
@@ -45,6 +45,8 @@
* Fixed: BUILDR-226 Release task should use XML output of "svn info" instead
of human-readable output (Alexis Midon).
* Fixed: BUILDR-235 JRuby download link is broke (Alexis Midon).
+* Fixed: BUILDR-239 HTTP redirects lose authentication information (Joel
+Muzzerall).
* Fixed: BUILDR-247 OpenObject does not work with Hash#only (Rhett Sutphin).
* Fixed: BUILDR-253 ZipTask now uses Zlib::DEFAULT_COMPRESSION instead of NO_COMPRESSION
* Fixed: BUILDR-261 ScalaSpecs should be run with Scala dependencies
Modified: buildr/trunk/lib/buildr/core/transports.rb
URL: http://svn.apache.org/viewvc/buildr/trunk/lib/buildr/core/transports.rb?rev=753060&r1=753059&r2=753060&view=diff
==============================================================================
--- buildr/trunk/lib/buildr/core/transports.rb (original)
+++ buildr/trunk/lib/buildr/core/transports.rb Thu Mar 12 23:42:37 2009
@@ -291,7 +291,9 @@
when Net::HTTPRedirection
# Try to download from the new URI, handle relative redirects.
trace "Redirected to #{response['Location']}"
- return (self + URI.parse(response['location'])).read(options, &block)
+ rself = self + URI.parse(response['Location'])
+ rself.user, rself.password = self.user, self.password
+ return rself.read(options, &block)
when Net::HTTPOK
info "Downloading #{self}"
result = nil
Modified: buildr/trunk/spec/core/transport_spec.rb
URL: http://svn.apache.org/viewvc/buildr/trunk/spec/core/transport_spec.rb?rev=753060&r1=753059&r2=753060&view=diff
==============================================================================
--- buildr/trunk/spec/core/transport_spec.rb (original)
+++ buildr/trunk/spec/core/transport_spec.rb Thu Mar 12 23:42:37 2009
@@ -299,6 +299,30 @@
request.should_receive(:basic_auth).with('john', 'secret')
URI("http://john:secret@#{@host_domain}").read
end
+
+ it 'should preseve authentication information during a redirect' do
+ Net::HTTP.should_receive(:new).twice.and_return(@http)
+
+ # The first request will produce a redirect
+ redirect = Net::HTTPRedirection.new(nil, nil, nil)
+ redirect['Location'] = "http://#{@host_domain}/asdf"
+
+ request1 = mock('request1')
+ Net::HTTP::Get.should_receive(:new).once.with('/', nil).and_return(request1)
+ request1.should_receive(:basic_auth).with('john', 'secret')
+ @http.should_receive(:request).with(request1).and_yield(redirect)
+
+ # The second request will be ok
+ ok = Net::HTTPOK.new(nil, nil, nil)
+ ok.stub!(:read_body)
+
+ request2 = mock('request2')
+ Net::HTTP::Get.should_receive(:new).once.with("/asdf", nil).and_return(request2)
+ request2.should_receive(:basic_auth).with('john', 'secret')
+ @http.should_receive(:request).with(request2).and_yield(ok)
+
+ URI("http://john:secret@#{@host_domain}").read
+ end
it 'should include the query part when performing HTTP GET' do
# should this test be generalized or shared with any other URI subtypes?