aboutsummaryrefslogtreecommitdiffstats
path: root/test/rubygems/test_gem_commands_sources_command.rb
diff options
context:
space:
mode:
authorHiroshi SHIBATA <hsbt@ruby-lang.org>2019-12-13 20:19:08 +0900
committerHiroshi SHIBATA <hsbt@ruby-lang.org>2019-12-13 20:19:33 +0900
commit82cc2843a92b286cc13afd0860a4e111d4ea2a0b (patch)
treea517dedd40d35540930cea7732f5a36e76a549e8 /test/rubygems/test_gem_commands_sources_command.rb
parent26774351dc5f494253ba031e4bc453dc4dddb2cf (diff)
downloadruby-82cc2843a92b286cc13afd0860a4e111d4ea2a0b.tar.gz
Prepare to release RubyGems 3.1.0 final version.
Diffstat (limited to 'test/rubygems/test_gem_commands_sources_command.rb')
-rw-r--r--test/rubygems/test_gem_commands_sources_command.rb74
1 files changed, 74 insertions, 0 deletions
diff --git a/test/rubygems/test_gem_commands_sources_command.rb b/test/rubygems/test_gem_commands_sources_command.rb
index 36e6ee9293..b63fbce81f 100644
--- a/test/rubygems/test_gem_commands_sources_command.rb
+++ b/test/rubygems/test_gem_commands_sources_command.rb
@@ -74,6 +74,80 @@ class TestGemCommandsSourcesCommand < Gem::TestCase
assert_equal '', @ui.error
end
+ def test_execute_add_allow_typo_squatting_source
+ rubygems_org = "https://rubyems.org"
+
+ spec_fetcher do |fetcher|
+ fetcher.spec("a", 1)
+ end
+
+ specs = Gem::Specification.map do |spec|
+ [spec.name, spec.version, spec.original_platform]
+ end
+
+ specs_dump_gz = StringIO.new
+ Zlib::GzipWriter.wrap(specs_dump_gz) do |io|
+ Marshal.dump(specs, io)
+ end
+
+ @fetcher.data["#{rubygems_org}/specs.#{@marshal_version}.gz"] = specs_dump_gz.string
+ @cmd.handle_options %W[--add #{rubygems_org}]
+ ui = Gem::MockGemUi.new("y")
+
+ use_ui ui do
+ @cmd.execute
+ end
+
+ expected = "https://rubyems.org is too similar to https://rubygems.org\n\nDo you want to add this source? [yn] https://rubyems.org added to sources\n"
+
+ assert_equal expected, ui.output
+
+ source = Gem::Source.new(rubygems_org)
+ assert Gem.sources.include?(source)
+
+ assert_empty ui.error
+ end
+
+ def test_execute_add_deny_typo_squatting_source
+ rubygems_org = "https://rubyems.org"
+
+ spec_fetcher do |fetcher|
+ fetcher.spec("a", 1)
+ end
+
+ specs = Gem::Specification.map do |spec|
+ [spec.name, spec.version, spec.original_platform]
+ end
+
+ specs_dump_gz = StringIO.new
+ Zlib::GzipWriter.wrap(specs_dump_gz) do |io|
+ Marshal.dump(specs, io)
+ end
+
+ @fetcher.data["#{rubygems_org}/specs.#{@marshal_version}.gz"] =
+ specs_dump_gz.string
+
+ @cmd.handle_options %W[--add #{rubygems_org}]
+
+ ui = Gem::MockGemUi.new("n")
+
+ use_ui ui do
+
+ assert_raises Gem::MockGemUi::TermError do
+ @cmd.execute
+ end
+ end
+
+ expected = "https://rubyems.org is too similar to https://rubygems.org\n\nDo you want to add this source? [yn] "
+
+ assert_equal expected, ui.output
+
+ source = Gem::Source.new(rubygems_org)
+ refute Gem.sources.include?(source)
+
+ assert_empty ui.error
+ end
+
def test_execute_add_nonexistent_source
spec_fetcher