summaryrefslogtreecommitdiff
path: root/test/rubygems/test_gem_config_file.rb
diff options
context:
space:
mode:
Diffstat (limited to 'test/rubygems/test_gem_config_file.rb')
-rw-r--r--test/rubygems/test_gem_config_file.rb107
1 files changed, 86 insertions, 21 deletions
diff --git a/test/rubygems/test_gem_config_file.rb b/test/rubygems/test_gem_config_file.rb
index e23773a133..a055f248be 100644
--- a/test/rubygems/test_gem_config_file.rb
+++ b/test/rubygems/test_gem_config_file.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
require_relative "helper"
require "rubygems/config_file"
@@ -57,6 +58,7 @@ class TestGemConfigFile < Gem::TestCase
fp.puts ":ssl_verify_mode: 0"
fp.puts ":ssl_ca_cert: /etc/ssl/certs"
fp.puts ":cert_expiration_length_days: 28"
+ fp.puts ":install_extension_in_lib: true"
fp.puts ":ipv4_fallback_enabled: true"
end
@@ -72,6 +74,7 @@ class TestGemConfigFile < Gem::TestCase
assert_equal 0, @cfg.ssl_verify_mode
assert_equal "/etc/ssl/certs", @cfg.ssl_ca_cert
assert_equal 28, @cfg.cert_expiration_length_days
+ assert_equal true, @cfg.install_extension_in_lib
assert_equal true, @cfg.ipv4_fallback_enabled
end
@@ -184,22 +187,22 @@ class TestGemConfigFile < Gem::TestCase
temp_cred = File.join Gem.user_home, ".gem", "credentials"
FileUtils.mkdir_p File.dirname(temp_cred)
- File.open temp_cred, "w", 0600 do |fp|
+ File.open temp_cred, "w", 0o600 do |fp|
fp.puts ":rubygems_api_key: 701229f217cdf23b1344c7b4b54ca97"
end
util_config_file
- assert_equal({ :rubygems => "701229f217cdf23b1344c7b4b54ca97" },
+ assert_equal({ rubygems: "701229f217cdf23b1344c7b4b54ca97" },
@cfg.api_keys)
end
def test_check_credentials_permissions
- pend "chmod not supported" if win_platform?
+ pend "chmod not supported" if Gem.win_platform?
@cfg.rubygems_api_key = "x"
- File.chmod 0644, @cfg.credentials_path
+ File.chmod 0o644, @cfg.credentials_path
use_ui @ui do
assert_raise Gem::MockGemUi::TermError do
@@ -322,23 +325,28 @@ if you believe they were disclosed to a third party.
def test_load_api_keys
temp_cred = File.join Gem.user_home, ".gem", "credentials"
FileUtils.mkdir_p File.dirname(temp_cred)
- File.open temp_cred, "w", 0600 do |fp|
- fp.puts ":rubygems_api_key: 701229f217cdf23b1344c7b4b54ca97"
- fp.puts ":other: a5fdbb6ba150cbb83aad2bb2fede64c"
+ File.open temp_cred, "w", 0o600 do |fp|
+ fp.puts ":rubygems_api_key: rubygems_b9ce70c306b3a2e248679fbbbd66722d408d3c8c4f00566c"
+ fp.puts ":other: rubygems_9636a120106ea8b81fbc792188251738665711d2ece160c5"
+ fp.puts "http://localhost:3000: rubygems_be293ad9dd71550a012b17d848893b41960b811ce9312b47"
end
util_config_file
- assert_equal({ :rubygems => "701229f217cdf23b1344c7b4b54ca97",
- :other => "a5fdbb6ba150cbb83aad2bb2fede64c" }, @cfg.api_keys)
+ assert_equal(
+ { :rubygems => "rubygems_b9ce70c306b3a2e248679fbbbd66722d408d3c8c4f00566c",
+ :other => "rubygems_9636a120106ea8b81fbc792188251738665711d2ece160c5",
+ "http://localhost:3000" => "rubygems_be293ad9dd71550a012b17d848893b41960b811ce9312b47" },
+ @cfg.api_keys
+ )
end
def test_load_api_keys_bad_permission
- pend "chmod not supported" if win_platform?
+ pend "chmod not supported" if Gem.win_platform?
@cfg.rubygems_api_key = "x"
- File.chmod 0644, @cfg.credentials_path
+ File.chmod 0o644, @cfg.credentials_path
assert_raise Gem::MockGemUi::TermError do
@cfg.load_api_keys
@@ -363,38 +371,38 @@ if you believe they were disclosed to a third party.
assert_equal "x", @cfg.rubygems_api_key
expected = {
- :rubygems_api_key => "x",
+ rubygems_api_key: "x",
}
assert_equal expected, load_yaml_file(@cfg.credentials_path)
- unless win_platform?
+ unless Gem.win_platform?
stat = File.stat @cfg.credentials_path
- assert_equal 0600, stat.mode & 0600
+ assert_equal 0o600, stat.mode & 0o600
end
end
def test_rubygems_api_key_equals_bad_permission
- pend "chmod not supported" if win_platform?
+ pend "chmod not supported" if Gem.win_platform?
@cfg.rubygems_api_key = "x"
- File.chmod 0644, @cfg.credentials_path
+ File.chmod 0o644, @cfg.credentials_path
assert_raise Gem::MockGemUi::TermError do
@cfg.rubygems_api_key = "y"
end
expected = {
- :rubygems_api_key => "x",
+ rubygems_api_key: "x",
}
assert_equal expected, load_yaml_file(@cfg.credentials_path)
stat = File.stat @cfg.credentials_path
- assert_equal 0644, stat.mode & 0644
+ assert_equal 0o644, stat.mode & 0o644
end
def test_write
@@ -470,7 +478,8 @@ if you believe they were disclosed to a third party.
end
begin
- verbose, $VERBOSE = $VERBOSE, nil
+ verbose = $VERBOSE
+ $VERBOSE = nil
util_config_file
ensure
@@ -478,6 +487,16 @@ if you believe they were disclosed to a third party.
end
end
+ def test_accept_string_key
+ File.open @temp_conf, "w" do |fp|
+ fp.puts "verbose: false"
+ end
+
+ util_config_file
+
+ assert_equal false, @cfg.verbose
+ end
+
def test_load_ssl_verify_mode_from_config
File.open @temp_conf, "w" do |fp|
fp.puts ":ssl_verify_mode: 1"
@@ -502,8 +521,12 @@ if you believe they were disclosed to a third party.
assert_equal("/home/me/mine.pem", @cfg.ssl_client_cert)
end
- def util_config_file(args = @cfg_args)
- @cfg = Gem::ConfigFile.new args
+ def test_load_install_extension_in_lib_from_config
+ File.open @temp_conf, "w" do |fp|
+ fp.puts ":install_extension_in_lib: false"
+ end
+ util_config_file
+ assert_equal(false, @cfg.install_extension_in_lib)
end
def test_disable_default_gem_server
@@ -513,4 +536,46 @@ if you believe they were disclosed to a third party.
util_config_file
assert_equal(true, @cfg.disable_default_gem_server)
end
+
+ def test_load_with_rubygems_config_hash
+ yaml = <<~YAML
+ ---
+ :foo: bar
+ bar: 100
+ buzz: true
+ alpha: :bravo
+ charlie: ""
+ delta:
+ YAML
+ actual = Gem::ConfigFile.load_with_rubygems_config_hash(yaml)
+
+ assert_equal "bar", actual[:foo]
+ assert_equal 100, actual["bar"]
+ assert_equal true, actual["buzz"]
+ assert_equal :bravo, actual["alpha"]
+ assert_equal nil, actual["charlie"]
+ assert_equal nil, actual["delta"]
+ end
+
+ def test_dump_with_rubygems_yaml
+ symbol_key_hash = { foo: "bar" }
+
+ actual = Gem::ConfigFile.dump_with_rubygems_yaml(symbol_key_hash)
+
+ assert_equal("---\n:foo: \"bar\"\n", actual)
+ end
+
+ def test_handle_comment
+ yaml = <<~YAML
+ ---
+ :foo: bar # buzz
+ YAML
+
+ actual = Gem::ConfigFile.load_with_rubygems_config_hash(yaml)
+ assert_equal("bar", actual[:foo])
+ end
+
+ def util_config_file(args = @cfg_args)
+ @cfg = Gem::ConfigFile.new args
+ end
end