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
Changes from all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file or symbol
Failed to load files and symbols.
+27 −1
Diff settings

Always

Just for now

Copy path View file
@@ -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
@@ -1,6 +1,7 @@
require 'rubygems/test_case'
require 'rubygems/request'
require 'ostruct'
require 'base64'

class TestGemRequest < Gem::TestCase

@@ -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)
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.