[rubygems/rubygems] Merge Gem::UriParser and Gem::PrintableUri into a Gem::Uri class

The new class is a wrapper on top of an URI. And then, when you want
credentials redacted, you call `#redacted` that returns a copy of itself,
but with credentials redacted.

9581c2740a
This commit is contained in:
David Rodríguez 2021-08-24 12:02:29 +02:00 committed by Hiroshi SHIBATA
parent f0c6cc14b1
commit 1e290c31f4
Notes: git 2021-08-31 19:06:53 +09:00
9 changed files with 145 additions and 178 deletions

View file

@ -1,44 +0,0 @@
require_relative 'helper'
require 'rubygems/printable_uri'
class TestPrintableUri < Gem::TestCase
def test_parsed_uri
assert_equal true, Gem::PrintableUri.parse_uri("https://www.example.com").valid_uri?
end
def test_valid_uri_with_invalid_uri
assert_equal false, Gem::PrintableUri.parse_uri("https://www.example.com:80index").valid_uri?
end
def test_original_password_user_pass
assert_equal "pass", Gem::PrintableUri.parse_uri("https://user:pass@example.com").original_password
end
def test_original_password_with_token
assert_equal nil, Gem::PrintableUri.parse_uri("https://token@example.com").original_password
end
def test_original_password_without_credential
assert_equal nil, Gem::PrintableUri.parse_uri("https://www.example.com").original_password
end
def test_to_s_with_user_pass
assert_equal "https://user:REDACTED@example.com", Gem::PrintableUri.parse_uri("https://user:pass@example.com").to_s
end
def test_to_s_with_token
assert_equal "https://REDACTED@example.com", Gem::PrintableUri.parse_uri("https://token@example.com").to_s
end
def test_to_s_with_user_x_oauth_basic
assert_equal "https://REDACTED:x-oauth-basic@example.com", Gem::PrintableUri.parse_uri("https://token:x-oauth-basic@example.com").to_s
end
def test_to_s_without_credential
assert_equal "https://www.example.com", Gem::PrintableUri.parse_uri("https://www.example.com").to_s
end
def test_to_s_with_invalid_uri
assert_equal "https://www.example.com:80index", Gem::PrintableUri.parse_uri("https://www.example.com:80index").to_s
end
end

View file

@ -0,0 +1,32 @@
require_relative 'helper'
require 'rubygems/uri'
class TestUri < Gem::TestCase
def test_to_s_not_string
assert_equal "not_a_uri", Gem::Uri.new(:not_a_uri).to_s
end
def test_to_s_invalid_uri
assert_equal "https://www.example.com:80index", Gem::Uri.new("https://www.example.com:80index").to_s
end
def test_redacted_with_user_pass
assert_equal "https://user:REDACTED@example.com", Gem::Uri.new("https://user:pass@example.com").redacted.to_s
end
def test_redacted_with_token
assert_equal "https://REDACTED@example.com", Gem::Uri.new("https://token@example.com").redacted.to_s
end
def test_redacted_with_user_x_oauth_basic
assert_equal "https://REDACTED:x-oauth-basic@example.com", Gem::Uri.new("https://token:x-oauth-basic@example.com").redacted.to_s
end
def test_redacted_without_credential
assert_equal "https://www.example.com", Gem::Uri.new("https://www.example.com").redacted.to_s
end
def test_redacted_with_invalid_uri
assert_equal "https://www.example.com:80index", Gem::Uri.new("https://www.example.com:80index").redacted.to_s
end
end

View file

@ -1,17 +0,0 @@
require_relative 'helper'
require 'uri'
require 'rubygems/uri_parser'
class TestUriParser < Gem::TestCase
def test_parse_uri_none_string
assert_equal :not_a_uri, Gem::UriParser.parse_uri(:not_a_uri)
end
def test_parse_uri_invalid_uri
assert_equal "https://www.example.com:80index", Gem::UriParser.parse_uri("https://www.example.com:80index")
end
def test_parse_uri
assert_equal URI::HTTPS, Gem::UriParser.parse_uri("https://www.example.com").class
end
end