aboutsummaryrefslogtreecommitdiffstats
path: root/test/rubygems
diff options
context:
space:
mode:
authorJenny Shen <jenny.shen@shopify.com>2022-09-16 08:48:38 -0400
committergit <svn-admin@ruby-lang.org>2022-09-29 17:56:34 +0900
commit1cbf0fd86356ccbac5556ab0f63ea8a4b08fd24d (patch)
tree594fd118edf2ddb0af882955521a1f048805515d /test/rubygems
parent9948b8bfec08d18c2803dd1fced82a6c28967441 (diff)
downloadruby-1cbf0fd86356ccbac5556ab0f63ea8a4b08fd24d.tar.gz
[rubygems/rubygems] Add error message when api response is a permanent redirect
https://github.com/rubygems/rubygems/commit/ccca30c77a Co-authored-by: Nick Schwaderer <nick.schwaderer@shopify.com>
Diffstat (limited to 'test/rubygems')
-rw-r--r--test/rubygems/test_gem_commands_owner_command.rb47
-rw-r--r--test/rubygems/test_gem_commands_push_command.rb18
-rw-r--r--test/rubygems/test_gem_commands_signin_command.rb21
3 files changed, 86 insertions, 0 deletions
diff --git a/test/rubygems/test_gem_commands_owner_command.rb b/test/rubygems/test_gem_commands_owner_command.rb
index ca77041000..3d0a265eb1 100644
--- a/test/rubygems/test_gem_commands_owner_command.rb
+++ b/test/rubygems/test_gem_commands_owner_command.rb
@@ -118,6 +118,23 @@ EOF
assert_match response, @stub_ui.output
end
+ def test_show_owners_permanent_redirect
+ host = "http://rubygems.example"
+ ENV["RUBYGEMS_HOST"] = host
+ @stub_fetcher.data["#{host}/api/v1/gems/freewill/owners.yaml"] = ["", 301, "Moved Permanently"]
+
+ assert_raise Gem::MockGemUi::TermError do
+ use_ui @stub_ui do
+ Gem::Uri.stub("parse", URI.parse("https://rubygems.example/")) do
+ @cmd.show_owners("freewill")
+ end
+ end
+ end
+
+ response = "The request has redirected permanently to https://rubygems.example. Please check your defined push host."
+ assert_match response, @stub_ui.output
+ end
+
def test_show_owners_key
response = "- email: user1@example.com\n"
@stub_fetcher.data["#{Gem.host}/api/v1/gems/freewill/owners.yaml"] = [response, 200, "OK"]
@@ -158,6 +175,21 @@ EOF
assert_match response, @stub_ui.output
end
+ def test_add_owners_permanent_redirect
+ host = "http://rubygems.example"
+ ENV["RUBYGEMS_HOST"] = host
+ @stub_fetcher.data["#{host}/api/v1/gems/freewill/owners"] = ["", 308, "Permanent Redirect"]
+
+ use_ui @stub_ui do
+ Gem::Uri.stub("parse", URI.parse("https://rubygems.example/")) do
+ @cmd.add_owners("freewill", ["user-new1@example.com"])
+ end
+ end
+
+ response = "The request has redirected permanently to https://rubygems.example. Please check your defined push host."
+ assert_match response, @stub_ui.output
+ end
+
def test_add_owner_with_host_option_through_execute
host = "http://rubygems.example"
add_owner_response = "Owner added successfully."
@@ -216,6 +248,21 @@ EOF
assert_match response, @stub_ui.output
end
+ def test_remove_owners_permanent_redirect
+ host = "http://rubygems.example"
+ ENV["RUBYGEMS_HOST"] = host
+ @stub_fetcher.data["#{host}/api/v1/gems/freewill/owners"] = ["", 308, "Permanent Redirect"]
+
+ use_ui @stub_ui do
+ Gem::Uri.stub("parse", URI.parse("https://rubygems.example/")) do
+ @cmd.remove_owners("freewill", ["user-remove1@example.com"])
+ end
+ end
+
+ response = "The request has redirected permanently to https://rubygems.example. Please check your defined push host."
+ assert_match response, @stub_ui.output
+ end
+
def test_remove_owners_key
response = "Owner removed successfully."
@stub_fetcher.data["#{Gem.host}/api/v1/gems/freewill/owners"] = [response, 200, "OK"]
diff --git a/test/rubygems/test_gem_commands_push_command.rb b/test/rubygems/test_gem_commands_push_command.rb
index f38a2ae7a1..c58d3f3692 100644
--- a/test/rubygems/test_gem_commands_push_command.rb
+++ b/test/rubygems/test_gem_commands_push_command.rb
@@ -325,6 +325,24 @@ class TestGemCommandsPushCommand < Gem::TestCase
assert_match @response, @ui.output
end
+ def test_sending_gem_to_permanent_redirect_host
+ @host = "http://rubygems.example"
+ @fetcher.data["#{@host}/api/v1/gems"] = ["", 308, "Permanent Redirect"]
+
+ assert_raise Gem::MockGemUi::TermError do
+ use_ui @ui do
+ @cmd.instance_variable_set :@host, @host
+
+ Gem::Uri.stub("parse", URI.parse("https://rubygems.example/")) do
+ @cmd.send_gem(@path)
+ end
+ end
+ end
+
+ response = "The request has redirected permanently to https://rubygems.example. Please check your defined push host."
+ assert_match response, @ui.output
+ end
+
def test_raises_error_with_no_arguments
def @cmd.sign_in(*); end
assert_raise Gem::CommandLineError do
diff --git a/test/rubygems/test_gem_commands_signin_command.rb b/test/rubygems/test_gem_commands_signin_command.rb
index ce745bff20..940e68b3da 100644
--- a/test/rubygems/test_gem_commands_signin_command.rb
+++ b/test/rubygems/test_gem_commands_signin_command.rb
@@ -71,6 +71,27 @@ class TestGemCommandsSigninCommand < Gem::TestCase
assert_equal api_key, credentials[host]
end
+ def test_execute_with_host_permanent_redirect
+ host = "http://rubygems.example/"
+ ENV["RUBYGEMS_HOST"] = host
+ data_key = "#{host}/api/v1/api_key"
+ fetcher = Gem::FakeFetcher.new
+ fetcher.data[data_key] = ["", 308, "Moved Permanently"]
+ Gem::RemoteFetcher.fetcher = fetcher
+ ui = Gem::MockGemUi.new("you@example.com\nsecret\n\n\n\n\n\n\n\n\n")
+
+ assert_raise Gem::MockGemUi::TermError do
+ use_ui ui do
+ Gem::Uri.stub("parse", URI.parse("https://rubygems.example/")) do
+ @cmd.execute
+ end
+ end
+ end
+
+ response = "The request has redirected permanently to https://rubygems.example. Please check your defined push host."
+ assert_match response, ui.output
+ end
+
def test_execute_with_valid_creds_set_for_default_host
util_capture { @cmd.execute }