From d89cc317c642848008f5b17a82196d25ddcdf124 Mon Sep 17 00:00:00 2001 From: Hiroshi SHIBATA Date: Tue, 11 Apr 2023 14:56:08 +0900 Subject: [PATCH] util/rubocop -A --only Style/NumericLiteralPrefix --- lib/rubygems.rb | 2 +- lib/rubygems/commands/cert_command.rb | 4 +- lib/rubygems/commands/setup_command.rb | 14 ++-- lib/rubygems/config_file.rb | 6 +- lib/rubygems/indexer.rb | 2 +- lib/rubygems/installer.rb | 14 ++-- lib/rubygems/package.rb | 12 ++-- lib/rubygems/package/old.rb | 2 +- lib/rubygems/package/tar_writer.rb | 2 +- lib/rubygems/security.rb | 2 +- lib/rubygems/security/trust_dir.rb | 8 +-- lib/rubygems/specification_policy.rb | 2 +- test/rubygems/helper.rb | 2 +- test/rubygems/package/tar_test_case.rb | 4 +- test/rubygems/test_gem.rb | 36 +++++----- .../test_gem_commands_cert_command.rb | 26 ++++---- .../test_gem_commands_cleanup_command.rb | 4 +- .../test_gem_commands_install_command.rb | 6 +- .../test_gem_commands_pristine_command.rb | 4 +- .../test_gem_commands_unpack_command.rb | 4 +- test/rubygems/test_gem_config_file.rb | 14 ++-- .../test_gem_install_update_options.rb | 6 +- test/rubygems/test_gem_installer.rb | 18 ++--- test/rubygems/test_gem_package.rb | 66 +++++++++---------- test/rubygems/test_gem_package_old.rb | 2 +- test/rubygems/test_gem_package_tar_header.rb | 6 +- test/rubygems/test_gem_package_tar_reader.rb | 8 +-- test/rubygems/test_gem_package_tar_writer.rb | 50 +++++++------- test/rubygems/test_gem_rdoc.rb | 4 +- test/rubygems/test_gem_remote_fetcher.rb | 16 ++--- test/rubygems/test_gem_security.rb | 4 +- test/rubygems/test_gem_security_signer.rb | 4 +- test/rubygems/test_gem_security_trust_dir.rb | 12 ++-- test/rubygems/test_gem_spec_fetcher.rb | 4 +- test/rubygems/test_gem_specification.rb | 22 +++---- test/rubygems/test_gem_util.rb | 4 +- 36 files changed, 198 insertions(+), 198 deletions(-) diff --git a/lib/rubygems.rb b/lib/rubygems.rb index de0c8b84c3be9d..cb716570187433 100644 --- a/lib/rubygems.rb +++ b/lib/rubygems.rb @@ -429,7 +429,7 @@ def self.ensure_default_gem_subdirectories(dir = Gem.dir, mode = nil) def self.ensure_subdirectories(dir, mode, subdirs) # :nodoc: old_umask = File.umask - File.umask old_umask | 002 + File.umask old_umask | 0o002 options = {} diff --git a/lib/rubygems/commands/cert_command.rb b/lib/rubygems/commands/cert_command.rb index 57f01a3ae1379c..22864a9b29005f 100644 --- a/lib/rubygems/commands/cert_command.rb +++ b/lib/rubygems/commands/cert_command.rb @@ -178,7 +178,7 @@ def build_key # :nodoc: algorithm = options[:key_algorithm] || Gem::Security::DEFAULT_KEY_ALGORITHM key = Gem::Security.create_key(algorithm) - key_path = Gem::Security.write key, "gem-private_key.pem", 0600, passphrase + key_path = Gem::Security.write key, "gem-private_key.pem", 0o600, passphrase [key, key_path] end @@ -291,7 +291,7 @@ def sign(cert_file) cert = File.read cert_file cert = OpenSSL::X509::Certificate.new cert - permissions = File.stat(cert_file).mode & 0777 + permissions = File.stat(cert_file).mode & 0o777 issuer_cert = options[:issuer_cert] issuer_key = options[:key] diff --git a/lib/rubygems/commands/setup_command.rb b/lib/rubygems/commands/setup_command.rb index cf3924df542bad..c2b681c60d3d55 100644 --- a/lib/rubygems/commands/setup_command.rb +++ b/lib/rubygems/commands/setup_command.rb @@ -243,7 +243,7 @@ def execute end def install_executables(bin_dir) - prog_mode = options[:prog_mode] || 0755 + prog_mode = options[:prog_mode] || 0o755 executables = { "gem" => "bin" } executables.each do |tool, path| @@ -369,7 +369,7 @@ def install_default_bundler_gem(bin_dir) File.dirname(loaded_from) else target_specs_dir = File.join(default_dir, "specifications", "default") - mkdir_p target_specs_dir, :mode => 0755 + mkdir_p target_specs_dir, :mode => 0o755 target_specs_dir end @@ -393,7 +393,7 @@ def install_default_bundler_gem(bin_dir) end bundler_bin_dir = bundler_spec.bin_dir - mkdir_p bundler_bin_dir, :mode => 0755 + mkdir_p bundler_bin_dir, :mode => 0o755 bundler_spec.executables.each do |e| cp File.join("bundler", bundler_spec.bindir, e), File.join(bundler_bin_dir, e) end @@ -430,8 +430,8 @@ def make_destination_dirs lib_dir, bin_dir = generate_default_dirs end - mkdir_p lib_dir, :mode => 0755 - mkdir_p bin_dir, :mode => 0755 + mkdir_p lib_dir, :mode => 0o755 + mkdir_p bin_dir, :mode => 0o755 [lib_dir, bin_dir] end @@ -639,10 +639,10 @@ def install_file(file, dest_dir) dest_file = File.join dest_dir, file dest_dir = File.dirname dest_file unless File.directory? dest_dir - mkdir_p dest_dir, :mode => 0755 + mkdir_p dest_dir, :mode => 0o755 end - install file, dest_file, :mode => options[:data_mode] || 0644 + install file, dest_file, :mode => options[:data_mode] || 0o644 end def remove_file_list(files, dir) diff --git a/lib/rubygems/config_file.rb b/lib/rubygems/config_file.rb index 0a5f6ffad2e76c..9d38d8b134fc4c 100644 --- a/lib/rubygems/config_file.rb +++ b/lib/rubygems/config_file.rb @@ -241,9 +241,9 @@ def check_credentials_permissions return if Gem.win_platform? # windows doesn't write 0600 as 0600 return unless File.exist? credentials_path - existing_permissions = File.stat(credentials_path).mode & 0777 + existing_permissions = File.stat(credentials_path).mode & 0o777 - return if existing_permissions == 0600 + return if existing_permissions == 0o600 alert_error <<-ERROR Your gem push credentials file located at: @@ -326,7 +326,7 @@ def set_api_key(host, api_key) Gem.load_yaml - permissions = 0600 & (~File.umask) + permissions = 0o600 & (~File.umask) File.open(credentials_path, "w", permissions) do |f| f.write config.to_yaml end diff --git a/lib/rubygems/indexer.rb b/lib/rubygems/indexer.rb index 6a13d9c11ca7a0..c6691517b38dab 100644 --- a/lib/rubygems/indexer.rb +++ b/lib/rubygems/indexer.rb @@ -327,7 +327,7 @@ def install_indices def make_temp_directories FileUtils.rm_rf @directory - FileUtils.mkdir_p @directory, :mode => 0700 + FileUtils.mkdir_p @directory, :mode => 0o700 FileUtils.mkdir_p @quick_marshal_dir end diff --git a/lib/rubygems/installer.rb b/lib/rubygems/installer.rb index 5aa6acf81104f7..0534d7c36b17c8 100644 --- a/lib/rubygems/installer.rb +++ b/lib/rubygems/installer.rb @@ -316,7 +316,7 @@ def install FileUtils.rm_rf spec.extension_dir dir_mode = options[:dir_mode] - FileUtils.mkdir_p gem_dir, :mode => dir_mode && 0755 + FileUtils.mkdir_p gem_dir, :mode => dir_mode && 0o755 if @options[:install_as_default] extract_bin @@ -495,7 +495,7 @@ def generate_bin # :nodoc: next unless File.exist? bin_path mode = File.stat(bin_path).mode - dir_mode = options[:prog_mode] || (mode | 0111) + dir_mode = options[:prog_mode] || (mode | 0o111) unless dir_mode == mode require "fileutils" @@ -540,9 +540,9 @@ def generate_bin_script(filename, bindir) require "fileutils" FileUtils.rm_f bin_script_path # prior install may have been --no-wrappers - File.open bin_script_path, "wb", 0755 do |file| + File.open bin_script_path, "wb", 0o755 do |file| file.print app_script_text(filename) - file.chmod(options[:prog_mode] || 0755) + file.chmod(options[:prog_mode] || 0o755) end verbose bin_script_path @@ -712,7 +712,7 @@ def check_that_user_bin_dir_is_in_path # :nodoc: end def verify_gem_home # :nodoc: - FileUtils.mkdir_p gem_home, :mode => options[:dir_mode] && 0755 + FileUtils.mkdir_p gem_home, :mode => options[:dir_mode] && 0o755 raise Gem::FilePermissionError, gem_home unless File.writable?(gem_home) end @@ -934,7 +934,7 @@ def write_build_info_file build_info_dir = File.join gem_home, "build_info" dir_mode = options[:dir_mode] - FileUtils.mkdir_p build_info_dir, :mode => dir_mode && 0755 + FileUtils.mkdir_p build_info_dir, :mode => dir_mode && 0o755 build_info_file = File.join build_info_dir, "#{spec.full_name}.info" @@ -957,7 +957,7 @@ def write_cache_file def ensure_writable_dir(dir) # :nodoc: begin - Dir.mkdir dir, *[options[:dir_mode] && 0755].compact + Dir.mkdir dir, *[options[:dir_mode] && 0o755].compact rescue SystemCallError raise unless File.directory? dir end diff --git a/lib/rubygems/package.rb b/lib/rubygems/package.rb index c3f91ebc34f8e4..61cae75357f83e 100644 --- a/lib/rubygems/package.rb +++ b/lib/rubygems/package.rb @@ -230,7 +230,7 @@ def add_checksums(tar) end end - tar.add_file_signed "checksums.yaml.gz", 0444, @signer do |io| + tar.add_file_signed "checksums.yaml.gz", 0o444, @signer do |io| gzip_to io do |gz_io| Psych.dump checksums_by_algorithm, gz_io end @@ -242,7 +242,7 @@ def add_checksums(tar) # and adds this file to the +tar+. def add_contents(tar) # :nodoc: - digests = tar.add_file_signed "data.tar.gz", 0444, @signer do |io| + digests = tar.add_file_signed "data.tar.gz", 0o444, @signer do |io| gzip_to io do |gz_io| Gem::Package::TarWriter.new gz_io do |data_tar| add_files data_tar @@ -278,7 +278,7 @@ def add_files(tar) # :nodoc: # Adds the package's Gem::Specification to the +tar+ file def add_metadata(tar) # :nodoc: - digests = tar.add_file_signed "metadata.gz", 0444, @signer do |io| + digests = tar.add_file_signed "metadata.gz", 0o444, @signer do |io| gzip_to io do |gz_io| gz_io.write @spec.to_yaml end @@ -382,7 +382,7 @@ def digest(entry) # :nodoc: def extract_files(destination_dir, pattern = "*") verify unless @spec - FileUtils.mkdir_p destination_dir, :mode => dir_mode && 0755 + FileUtils.mkdir_p destination_dir, :mode => dir_mode && 0o755 @gem.with_read_io do |io| reader = Gem::Package::TarReader.new io @@ -432,7 +432,7 @@ def extract_tar_gz(io, destination_dir, pattern = "*") # :nodoc: FileUtils.rm_rf destination mkdir_options = {} - mkdir_options[:mode] = dir_mode ? 0755 : (entry.header.mode if entry.directory?) + mkdir_options[:mode] = dir_mode ? 0o755 : (entry.header.mode if entry.directory?) mkdir = if entry.directory? destination @@ -468,7 +468,7 @@ def extract_tar_gz(io, destination_dir, pattern = "*") # :nodoc: end def file_mode(mode) # :nodoc: - ((mode & 0111).zero? ? data_mode : prog_mode) || + ((mode & 0o111).zero? ? data_mode : prog_mode) || # If we're not using one of the default modes, then we're going to fall # back to the mode from the tarball. In this case we need to mask it down # to fit into 2^16 bits (the maximum value for a mode in CRuby since it diff --git a/lib/rubygems/package/old.rb b/lib/rubygems/package/old.rb index bf0ed61b0a85d8..41f6986b8f5ad8 100644 --- a/lib/rubygems/package/old.rb +++ b/lib/rubygems/package/old.rb @@ -78,7 +78,7 @@ def extract_files(destination_dir) FileUtils.rm_rf destination - FileUtils.mkdir_p File.dirname(destination), :mode => dir_mode && 0755 + FileUtils.mkdir_p File.dirname(destination), :mode => dir_mode && 0o755 File.open destination, "wb", file_mode(entry["mode"]) do |out| out.write file_data diff --git a/lib/rubygems/package/tar_writer.rb b/lib/rubygems/package/tar_writer.rb index 30880d893cfd9f..e06ec25961616d 100644 --- a/lib/rubygems/package/tar_writer.rb +++ b/lib/rubygems/package/tar_writer.rb @@ -192,7 +192,7 @@ def add_file_signed(name, mode, signer) if signer.key signature = signer.sign signature_digest.digest - add_file_simple "#{name}.sig", 0444, signature.length do |io| + add_file_simple "#{name}.sig", 0o444, signature.length do |io| io.write signature end end diff --git a/lib/rubygems/security.rb b/lib/rubygems/security.rb index 46f084fa404fc7..1e8e57b5a96165 100644 --- a/lib/rubygems/security.rb +++ b/lib/rubygems/security.rb @@ -589,7 +589,7 @@ def self.trusted_certificates(&block) # +permissions+. If passed +cipher+ and +passphrase+ those arguments will be # passed to +to_pem+. - def self.write(pemmable, path, permissions = 0600, passphrase = nil, cipher = KEY_CIPHER) + def self.write(pemmable, path, permissions = 0o600, passphrase = nil, cipher = KEY_CIPHER) path = File.expand_path path File.open path, "wb", permissions do |io| diff --git a/lib/rubygems/security/trust_dir.rb b/lib/rubygems/security/trust_dir.rb index 713d0e6ffae7db..ea011e6d656614 100644 --- a/lib/rubygems/security/trust_dir.rb +++ b/lib/rubygems/security/trust_dir.rb @@ -9,8 +9,8 @@ class Gem::Security::TrustDir # Default permissions for the trust directory and its contents DEFAULT_PERMISSIONS = { - :trust_dir => 0700, - :trusted_cert => 0600, + :trust_dir => 0o700, + :trusted_cert => 0o600, }.freeze ## @@ -91,7 +91,7 @@ def trust_cert(certificate) destination = cert_path certificate - File.open destination, "wb", 0600 do |io| + File.open destination, "wb", 0o600 do |io| io.write certificate.to_pem io.chmod(@permissions[:trusted_cert]) end @@ -109,7 +109,7 @@ def verify "trust directory #{@dir} is not a directory" unless File.directory? @dir - FileUtils.chmod 0700, @dir + FileUtils.chmod 0o700, @dir else FileUtils.mkdir_p @dir, :mode => @permissions[:trust_dir] end diff --git a/lib/rubygems/specification_policy.rb b/lib/rubygems/specification_policy.rb index 06c0ba52ec1986..da3beee628c466 100644 --- a/lib/rubygems/specification_policy.rb +++ b/lib/rubygems/specification_policy.rb @@ -234,7 +234,7 @@ def validate_permissions @specification.files.each do |file| next unless File.file?(file) - next if File.stat(file).mode & 0444 == 0444 + next if File.stat(file).mode & 0o444 == 0o444 warning "#{file} is not world-readable" end diff --git a/test/rubygems/helper.rb b/test/rubygems/helper.rb index be43e2a26c9197..9ed26ce0116d8e 100644 --- a/test/rubygems/helper.rb +++ b/test/rubygems/helper.rb @@ -477,7 +477,7 @@ def credential_setup @temp_cred = File.join(@userhome, ".gem", "credentials") FileUtils.mkdir_p File.dirname(@temp_cred) File.write @temp_cred, ":rubygems_api_key: 701229f217cdf23b1344c7b4b54ca97" - File.chmod 0600, @temp_cred + File.chmod 0o600, @temp_cred end def credential_teardown diff --git a/test/rubygems/package/tar_test_case.rb b/test/rubygems/package/tar_test_case.rb index 6033c87415b8dd..e3d812bf3fd23d 100644 --- a/test/rubygems/package/tar_test_case.rb +++ b/test/rubygems/package/tar_test_case.rb @@ -163,11 +163,11 @@ def util_gem_data_tar(spec = nil, &block) data_tgz = util_tar_gz(&block) util_tar do |tar| if spec - tar.add_file "metadata.gz", 0444 do |io| + tar.add_file "metadata.gz", 0o444 do |io| io.write util_gzip(spec.to_yaml) end end - tar.add_file "data.tar.gz", 0644 do |io| + tar.add_file "data.tar.gz", 0o644 do |io| io.write data_tgz.string end end diff --git a/test/rubygems/test_gem.rb b/test/rubygems/test_gem.rb index 0f84ccd87dca1c..39a4c329cd02a5 100644 --- a/test/rubygems/test_gem.rb +++ b/test/rubygems/test_gem.rb @@ -132,7 +132,7 @@ def test_self_install_permissions_umask_0 end def test_self_install_permissions_umask_077 - umask = File.umask(077) + umask = File.umask(0o077) assert_self_install_permissions ensure File.umask(umask) @@ -152,11 +152,11 @@ def test_self_install_permissions_with_format_executable_and_non_standard_ruby_i end def assert_self_install_permissions(format_executable: false) - mask = Gem.win_platform? ? 0700 : 0777 + mask = Gem.win_platform? ? 0o700 : 0o777 options = { - :dir_mode => 0500, - :prog_mode => Gem.win_platform? ? 0410 : 0510, - :data_mode => 0640, + :dir_mode => 0o500, + :prog_mode => Gem.win_platform? ? 0o410 : 0o510, + :data_mode => 0o640, :wrappers => true, :format_executable => format_executable, } @@ -165,7 +165,7 @@ def assert_self_install_permissions(format_executable: false) Dir.mkdir "data" File.write "bin/foo", "#!/usr/bin/env ruby\n" - File.chmod 0755, "bin/foo" + File.chmod 0o755, "bin/foo" File.write "data/foo.txt", "blah\n" @@ -201,7 +201,7 @@ def assert_self_install_permissions(format_executable: false) end assert_equal(expected, result) ensure - File.chmod(0755, *Dir.glob(@gemhome + "/gems/**/").map {|path| path.tap(&Gem::UNTAINT) }) + File.chmod(0o755, *Dir.glob(@gemhome + "/gems/**/").map {|path| path.tap(&Gem::UNTAINT) }) end def test_require_missing @@ -639,12 +639,12 @@ def test_self_ensure_gem_directories_permissions FileUtils.rm_r @gemhome Gem.use_paths @gemhome - Gem.ensure_gem_subdirectories @gemhome, 0750 + Gem.ensure_gem_subdirectories @gemhome, 0o750 assert_directory_exists File.join(@gemhome, "cache") - assert_equal 0750, File::Stat.new(@gemhome).mode & 0777 - assert_equal 0750, File::Stat.new(File.join(@gemhome, "cache")).mode & 0777 + assert_equal 0o750, File::Stat.new(@gemhome).mode & 0o777 + assert_equal 0o750, File::Stat.new(File.join(@gemhome, "cache")).mode & 0o777 end unless Gem.win_platform? def test_self_ensure_gem_directories_safe_permissions @@ -655,8 +655,8 @@ def test_self_ensure_gem_directories_safe_permissions File.umask 0 Gem.ensure_gem_subdirectories @gemhome - assert_equal 0, File::Stat.new(@gemhome).mode & 002 - assert_equal 0, File::Stat.new(File.join(@gemhome, "cache")).mode & 002 + assert_equal 0, File::Stat.new(@gemhome).mode & 0o002 + assert_equal 0, File::Stat.new(File.join(@gemhome, "cache")).mode & 0o002 ensure File.umask old_umask end unless Gem.win_platform? @@ -687,14 +687,14 @@ def test_self_ensure_gem_directories_write_protected end refute File.exist?(gemdir), "manually remove #{gemdir}, tests are broken" FileUtils.mkdir_p gemdir - FileUtils.chmod 0400, gemdir + FileUtils.chmod 0o400, gemdir Gem.use_paths gemdir Gem.ensure_gem_subdirectories gemdir refute File.exist?(util_cache_dir) ensure - FileUtils.chmod 0600, gemdir + FileUtils.chmod 0o600, gemdir end def test_self_ensure_gem_directories_write_protected_parents @@ -708,14 +708,14 @@ def test_self_ensure_gem_directories_write_protected_parents end refute File.exist?(parent), "manually remove #{parent}, tests are broken" FileUtils.mkdir_p parent - FileUtils.chmod 0400, parent + FileUtils.chmod 0o400, parent Gem.use_paths(gemdir) Gem.ensure_gem_subdirectories gemdir refute File.exist? File.join(gemdir, "gems") ensure - FileUtils.chmod 0600, parent + FileUtils.chmod 0o600, parent end def test_self_ensure_gem_directories_non_existent_paths @@ -977,11 +977,11 @@ def test_self_read_binary pend "chmod not supported" if Gem.win_platform? begin - File.chmod 0444, "test" + File.chmod 0o444, "test" assert_equal ["\xCF", "\x80"], Gem.read_binary("test").chars.to_a ensure - File.chmod 0644, "test" + File.chmod 0o644, "test" end end diff --git a/test/rubygems/test_gem_commands_cert_command.rb b/test/rubygems/test_gem_commands_cert_command.rb index b4a511f4da690a..5249b25c8c22c2 100644 --- a/test/rubygems/test_gem_commands_cert_command.rb +++ b/test/rubygems/test_gem_commands_cert_command.rb @@ -476,7 +476,7 @@ def test_execute_remove_twice def test_execute_sign path = File.join @tempdir, "cert.pem" - Gem::Security.write ALTERNATE_CERT, path, 0600 + Gem::Security.write ALTERNATE_CERT, path, 0o600 assert_equal "/CN=alternate/DC=example", ALTERNATE_CERT.issuer.to_s @@ -498,14 +498,14 @@ def test_execute_sign assert_equal "/CN=nobody/DC=example", cert.issuer.to_s - mask = 0100600 & (~File.umask) + mask = 0o100600 & (~File.umask) assert_equal mask, File.stat(path).mode unless Gem.win_platform? end def test_execute_sign_encrypted_key path = File.join @tempdir, "cert.pem" - Gem::Security.write ALTERNATE_CERT, path, 0600 + Gem::Security.write ALTERNATE_CERT, path, 0o600 assert_equal "/CN=alternate/DC=example", ALTERNATE_CERT.issuer.to_s @@ -527,7 +527,7 @@ def test_execute_sign_encrypted_key assert_equal "/CN=nobody/DC=example", cert.issuer.to_s - mask = 0100600 & (~File.umask) + mask = 0o100600 & (~File.umask) assert_equal mask, File.stat(path).mode unless Gem.win_platform? end @@ -542,7 +542,7 @@ def test_execute_sign_default Gem::Security.write PUBLIC_CERT, public_cert_path path = File.join @tempdir, "cert.pem" - Gem::Security.write ALTERNATE_CERT, path, 0600 + Gem::Security.write ALTERNATE_CERT, path, 0o600 assert_equal "/CN=alternate/DC=example", ALTERNATE_CERT.issuer.to_s @@ -559,7 +559,7 @@ def test_execute_sign_default assert_equal "/CN=nobody/DC=example", cert.issuer.to_s - mask = 0100600 & (~File.umask) + mask = 0o100600 & (~File.umask) assert_equal mask, File.stat(path).mode unless Gem.win_platform? end @@ -568,13 +568,13 @@ def test_execute_sign_default_encrypted_key FileUtils.mkdir_p File.join(Gem.user_home, ".gem") private_key_path = File.join Gem.user_home, ".gem", "gem-private_key.pem" - Gem::Security.write ENCRYPTED_PRIVATE_KEY, private_key_path, 0600, PRIVATE_KEY_PASSPHRASE + Gem::Security.write ENCRYPTED_PRIVATE_KEY, private_key_path, 0o600, PRIVATE_KEY_PASSPHRASE public_cert_path = File.join Gem.user_home, ".gem", "gem-public_cert.pem" Gem::Security.write PUBLIC_CERT, public_cert_path path = File.join @tempdir, "cert.pem" - Gem::Security.write ALTERNATE_CERT, path, 0600 + Gem::Security.write ALTERNATE_CERT, path, 0o600 assert_equal "/CN=alternate/DC=example", ALTERNATE_CERT.issuer.to_s @@ -591,7 +591,7 @@ def test_execute_sign_default_encrypted_key assert_equal "/CN=nobody/DC=example", cert.issuer.to_s - mask = 0100600 & (~File.umask) + mask = 0o100600 & (~File.umask) assert_equal mask, File.stat(path).mode unless Gem.win_platform? end @@ -603,7 +603,7 @@ def test_execute_sign_no_cert Gem::Security.write PRIVATE_KEY, private_key_path path = File.join @tempdir, "cert.pem" - Gem::Security.write ALTERNATE_CERT, path, 0600 + Gem::Security.write ALTERNATE_CERT, path, 0o600 assert_equal "/CN=alternate/DC=example", ALTERNATE_CERT.issuer.to_s @@ -631,7 +631,7 @@ def test_execute_sign_no_key Gem::Security.write PUBLIC_CERT, public_cert_path path = File.join @tempdir, "cert.pem" - Gem::Security.write ALTERNATE_CERT, path, 0600 + Gem::Security.write ALTERNATE_CERT, path, 0o600 assert_equal "/CN=alternate/DC=example", ALTERNATE_CERT.issuer.to_s @@ -657,7 +657,7 @@ def test_execute_re_sign Dir.mkdir gem_path path = File.join @tempdir, "cert.pem" - Gem::Security.write EXPIRED_PUBLIC_CERT, path, 0600 + Gem::Security.write EXPIRED_PUBLIC_CERT, path, 0o600 assert_equal "/CN=nobody/DC=example", EXPIRED_PUBLIC_CERT.issuer.to_s @@ -689,7 +689,7 @@ def test_execute_re_sign_with_cert_expiration_length_days Dir.mkdir gem_path path = File.join @tempdir, "cert.pem" - Gem::Security.write EXPIRED_PUBLIC_CERT, path, 0600 + Gem::Security.write EXPIRED_PUBLIC_CERT, path, 0o600 assert_equal "/CN=nobody/DC=example", EXPIRED_PUBLIC_CERT.issuer.to_s diff --git a/test/rubygems/test_gem_commands_cleanup_command.rb b/test/rubygems/test_gem_commands_cleanup_command.rb index 53e3394361811f..732b3288a5a555 100644 --- a/test/rubygems/test_gem_commands_cleanup_command.rb +++ b/test/rubygems/test_gem_commands_cleanup_command.rb @@ -166,7 +166,7 @@ def test_execute_all_user end def test_execute_all_user_no_sudo - FileUtils.chmod 0555, @gemhome + FileUtils.chmod 0o555, @gemhome @a_1_1, = util_gem "a", "1.1" @a_1_1 = install_gem @a_1_1, :user_install => true # pick up user install path @@ -183,7 +183,7 @@ def test_execute_all_user_no_sudo assert_path_exist @a_1.gem_dir assert_path_exist @a_1_1.gem_dir ensure - FileUtils.chmod 0755, @gemhome + FileUtils.chmod 0o755, @gemhome end unless Gem.win_platform? || Process.uid.zero? def test_execute_dry_run diff --git a/test/rubygems/test_gem_commands_install_command.rb b/test/rubygems/test_gem_commands_install_command.rb index 008c3c7e10c092..90c030951e0cd5 100644 --- a/test/rubygems/test_gem_commands_install_command.rb +++ b/test/rubygems/test_gem_commands_install_command.rb @@ -205,8 +205,8 @@ def test_execute_no_user_install use_ui @ui do orig_dir = Dir.pwd begin - FileUtils.chmod 0755, @userhome - FileUtils.chmod 0555, @gemhome + FileUtils.chmod 0o755, @userhome + FileUtils.chmod 0o555, @gemhome Dir.chdir @tempdir assert_raise Gem::FilePermissionError do @@ -214,7 +214,7 @@ def test_execute_no_user_install end ensure Dir.chdir orig_dir - FileUtils.chmod 0755, @gemhome + FileUtils.chmod 0o755, @gemhome end end end diff --git a/test/rubygems/test_gem_commands_pristine_command.rb b/test/rubygems/test_gem_commands_pristine_command.rb index e5c3be1c7ad795..51b097dfbda634 100644 --- a/test/rubygems/test_gem_commands_pristine_command.rb +++ b/test/rubygems/test_gem_commands_pristine_command.rb @@ -54,7 +54,7 @@ def test_execute end def test_execute_user_install - FileUtils.chmod 0555, @gemhome + FileUtils.chmod 0o555, @gemhome a = util_spec "a" do |s| s.executables = %w[foo] @@ -99,7 +99,7 @@ def test_execute_user_install assert_equal "Restored #{a.full_name}", out.shift assert_empty out, out.inspect ensure - FileUtils.chmod(0755, @gemhome) + FileUtils.chmod(0o755, @gemhome) end def test_execute_all diff --git a/test/rubygems/test_gem_commands_unpack_command.rb b/test/rubygems/test_gem_commands_unpack_command.rb index e41b6bf2b93236..61cf8a611a0fd7 100644 --- a/test/rubygems/test_gem_commands_unpack_command.rb +++ b/test/rubygems/test_gem_commands_unpack_command.rb @@ -156,7 +156,7 @@ def test_execute_sudo util_make_gems - FileUtils.chmod 0555, @gemhome + FileUtils.chmod 0o555, @gemhome @cmd.options[:args] = %w[b] @@ -168,7 +168,7 @@ def test_execute_sudo assert File.exist?(File.join(@tempdir, "b-2")), "b should be unpacked" ensure - FileUtils.chmod 0755, @gemhome + FileUtils.chmod 0o755, @gemhome end def test_execute_with_target_option diff --git a/test/rubygems/test_gem_config_file.rb b/test/rubygems/test_gem_config_file.rb index c65b18af904a0d..d6957efb721fc2 100644 --- a/test/rubygems/test_gem_config_file.rb +++ b/test/rubygems/test_gem_config_file.rb @@ -185,7 +185,7 @@ def test_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| + File.open temp_cred, "w", 0o600 do |fp| fp.puts ":rubygems_api_key: 701229f217cdf23b1344c7b4b54ca97" end @@ -200,7 +200,7 @@ def test_check_credentials_permissions @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 @@ -323,7 +323,7 @@ def test_handle_arguments_norc 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| + File.open temp_cred, "w", 0o600 do |fp| fp.puts ":rubygems_api_key: 701229f217cdf23b1344c7b4b54ca97" fp.puts ":other: a5fdbb6ba150cbb83aad2bb2fede64c" end @@ -339,7 +339,7 @@ def test_load_api_keys_bad_permission @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 @@ -372,7 +372,7 @@ def test_rubygems_api_key_equals unless Gem.win_platform? stat = File.stat @cfg.credentials_path - assert_equal 0600, stat.mode & 0600 + assert_equal 0o600, stat.mode & 0o600 end end @@ -381,7 +381,7 @@ def test_rubygems_api_key_equals_bad_permission @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" @@ -395,7 +395,7 @@ def test_rubygems_api_key_equals_bad_permission stat = File.stat @cfg.credentials_path - assert_equal 0644, stat.mode & 0644 + assert_equal 0o644, stat.mode & 0o644 end def test_write diff --git a/test/rubygems/test_gem_install_update_options.rb b/test/rubygems/test_gem_install_update_options.rb index 9b136363d0576b..f3bd1c6d5efd6d 100644 --- a/test/rubygems/test_gem_install_update_options.rb +++ b/test/rubygems/test_gem_install_update_options.rb @@ -146,8 +146,8 @@ def test_user_install_disabled_read_only refute @cmd.options[:user_install] - FileUtils.chmod 0755, @userhome - FileUtils.chmod 0000, @gemhome + FileUtils.chmod 0o755, @userhome + FileUtils.chmod 0o000, @gemhome Gem.use_paths @gemhome, @userhome @@ -156,7 +156,7 @@ def test_user_install_disabled_read_only end end ensure - FileUtils.chmod 0755, @gemhome + FileUtils.chmod 0o755, @gemhome end def test_vendor diff --git a/test/rubygems/test_gem_installer.rb b/test/rubygems/test_gem_installer.rb index 965f05616bf93e..c4f107fd52752b 100644 --- a/test/rubygems/test_gem_installer.rb +++ b/test/rubygems/test_gem_installer.rb @@ -469,14 +469,14 @@ def test_generate_bin_script_no_perms elsif Process.uid.zero? pend("test_generate_bin_script_no_perms skipped in root privilege") else - FileUtils.chmod 0000, util_inst_bindir + FileUtils.chmod 0o000, util_inst_bindir assert_raise Gem::FilePermissionError do installer.generate_bin end end ensure - FileUtils.chmod 0755, util_inst_bindir unless $DEBUG || Gem.win_platform? + FileUtils.chmod 0o755, util_inst_bindir unless $DEBUG || Gem.win_platform? end def test_generate_bin_script_no_shebang @@ -573,14 +573,14 @@ def test_generate_bin_symlink_no_perms elsif Process.uid.zero? pend("test_user_install_disabled_read_only test skipped in root privilege") else - FileUtils.chmod 0000, util_inst_bindir + FileUtils.chmod 0o000, util_inst_bindir assert_raise Gem::FilePermissionError do installer.generate_bin end end ensure - FileUtils.chmod 0755, util_inst_bindir unless $DEBUG || Gem.win_platform? + FileUtils.chmod 0o755, util_inst_bindir unless $DEBUG || Gem.win_platform? end def test_generate_bin_symlink_update_newer @@ -818,7 +818,7 @@ def test_generate_plugins_with_user_install util_build_gem spec - File.chmod(0555, Gem.plugindir) + File.chmod(0o555, Gem.plugindir) system_path = File.join(Gem.plugindir, "a_plugin.rb") user_path = File.join(Gem.plugindir(Gem.user_dir), "a_plugin.rb") installer = util_installer spec, Gem.dir, :user @@ -840,7 +840,7 @@ def test_generate_plugins_with_build_root util_build_gem spec - File.chmod(0555, Gem.plugindir) + File.chmod(0o555, Gem.plugindir) system_path = File.join(Gem.plugindir, "a_plugin.rb") build_root = File.join(@tempdir, "build_root") @@ -986,8 +986,8 @@ def test_install exe = File.join gemdir, "bin", "executable" assert_path_exist exe - exe_mode = File.stat(exe).mode & 0111 - assert_equal 0111, exe_mode, format("0%o", exe_mode) unless Gem.win_platform? + exe_mode = File.stat(exe).mode & 0o111 + assert_equal 0o111, exe_mode, format("0%o", exe_mode) unless Gem.win_platform? assert_path_exist File.join gemdir, "lib", "code.rb" @@ -2458,7 +2458,7 @@ def util_conflict_executable(wrappers) end def mask - 0100755 + 0o100755 end def load_relative(value) diff --git a/test/rubygems/test_gem_package.rb b/test/rubygems/test_gem_package.rb index 18e10c5d5acf1c..1adb7801581753 100644 --- a/test/rubygems/test_gem_package.rb +++ b/test/rubygems/test_gem_package.rb @@ -442,11 +442,11 @@ def test_raw_spec data_tgz = util_tar_gz {} gem = util_tar do |tar| - tar.add_file "data.tar.gz", 0644 do |io| + tar.add_file "data.tar.gz", 0o644 do |io| io.write data_tgz.string end - tar.add_file "metadata.gz", 0644 do |io| + tar.add_file "metadata.gz", 0o644 do |io| Zlib::GzipWriter.wrap io do |gzio| gzio.write @spec.to_yaml end @@ -479,7 +479,7 @@ def test_extract_files extracted = File.join @destination, "lib/code.rb" assert_path_exist extracted - mask = 0100666 & (~File.umask) + mask = 0o100666 & (~File.umask) assert_equal mask.to_s(8), File.stat(extracted).mode.to_s(8) unless Gem.win_platform? @@ -489,11 +489,11 @@ def test_extract_files_empty data_tgz = util_tar_gz {} gem = util_tar do |tar| - tar.add_file "data.tar.gz", 0644 do |io| + tar.add_file "data.tar.gz", 0o644 do |io| io.write data_tgz.string end - tar.add_file "metadata.gz", 0644 do |io| + tar.add_file "metadata.gz", 0o644 do |io| Zlib::GzipWriter.wrap io do |gzio| gzio.write @spec.to_yaml end @@ -523,14 +523,14 @@ def test_extract_file_permissions filepath = File.join @destination, "README.rdoc" assert_path_exist filepath - assert_equal 0104444, File.stat(filepath).mode + assert_equal 0o104444, File.stat(filepath).mode end def test_extract_tar_gz_absolute package = Gem::Package.new @gem tgz_io = util_tar_gz do |tar| - tar.add_file "/absolute.rb", 0644 do |io| + tar.add_file "/absolute.rb", 0o644 do |io| io.write "hi" end end @@ -548,12 +548,12 @@ def test_extract_tar_gz_symlink_relative_path package.verify tgz_io = util_tar_gz do |tar| - tar.add_file "relative.rb", 0644 do |io| + tar.add_file "relative.rb", 0o644 do |io| io.write "hi" end - tar.mkdir "lib", 0755 - tar.add_symlink "lib/foo.rb", "../relative.rb", 0644 + tar.mkdir "lib", 0o755 + tar.add_symlink "lib/foo.rb", "../relative.rb", 0o644 end begin @@ -579,8 +579,8 @@ def test_extract_tar_gz_symlink_broken_relative_path package.verify tgz_io = util_tar_gz do |tar| - tar.mkdir "lib", 0755 - tar.add_symlink "lib/foo.rb", "../broken.rb", 0644 + tar.mkdir "lib", 0o755 + tar.add_symlink "lib/foo.rb", "../broken.rb", 0o644 end ui = Gem::MockGemUi.new @@ -599,9 +599,9 @@ def test_extract_symlink_parent package = Gem::Package.new @gem tgz_io = util_tar_gz do |tar| - tar.mkdir "lib", 0755 - tar.add_symlink "lib/link", "../..", 0644 - tar.add_file "lib/link/outside.txt", 0644 do |io| + tar.mkdir "lib", 0o755 + tar.add_symlink "lib/link", "../..", 0o644 + tar.add_file "lib/link/outside.txt", 0o644 do |io| io.write "hi" end end @@ -667,11 +667,11 @@ def test_extract_tar_gz_directory package = Gem::Package.new @gem tgz_io = util_tar_gz do |tar| - tar.mkdir "lib", 0755 - tar.add_file "lib/foo.rb", 0644 do |io| + tar.mkdir "lib", 0o755 + tar.add_file "lib/foo.rb", 0o644 do |io| io.write "hi" end - tar.mkdir "lib/foo", 0755 + tar.mkdir "lib/foo", 0o755 end package.extract_tar_gz tgz_io, @destination @@ -687,7 +687,7 @@ def test_extract_tar_gz_dot_slash package = Gem::Package.new @gem tgz_io = util_tar_gz do |tar| - tar.add_file "./dot_slash.rb", 0644 do |io| + tar.add_file "./dot_slash.rb", 0o644 do |io| io.write "hi" end end @@ -702,7 +702,7 @@ def test_extract_tar_gz_dot_file package = Gem::Package.new @gem tgz_io = util_tar_gz do |tar| - tar.add_file ".dot_file.rb", 0644 do |io| + tar.add_file ".dot_file.rb", 0o644 do |io| io.write "hi" end end @@ -718,7 +718,7 @@ def test_extract_tar_gz_case_insensitive package = Gem::Package.new @gem tgz_io = util_tar_gz do |tar| - tar.add_file "foo/file.rb", 0644 do |io| + tar.add_file "foo/file.rb", 0o644 do |io| io.write "hi" end end @@ -834,7 +834,7 @@ def test_verify def test_verify_checksum_bad data_tgz = util_tar_gz do |tar| - tar.add_file "lib/code.rb", 0444 do |io| + tar.add_file "lib/code.rb", 0o444 do |io| io.write "# lib/code.rb" end end @@ -844,11 +844,11 @@ def test_verify_checksum_bad gem = util_tar do |tar| metadata_gz = Gem::Util.gzip @spec.to_yaml - tar.add_file "metadata.gz", 0444 do |io| + tar.add_file "metadata.gz", 0o444 do |io| io.write metadata_gz end - tar.add_file "data.tar.gz", 0444 do |io| + tar.add_file "data.tar.gz", 0o444 do |io| io.write data_tgz end @@ -858,7 +858,7 @@ def test_verify_checksum_bad "metadata.gz" => "bogus", }, } - tar.add_file "checksums.yaml.gz", 0444 do |io| + tar.add_file "checksums.yaml.gz", 0o444 do |io| Zlib::GzipWriter.wrap io do |gz_io| gz_io.write Psych.dump bogus_checksums end @@ -881,7 +881,7 @@ def test_verify_checksum_bad def test_verify_checksum_missing data_tgz = util_tar_gz do |tar| - tar.add_file "lib/code.rb", 0444 do |io| + tar.add_file "lib/code.rb", 0o444 do |io| io.write "# lib/code.rb" end end @@ -891,7 +891,7 @@ def test_verify_checksum_missing gem = util_tar do |tar| metadata_gz = Gem::Util.gzip @spec.to_yaml - tar.add_file "metadata.gz", 0444 do |io| + tar.add_file "metadata.gz", 0o444 do |io| io.write metadata_gz end @@ -904,13 +904,13 @@ def test_verify_checksum_missing }, } - tar.add_file "checksums.yaml.gz", 0444 do |io| + tar.add_file "checksums.yaml.gz", 0o444 do |io| Zlib::GzipWriter.wrap io do |gz_io| gz_io.write Psych.dump checksums end end - tar.add_file "data.tar.gz", 0444 do |io| + tar.add_file "data.tar.gz", 0o444 do |io| io.write data_tgz end end @@ -929,7 +929,7 @@ def test_verify_corrupt tf = Tempfile.open "corrupt" do |io| data = Gem::Util.gzip "a" * 10 io.write \ - tar_file_header("metadata.gz", "\000x", 0644, data.length, Time.now) + tar_file_header("metadata.gz", "\000x", 0o644, data.length, Time.now) io.write data io.rewind @@ -981,8 +981,8 @@ def test_verify_duplicate_file build.add_metadata gem build.add_contents gem - gem.add_file_simple "a.sig", 0444, 0 - gem.add_file_simple "a.sig", 0444, 0 + gem.add_file_simple "a.sig", 0o444, 0 + gem.add_file_simple "a.sig", 0o444, 0 end end @@ -1069,7 +1069,7 @@ def sign(*) "fake_sig" end end - gem.add_file_signed "data2.tar.gz", 0444, fake_signer.new do |io| + gem.add_file_signed "data2.tar.gz", 0o444, fake_signer.new do |io| io.write bogus_data end diff --git a/test/rubygems/test_gem_package_old.rb b/test/rubygems/test_gem_package_old.rb index f95bbaf1d26f05..7582dbedd40f08 100644 --- a/test/rubygems/test_gem_package_old.rb +++ b/test/rubygems/test_gem_package_old.rb @@ -39,7 +39,7 @@ def test_extract_files extracted = File.join @destination, "lib/foo.rb" assert_path_exist extracted - mask = 0100644 & (~File.umask) + mask = 0o100644 & (~File.umask) assert_equal mask, File.stat(extracted).mode unless Gem.win_platform? end diff --git a/test/rubygems/test_gem_package_tar_header.rb b/test/rubygems/test_gem_package_tar_header.rb index d992bcd4d3ff0f..bbdf20c23cb19f 100644 --- a/test/rubygems/test_gem_package_tar_header.rb +++ b/test/rubygems/test_gem_package_tar_header.rb @@ -9,7 +9,7 @@ def setup header = { :name => "x", - :mode => 0644, + :mode => 0o644, :uid => 1000, :gid => 10_000, :size => 100, @@ -44,7 +44,7 @@ def test_initialize assert_equal "group", @tar_header.gname, "gname" assert_equal "link", @tar_header.linkname, "linkname" assert_equal "ustar", @tar_header.magic, "magic" - assert_equal 0644, @tar_header.mode, "mode" + assert_equal 0o644, @tar_header.mode, "mode" assert_equal 12_345, @tar_header.mtime, "mtime" assert_equal "x", @tar_header.name, "name" assert_equal "y", @tar_header.prefix, "prefix" @@ -200,7 +200,7 @@ def test_big_uid_gid assert_equal 1_991_400_094, tar_header.gid assert_equal "GeoIP2-City_20190528/", tar_header.name - assert_equal 0755, tar_header.mode + assert_equal 0o755, tar_header.mode assert_equal 0, tar_header.size assert_equal 1_559_064_640, tar_header.mtime assert_equal 6932, tar_header.checksum diff --git a/test/rubygems/test_gem_package_tar_reader.rb b/test/rubygems/test_gem_package_tar_reader.rb index 7f16ba74cfe774..178e29c3d030ca 100644 --- a/test/rubygems/test_gem_package_tar_reader.rb +++ b/test/rubygems/test_gem_package_tar_reader.rb @@ -29,7 +29,7 @@ def test_rewind content = ("a".."z").to_a.join(" ") str = - tar_file_header("lib/foo", "", 010644, content.size, Time.now) + + tar_file_header("lib/foo", "", 0o10644, content.size, Time.now) + content + "\0" * (512 - content.size) str << "\0" * 1024 @@ -90,7 +90,7 @@ def test_seek_missing def test_read_in_gem_data gem_tar = util_gem_data_tar do |tar| - tar.add_file "lib/code.rb", 0444 do |io| + tar.add_file "lib/code.rb", 0o444 do |io| io.write "# lib/code.rb" end end @@ -112,10 +112,10 @@ def test_read_in_gem_data def test_seek_in_gem_data gem_tar = util_gem_data_tar do |tar| - tar.add_file "lib/code.rb", 0444 do |io| + tar.add_file "lib/code.rb", 0o444 do |io| io.write "# lib/code.rb" end - tar.add_file "lib/foo.rb", 0444 do |io| + tar.add_file "lib/foo.rb", 0o444 do |io| io.write "# lib/foo.rb" end end diff --git a/test/rubygems/test_gem_package_tar_writer.rb b/test/rubygems/test_gem_package_tar_writer.rb index 5e78c0ef25202f..751ceaca81cb5b 100644 --- a/test/rubygems/test_gem_package_tar_writer.rb +++ b/test/rubygems/test_gem_package_tar_writer.rb @@ -29,11 +29,11 @@ def teardown def test_add_file Time.stub :now, Time.at(1_458_518_157) do - @tar_writer.add_file "x", 0644 do |f| + @tar_writer.add_file "x", 0o644 do |f| f.write "a" * 10 end - assert_headers_equal(tar_file_header("x", "", 0644, 10, Time.now), + assert_headers_equal(tar_file_header("x", "", 0o644, 10, Time.now), @io.string[0, 512]) end assert_equal "aaaaaaaaaa#{"\0" * 502}", @io.string[512, 512] @@ -43,18 +43,18 @@ def test_add_file def test_add_file_source_date_epoch ENV["SOURCE_DATE_EPOCH"] = "123456789" Time.stub :now, Time.at(1_458_518_157) do - @tar_writer.mkdir "foo", 0644 + @tar_writer.mkdir "foo", 0o644 - assert_headers_equal tar_dir_header("foo", "", 0644, Time.at(ENV["SOURCE_DATE_EPOCH"].to_i).utc), + assert_headers_equal tar_dir_header("foo", "", 0o644, Time.at(ENV["SOURCE_DATE_EPOCH"].to_i).utc), @io.string[0, 512] end end def test_add_symlink Time.stub :now, Time.at(1_458_518_157) do - @tar_writer.add_symlink "x", "y", 0644 + @tar_writer.add_symlink "x", "y", 0o644 - assert_headers_equal(tar_symlink_header("x", "", 0644, Time.now, "y"), + assert_headers_equal(tar_symlink_header("x", "", 0o644, Time.now, "y"), @io.string[0, 512]) end assert_equal 512, @io.pos @@ -63,9 +63,9 @@ def test_add_symlink def test_add_symlink_source_date_epoch ENV["SOURCE_DATE_EPOCH"] = "123456789" Time.stub :now, Time.at(1_458_518_157) do - @tar_writer.add_symlink "x", "y", 0644 + @tar_writer.add_symlink "x", "y", 0o644 - assert_headers_equal(tar_symlink_header("x", "", 0644, Time.at(ENV["SOURCE_DATE_EPOCH"].to_i).utc, "y"), + assert_headers_equal(tar_symlink_header("x", "", 0o644, Time.at(ENV["SOURCE_DATE_EPOCH"].to_i).utc, "y"), @io.string[0, 512]) end end @@ -74,7 +74,7 @@ def test_add_file_digest digest_algorithms = OpenSSL::Digest::SHA1.new, OpenSSL::Digest::SHA512.new Time.stub :now, Time.at(1_458_518_157) do - digests = @tar_writer.add_file_digest "x", 0644, digest_algorithms do |io| + digests = @tar_writer.add_file_digest "x", 0o644, digest_algorithms do |io| io.write "a" * 10 end @@ -86,7 +86,7 @@ def test_add_file_digest "e1cf14b0", digests["SHA512"].hexdigest - assert_headers_equal(tar_file_header("x", "", 0644, 10, Time.now), + assert_headers_equal(tar_file_header("x", "", 0o644, 10, Time.now), @io.string[0, 512]) end assert_equal "aaaaaaaaaa#{"\0" * 502}", @io.string[512, 512] @@ -97,7 +97,7 @@ def test_add_file_digest_multiple digest_algorithms = [OpenSSL::Digest::SHA1.new, OpenSSL::Digest::SHA512.new] Time.stub :now, Time.at(1_458_518_157) do - digests = @tar_writer.add_file_digest "x", 0644, digest_algorithms do |io| + digests = @tar_writer.add_file_digest "x", 0o644, digest_algorithms do |io| io.write "a" * 10 end @@ -109,7 +109,7 @@ def test_add_file_digest_multiple "e1cf14b0", digests["SHA512"].hexdigest - assert_headers_equal(tar_file_header("x", "", 0644, 10, Time.now), + assert_headers_equal(tar_file_header("x", "", 0o644, 10, Time.now), @io.string[0, 512]) end assert_equal "aaaaaaaaaa#{"\0" * 502}", @io.string[512, 512] @@ -122,11 +122,11 @@ def test_add_file_signer signer = Gem::Security::Signer.new PRIVATE_KEY, [PUBLIC_CERT] Time.stub :now, Time.at(1_458_518_157) do - @tar_writer.add_file_signed "x", 0644, signer do |io| + @tar_writer.add_file_signed "x", 0o644, signer do |io| io.write "a" * 10 end - assert_headers_equal(tar_file_header("x", "", 0644, 10, Time.now), + assert_headers_equal(tar_file_header("x", "", 0o644, 10, Time.now), @io.string[0, 512]) assert_equal "aaaaaaaaaa#{"\0" * 502}", @io.string[512, 512] @@ -136,7 +136,7 @@ def test_add_file_signer signature = signer.sign digest.digest - assert_headers_equal(tar_file_header("x.sig", "", 0444, signature.length, + assert_headers_equal(tar_file_header("x.sig", "", 0o444, signature.length, Time.now), @io.string[1024, 512]) assert_equal "#{signature}#{"\0" * (512 - signature.length)}", @@ -150,11 +150,11 @@ def test_add_file_signer_empty signer = Gem::Security::Signer.new nil, nil Time.stub :now, Time.at(1_458_518_157) do - @tar_writer.add_file_signed "x", 0644, signer do |io| + @tar_writer.add_file_signed "x", 0o644, signer do |io| io.write "a" * 10 end - assert_headers_equal(tar_file_header("x", "", 0644, 10, Time.now), + assert_headers_equal(tar_file_header("x", "", 0o644, 10, Time.now), @io.string[0, 512]) end assert_equal "aaaaaaaaaa#{"\0" * 502}", @io.string[512, 512] @@ -164,11 +164,11 @@ def test_add_file_signer_empty def test_add_file_simple Time.stub :now, Time.at(1_458_518_157) do - @tar_writer.add_file_simple "x", 0644, 10 do |io| + @tar_writer.add_file_simple "x", 0o644, 10 do |io| io.write "a" * 10 end - assert_headers_equal(tar_file_header("x", "", 0644, 10, Time.now), + assert_headers_equal(tar_file_header("x", "", 0o644, 10, Time.now), @io.string[0, 512]) assert_equal "aaaaaaaaaa#{"\0" * 502}", @io.string[512, 512] @@ -179,11 +179,11 @@ def test_add_file_simple def test_add_file_simple_source_date_epoch ENV["SOURCE_DATE_EPOCH"] = "123456789" Time.stub :now, Time.at(1_458_518_157) do - @tar_writer.add_file_simple "x", 0644, 10 do |io| + @tar_writer.add_file_simple "x", 0o644, 10 do |io| io.write "a" * 10 end - assert_headers_equal(tar_file_header("x", "", 0644, 10, Time.at(ENV["SOURCE_DATE_EPOCH"].to_i).utc), + assert_headers_equal(tar_file_header("x", "", 0o644, 10, Time.at(ENV["SOURCE_DATE_EPOCH"].to_i).utc), @io.string[0, 512]) end end @@ -248,9 +248,9 @@ def test_close def test_mkdir Time.stub :now, Time.at(1_458_518_157) do - @tar_writer.mkdir "foo", 0644 + @tar_writer.mkdir "foo", 0o644 - assert_headers_equal tar_dir_header("foo", "", 0644, Time.now), + assert_headers_equal tar_dir_header("foo", "", 0o644, Time.now), @io.string[0, 512] assert_equal 512, @io.pos @@ -260,9 +260,9 @@ def test_mkdir def test_mkdir_source_date_epoch ENV["SOURCE_DATE_EPOCH"] = "123456789" Time.stub :now, Time.at(1_458_518_157) do - @tar_writer.mkdir "foo", 0644 + @tar_writer.mkdir "foo", 0o644 - assert_headers_equal tar_dir_header("foo", "", 0644, Time.at(ENV["SOURCE_DATE_EPOCH"].to_i).utc), + assert_headers_equal tar_dir_header("foo", "", 0o644, Time.at(ENV["SOURCE_DATE_EPOCH"].to_i).utc), @io.string[0, 512] end end diff --git a/test/rubygems/test_gem_rdoc.rb b/test/rubygems/test_gem_rdoc.rb index 69baae00399d30..f9b1df6cd55aa1 100644 --- a/test/rubygems/test_gem_rdoc.rb +++ b/test/rubygems/test_gem_rdoc.rb @@ -100,7 +100,7 @@ def test_remove_unwritable assert_equal @a.base_dir, e.directory ensure - FileUtils.chmod(0755, @a.base_dir) if File.directory?(@a.base_dir) + FileUtils.chmod(0o755, @a.base_dir) if File.directory?(@a.base_dir) end def test_ri_installed? @@ -130,7 +130,7 @@ def test_setup_unwritable assert_equal @a.doc_dir, e.directory ensure if File.exist? @a.doc_dir - FileUtils.chmod 0755, @a.doc_dir + FileUtils.chmod 0o755, @a.doc_dir FileUtils.rm_r @a.doc_dir end end diff --git a/test/rubygems/test_gem_remote_fetcher.rb b/test/rubygems/test_gem_remote_fetcher.rb index 21053843986b50..47633175f6dc92 100644 --- a/test/rubygems/test_gem_remote_fetcher.rb +++ b/test/rubygems/test_gem_remote_fetcher.rb @@ -359,13 +359,13 @@ def test_download_local_read_only FileUtils.mv @a1_gem, @tempdir local_path = File.join @tempdir, @a1.file_name inst = nil - FileUtils.chmod 0555, @a1.cache_dir + FileUtils.chmod 0o555, @a1.cache_dir begin FileUtils.mkdir_p File.join(Gem.user_dir, "cache") rescue StandardError nil end - FileUtils.chmod 0555, File.join(Gem.user_dir, "cache") + FileUtils.chmod 0o555, File.join(Gem.user_dir, "cache") Dir.chdir @tempdir do inst = Gem::RemoteFetcher.fetcher @@ -374,21 +374,21 @@ def test_download_local_read_only assert_equal(File.join(@tempdir, @a1.file_name), inst.download(@a1, local_path)) ensure - FileUtils.chmod 0755, File.join(Gem.user_dir, "cache") - FileUtils.chmod 0755, @a1.cache_dir + FileUtils.chmod 0o755, File.join(Gem.user_dir, "cache") + FileUtils.chmod 0o755, @a1.cache_dir end def test_download_read_only - FileUtils.chmod 0555, @a1.cache_dir - FileUtils.chmod 0555, @gemhome + FileUtils.chmod 0o555, @a1.cache_dir + FileUtils.chmod 0o555, @gemhome fetcher = util_fuck_with_fetcher File.read(@a1_gem) fetcher.download(@a1, "http://gems.example.com") a1_cache_gem = File.join Gem.user_dir, "cache", @a1.file_name assert File.exist? a1_cache_gem ensure - FileUtils.chmod 0755, @gemhome - FileUtils.chmod 0755, @a1.cache_dir + FileUtils.chmod 0o755, @gemhome + FileUtils.chmod 0o755, @a1.cache_dir end end diff --git a/test/rubygems/test_gem_security.rb b/test/rubygems/test_gem_security.rb index 757f866d839358..110d741310ebc3 100644 --- a/test/rubygems/test_gem_security.rb +++ b/test/rubygems/test_gem_security.rb @@ -308,7 +308,7 @@ def test_class_write_encrypted passphrase = "It should be long." - @SEC.write key, path, 0600, passphrase + @SEC.write key, path, 0o600, passphrase assert_path_exist path @@ -326,7 +326,7 @@ def test_class_write_encrypted_cipher cipher = OpenSSL::Cipher.new "AES-192-CBC" - @SEC.write key, path, 0600, passphrase, cipher + @SEC.write key, path, 0o600, passphrase, cipher assert_path_exist path diff --git a/test/rubygems/test_gem_security_signer.rb b/test/rubygems/test_gem_security_signer.rb index f97d9727d1f8d5..5265678d299d42 100644 --- a/test/rubygems/test_gem_security_signer.rb +++ b/test/rubygems/test_gem_security_signer.rb @@ -144,7 +144,7 @@ def test_sign_expired def test_sign_expired_auto_update pend if Gem.java_platform? - FileUtils.mkdir_p File.join(Gem.user_home, ".gem"), :mode => 0700 + FileUtils.mkdir_p File.join(Gem.user_home, ".gem"), :mode => 0o700 private_key_path = File.join(Gem.user_home, ".gem", "gem-private_key.pem") Gem::Security.write PRIVATE_KEY, private_key_path @@ -171,7 +171,7 @@ def test_sign_expired_auto_update end def test_sign_expired_auto_update_exists - FileUtils.mkdir_p File.join(Gem.user_home, ".gem"), :mode => 0700 + FileUtils.mkdir_p File.join(Gem.user_home, ".gem"), :mode => 0o700 expiry = EXPIRED_CERT.not_after.strftime "%Y%m%d%H%M%S" expired_path = diff --git a/test/rubygems/test_gem_security_trust_dir.rb b/test/rubygems/test_gem_security_trust_dir.rb index f398ab40f9e93c..b7c9a6feb03820 100644 --- a/test/rubygems/test_gem_security_trust_dir.rb +++ b/test/rubygems/test_gem_security_trust_dir.rb @@ -56,7 +56,7 @@ def test_trust_cert assert_path_exist trusted - mask = 0100600 & (~File.umask) + mask = 0o100600 & (~File.umask) assert_equal mask, File.stat(trusted).mode unless Gem.win_platform? @@ -70,8 +70,8 @@ def test_verify assert_path_exist @dest_dir - mask = 040700 & (~File.umask) - mask |= 0200000 if RUBY_PLATFORM.include?("aix") + mask = 0o040700 & (~File.umask) + mask |= 0o200000 if RUBY_PLATFORM.include?("aix") assert_equal mask, File.stat(@dest_dir).mode unless Gem.win_platform? end @@ -87,12 +87,12 @@ def test_verify_file end def test_verify_wrong_permissions - FileUtils.mkdir_p @dest_dir, :mode => 0777 + FileUtils.mkdir_p @dest_dir, :mode => 0o777 @trust_dir.verify - mask = 040700 & (~File.umask) - mask |= 0200000 if RUBY_PLATFORM.include?("aix") + mask = 0o40700 & (~File.umask) + mask |= 0o200000 if RUBY_PLATFORM.include?("aix") assert_equal mask, File.stat(@dest_dir).mode unless Gem.win_platform? end diff --git a/test/rubygems/test_gem_spec_fetcher.rb b/test/rubygems/test_gem_spec_fetcher.rb index 7d5b7fc52f78c0..0fca9f0c48e965 100644 --- a/test/rubygems/test_gem_spec_fetcher.rb +++ b/test/rubygems/test_gem_spec_fetcher.rb @@ -41,12 +41,12 @@ def test_initialize_nonexistent_home_dir def test_initialize_unwritable_home_dir pend "chmod not supported" if Gem.win_platform? - FileUtils.chmod 0000, Gem.user_home + FileUtils.chmod 0o000, Gem.user_home begin assert Gem::SpecFetcher.new ensure - FileUtils.chmod 0755, Gem.user_home + FileUtils.chmod 0o755, Gem.user_home end end diff --git a/test/rubygems/test_gem_specification.rb b/test/rubygems/test_gem_specification.rb index fc2adb0eda07a3..e4e908c98fa504 100644 --- a/test/rubygems/test_gem_specification.rb +++ b/test/rubygems/test_gem_specification.rb @@ -1445,15 +1445,15 @@ def test_build_extensions_extensions_dir_unwritable end FileUtils.mkdir_p File.join @ext.base_dir, "extensions" - FileUtils.chmod 0555, @ext.base_dir - FileUtils.chmod 0555, File.join(@ext.base_dir, "extensions") + FileUtils.chmod 0o555, @ext.base_dir + FileUtils.chmod 0o555, File.join(@ext.base_dir, "extensions") @ext.build_extensions assert_path_not_exist @ext.extension_dir ensure unless $DEBUG || Gem.win_platform? || Process.uid.zero? || Gem.java_platform? - FileUtils.chmod 0755, File.join(@ext.base_dir, "extensions") - FileUtils.chmod 0755, @ext.base_dir + FileUtils.chmod 0o755, File.join(@ext.base_dir, "extensions") + FileUtils.chmod 0o755, @ext.base_dir end end @@ -1478,14 +1478,14 @@ def test_build_extensions_no_extensions_dir_unwritable end FileUtils.rm_r File.join @gemhome, "extensions" - FileUtils.chmod 0555, @gemhome + FileUtils.chmod 0o555, @gemhome @ext.build_extensions gem_make_out = File.join @ext.extension_dir, "gem_make.out" assert_path_not_exist gem_make_out ensure - FileUtils.chmod 0755, @gemhome + FileUtils.chmod 0o755, @gemhome end def test_build_extensions_none @@ -1593,12 +1593,12 @@ def test_date_equals_time_utc def test_date_tolerates_hour_sec_zulu @a1.date = "2012-01-12 11:22:33.4444444 Z" - assert_equal Time.utc(2012,01,12,0,0,0), @a1.date + assert_equal Time.utc(2012,1,12,0,0,0), @a1.date end def test_date_tolerates_hour_sec_and_timezone @a1.date = "2012-01-12 11:22:33.4444444 +02:33" - assert_equal Time.utc(2012,01,12,0,0,0), @a1.date + assert_equal Time.utc(2012,1,12,0,0,0), @a1.date end def test_date_use_env_source_date_epoch @@ -3317,8 +3317,8 @@ def test_validate_permissions util_setup_validate Dir.chdir @tempdir do - File.chmod 0640, File.join("lib", "code.rb") - File.chmod 0640, File.join("bin", "exec") + File.chmod 0o640, File.join("lib", "code.rb") + File.chmod 0o640, File.join("bin", "exec") use_ui @ui do @a1.validate @@ -3812,7 +3812,7 @@ def util_setup_validate FileUtils.touch File.join("lib", "code.rb") FileUtils.touch File.join("test", "suite.rb") - File.open "bin/exec", "w", 0755 do |fp| + File.open "bin/exec", "w", 0o755 do |fp| fp.puts "#!#{Gem.ruby}" end ensure diff --git a/test/rubygems/test_gem_util.rb b/test/rubygems/test_gem_util.rb index 7d5b9507277c3c..608210a9031eb0 100644 --- a/test/rubygems/test_gem_util.rb +++ b/test/rubygems/test_gem_util.rb @@ -41,7 +41,7 @@ def test_traverse_parents_does_not_crash_on_permissions_error FileUtils.mkdir_p "d/e/f" # remove 'execute' permission from "e" directory and make it # impossible to cd into it and its children - FileUtils.chmod(0666, "d/e") + FileUtils.chmod(0o666, "d/e") pend "skipped in root privilege" if Process.uid.zero? @@ -53,7 +53,7 @@ def test_traverse_parents_does_not_crash_on_permissions_error assert_equal File.realpath("../..", @tempdir), paths[3] ensure # restore default permissions, allow the directory to be removed - FileUtils.chmod(0775, "d/e") unless Gem.win_platform? || Gem.java_platform? + FileUtils.chmod(0o775, "d/e") unless Gem.win_platform? || Gem.java_platform? end def test_glob_files_in_dir