Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support encoded usernames and passowrds in url #781

Merged
merged 2 commits into from Jan 15, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion lib/rubygems/request.rb
Expand Up @@ -106,7 +106,8 @@ def fetch
request = @request_class.new @uri.request_uri

unless @uri.nil? || @uri.user.nil? || @uri.user.empty? then
request.basic_auth @uri.user, @uri.password
request.basic_auth Gem::UriFormatter.new(@uri.user).unescape,
Gem::UriFormatter.new(@uri.password).unescape
end

request.add_field 'User-Agent', @user_agent
Expand Down
25 changes: 25 additions & 0 deletions test/rubygems/test_gem_request.rb
@@ -1,6 +1,7 @@
require 'rubygems/test_case'
require 'rubygems/request'
require 'ostruct'
require 'base64'

class TestGemRequest < Gem::TestCase

Expand Down Expand Up @@ -124,6 +125,30 @@ def test_fetch
assert_equal :junk, response.body
end

def test_fetch_basic_auth
uri = URI.parse "https://user:pass@example.rubygems/specs.#{Gem.marshal_version}"
@request = Gem::Request.new(uri, Net::HTTP::Get, nil, nil)
conn = util_stub_connection_for :body => :junk, :code => 200

response = @request.fetch

auth_header = conn.payload['Authorization']

assert_equal "Basic #{Base64.encode64('user:pass')}".strip, auth_header
end

def test_fetch_basic_auth_encoded
uri = URI.parse "https://user:%7BDEScede%7Dpass@example.rubygems/specs.#{Gem.marshal_version}"
@request = Gem::Request.new(uri, Net::HTTP::Get, nil, nil)
conn = util_stub_connection_for :body => :junk, :code => 200

response = @request.fetch

auth_header = conn.payload['Authorization']

assert_equal "Basic #{Base64.encode64('user:{DEScede}pass')}".strip, auth_header
end

def test_fetch_head
uri = URI.parse "#{@gem_repo}/specs.#{Gem.marshal_version}"
@request = Gem::Request.new(uri, Net::HTTP::Get, nil, nil)
Expand Down