Skip to content

Commit

Permalink
[rubygems/rubygems] Avoid to use Base64 library because I have a plan…
Browse files Browse the repository at this point in the history
… to base64 gem to bundled gems in ruby/ruby.

rubygems/rubygems@221797cfd1
  • Loading branch information
hsbt authored and matzbot committed Jul 6, 2023
1 parent 57bf732 commit d287d85
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions test/rubygems/test_gem_request.rb
Expand Up @@ -3,7 +3,6 @@
require_relative "helper"
require "rubygems/request"
require "ostruct"
require "base64"

unless Gem::HAVE_OPENSSL
warn "Skipping Gem::Request tests. openssl not found."
Expand All @@ -21,6 +20,12 @@ def make_request(uri, request_class, last_modified, proxy)
Gem::Request.create_with_proxy uri, request_class, last_modified, proxy
end

# This method is same code as Base64.encode64
# We should not use Base64.encode64 because we need to avoid gem activation.
def base64_encode64(bin)
[bin].pack("m")
end

def setup
@proxies = %w[http_proxy https_proxy HTTP_PROXY http_proxy_user HTTP_PROXY_USER http_proxy_pass HTTP_PROXY_PASS no_proxy NO_PROXY]
@old_proxies = @proxies.map {|k| ENV[k] }
Expand Down Expand Up @@ -209,7 +214,7 @@ def test_fetch_basic_auth
end

auth_header = conn.payload["Authorization"]
assert_equal "Basic #{Base64.encode64("user:pass")}".strip, auth_header
assert_equal "Basic #{base64_encode64("user:pass")}".strip, auth_header
assert_includes @ui.output, "GET https://user:REDACTED@example.rubygems/specs.#{Gem.marshal_version}"
end

Expand All @@ -226,7 +231,7 @@ def test_fetch_basic_auth_encoded
end

auth_header = conn.payload["Authorization"]
assert_equal "Basic #{Base64.encode64("user:{DEScede}pass")}".strip, auth_header
assert_equal "Basic #{base64_encode64("user:{DEScede}pass")}".strip, auth_header
assert_includes @ui.output, "GET https://user:REDACTED@example.rubygems/specs.#{Gem.marshal_version}"
end

Expand All @@ -243,7 +248,7 @@ def test_fetch_basic_oauth_encoded
end

auth_header = conn.payload["Authorization"]
assert_equal "Basic #{Base64.encode64("{DEScede}pass:x-oauth-basic")}".strip, auth_header
assert_equal "Basic #{base64_encode64("{DEScede}pass:x-oauth-basic")}".strip, auth_header
assert_includes @ui.output, "GET https://REDACTED:x-oauth-basic@example.rubygems/specs.#{Gem.marshal_version}"
end

Expand Down

0 comments on commit d287d85

Please sign in to comment.