summaryrefslogtreecommitdiff
path: root/test/rubygems
diff options
context:
space:
mode:
Diffstat (limited to 'test/rubygems')
-rw-r--r--test/rubygems/test_gem_printable_uri.rb116
1 files changed, 116 insertions, 0 deletions
diff --git a/test/rubygems/test_gem_printable_uri.rb b/test/rubygems/test_gem_printable_uri.rb
new file mode 100644
index 0000000000..59394547b9
--- /dev/null
+++ b/test/rubygems/test_gem_printable_uri.rb
@@ -0,0 +1,116 @@
+require_relative 'helper'
+require 'uri'
+require 'rubygems/printable_uri'
+
+class TestPrintableUri < Gem::TestCase
+ def test_parsed_uri
+ assert_equal true, Gem::PrintableUri.parse_uri("https://www.example.com").parsed_uri?
+ end
+
+ def test_parsed_uri_with_empty_uri_object
+ assert_equal true, Gem::PrintableUri.parse_uri(URI("")).parsed_uri?
+ end
+
+ def test_parsed_uri_with_valid_uri_object
+ assert_equal true, Gem::PrintableUri.parse_uri(URI("https://www.example.com")).parsed_uri?
+ end
+
+ def test_parsed_uri_with_other_objects
+ assert_equal false, Gem::PrintableUri.parse_uri(Object.new).parsed_uri?
+ end
+
+ def test_parsed_uri_with_invalid_uri
+ assert_equal false, Gem::PrintableUri.parse_uri("https://www.example.com:80index").parsed_uri?
+ end
+
+ def test_credential_redacted_with_user_pass
+ assert_equal true, Gem::PrintableUri.parse_uri("https://user:pass@example.com").credential_redacted?
+ end
+
+ def test_credential_redacted_with_token
+ assert_equal true, Gem::PrintableUri.parse_uri("https://token@example.com").credential_redacted?
+ end
+
+ def test_credential_redacted_with_user_x_oauth_basic
+ assert_equal true, Gem::PrintableUri.parse_uri("https://token:x-oauth-basic@example.com").credential_redacted?
+ end
+
+ def test_credential_redacted_without_credential
+ assert_equal false, Gem::PrintableUri.parse_uri("https://www.example.com").credential_redacted?
+ end
+
+ def test_credential_redacted_with_empty_uri_object
+ assert_equal false, Gem::PrintableUri.parse_uri(URI("")).credential_redacted?
+ end
+
+ def test_credential_redacted_with_valid_uri_object
+ assert_equal true, Gem::PrintableUri.parse_uri(URI("https://user:pass@example.com")).credential_redacted?
+ end
+
+ def test_credential_redacted_with_other_objects
+ assert_equal false, Gem::PrintableUri.parse_uri(Object.new).credential_redacted?
+ 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_original_password_with_invalid_uri
+ assert_equal nil, Gem::PrintableUri.parse_uri("https://www.example.com:80index").original_password
+ end
+
+ def test_original_password_with_empty_uri_object
+ assert_equal nil, Gem::PrintableUri.parse_uri(URI("")).original_password
+ end
+
+ def test_original_password_with_valid_uri_object
+ assert_equal "pass", Gem::PrintableUri.parse_uri(URI("https://user:pass@example.com")).original_password
+ end
+
+ def test_original_password_with_other_objects
+ assert_equal nil, Gem::PrintableUri.parse_uri(Object.new).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
+
+ def test_to_s_with_empty_uri_object
+ assert_equal "", Gem::PrintableUri.parse_uri(URI("")).to_s
+ end
+
+ def test_to_s_with_valid_uri_object
+ assert_equal "https://user:REDACTED@example.com", Gem::PrintableUri.parse_uri(URI("https://user:pass@example.com")).to_s
+ end
+
+ def test_to_s_with_other_objects
+ obj = Object.new
+ obj.stub(:to_s, "my-to-s") do
+ assert_equal "my-to-s", Gem::PrintableUri.parse_uri(obj).to_s
+ end
+ end
+end