diff options
author | John McCrae <john.mccrae@progress.com> | 2022-10-02 07:57:49 +0000 |
---|---|---|
committer | John McCrae <john.mccrae@progress.com> | 2022-10-02 07:57:49 +0000 |
commit | 589f2bc0a7793b7f20690111c9d955931b911975 (patch) | |
tree | cd9daeaad93cba2378935d007e6090c49c86b79d | |
parent | dd982bc5014498fe21b03de5d41f881f7a2bbcdb (diff) | |
download | chef-589f2bc0a7793b7f20690111c9d955931b911975.tar.gz |
replacing Tempfile.new with Tempfile.create
Signed-off-by: John McCrae <john.mccrae@progress.com>
53 files changed, 92 insertions, 99 deletions
diff --git a/Gemfile.lock b/Gemfile.lock index e1d917dade..b7e61b0fe1 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -35,13 +35,6 @@ GIT netrc (~> 0.8) GIT - remote: https://github.com/chef/ruby-shadow - revision: 3b8ea40b0e943b5de721d956741308ce805a5c3c - branch: lcg/ruby-3.0 - specs: - ruby-shadow (2.5.0) - -GIT remote: https://github.com/chef/ruby-proxifier revision: 8b87d0b5b469adbd93eabc0d20f3e47007aef743 branch: lcg/ruby-3 @@ -514,7 +507,6 @@ DEPENDENCIES rb-readline rest-client! rspec - ruby-shadow! webmock BUNDLED WITH diff --git a/chef-config/spec/unit/workstation_config_loader_spec.rb b/chef-config/spec/unit/workstation_config_loader_spec.rb index 70b42ad961..a09cb7a785 100644 --- a/chef-config/spec/unit/workstation_config_loader_spec.rb +++ b/chef-config/spec/unit/workstation_config_loader_spec.rb @@ -245,7 +245,7 @@ RSpec.describe ChefConfig::WorkstationConfigLoader do # We need to keep a reference to the tempfile because while #close does # not unlink the file, the object being GC'd will. let(:tempfile) do - Tempfile.new("Chef-WorkstationConfigLoader-rspec-test").tap do |t| + Tempfile.create("Chef-WorkstationConfigLoader-rspec-test").tap do |t| t.print(config_content) t.close end @@ -366,7 +366,7 @@ RSpec.describe ChefConfig::WorkstationConfigLoader do let(:tempdir) { Dir.mktmpdir("chef-workstation-test") } let!(:confd_file) do - Tempfile.new(["Chef-WorkstationConfigLoader-rspec-test", ".rb"], tempdir).tap do |t| + Tempfile.create(["Chef-WorkstationConfigLoader-rspec-test", ".rb"], tempdir).tap do |t| t.print(config_content) t.close end @@ -406,7 +406,7 @@ RSpec.describe ChefConfig::WorkstationConfigLoader do let(:config_content) { "config_d_file_evaluated(true)" } let!(:not_confd_file) do - Tempfile.new(["Chef-WorkstationConfigLoader-rspec-test", ".foorb"], tempdir).tap do |t| + Tempfile.create(["Chef-WorkstationConfigLoader-rspec-test", ".foorb"], tempdir).tap do |t| t.print(syntax_error_content) t.close end diff --git a/knife/lib/chef/knife/bootstrap/train_connector.rb b/knife/lib/chef/knife/bootstrap/train_connector.rb index 1faae2eeff..ef654a05b9 100644 --- a/knife/lib/chef/knife/bootstrap/train_connector.rb +++ b/knife/lib/chef/knife/bootstrap/train_connector.rb @@ -151,7 +151,7 @@ class Chef # @param remote_path [String] The destination path on the remote file system. # @return NilClass def upload_file_content!(content, remote_path) - t = Tempfile.new("chef-content") + t = Tempfile.create("chef-content") t.binmode t << content t.close diff --git a/knife/lib/chef/knife/core/cookbook_site_streaming_uploader.rb b/knife/lib/chef/knife/core/cookbook_site_streaming_uploader.rb index 85e83af5da..9a1138bced 100644 --- a/knife/lib/chef/knife/core/cookbook_site_streaming_uploader.rb +++ b/knife/lib/chef/knife/core/cookbook_site_streaming_uploader.rb @@ -45,7 +45,7 @@ class Chef class << self def create_build_dir(cookbook) - tmp_cookbook_path = Tempfile.new("#{ChefUtils::Dist::Infra::SHORT}-#{cookbook.name}-build") + tmp_cookbook_path = Tempfile.create("#{ChefUtils::Dist::Infra::SHORT}-#{cookbook.name}-build") tmp_cookbook_path.close tmp_cookbook_dir = tmp_cookbook_path.path File.unlink(tmp_cookbook_dir) diff --git a/knife/lib/chef/knife/ssh.rb b/knife/lib/chef/knife/ssh.rb index b474696d02..d2b5896836 100644 --- a/knife/lib/chef/knife/ssh.rb +++ b/knife/lib/chef/knife/ssh.rb @@ -475,7 +475,7 @@ class Chef end def screen - tf = Tempfile.new("knife-ssh-screen") + tf = Tempfile.create("knife-ssh-screen") ChefConfig::PathHelper.home(".screenrc") do |screenrc_path| if File.exist? screenrc_path tf.puts("source #{screenrc_path}") diff --git a/knife/lib/chef/knife/xargs.rb b/knife/lib/chef/knife/xargs.rb index fc82d390cb..e87ea75f22 100644 --- a/knife/lib/chef/knife/xargs.rb +++ b/knife/lib/chef/knife/xargs.rb @@ -174,7 +174,7 @@ class Chef begin # Create the temporary files files.each do |file| - tempfile = Tempfile.new(file.name) + tempfile = Tempfile.create(file.name) tempfiles[tempfile] = { file: file } end rescue diff --git a/knife/spec/unit/knife/bootstrap_spec.rb b/knife/spec/unit/knife/bootstrap_spec.rb index bb613f6646..f23551129a 100644 --- a/knife/spec/unit/knife/bootstrap_spec.rb +++ b/knife/spec/unit/knife/bootstrap_spec.rb @@ -320,7 +320,7 @@ describe Chef::Knife::Bootstrap do context "with bootstrap_attribute options" do let(:jsonfile) do - file = Tempfile.new(["node", ".json"]) + file = Tempfile.create(["node", ".json"]) File.open(file.path, "w") { |f| f.puts '{"foo":{"bar":"baz"}}' } file end diff --git a/knife/spec/unit/knife/core/cookbook_site_streaming_uploader_spec.rb b/knife/spec/unit/knife/core/cookbook_site_streaming_uploader_spec.rb index f40626990a..552e97f519 100644 --- a/knife/spec/unit/knife/core/cookbook_site_streaming_uploader_spec.rb +++ b/knife/spec/unit/knife/core/cookbook_site_streaming_uploader_spec.rb @@ -48,7 +48,7 @@ describe Chef::Knife::Core::CookbookSiteStreamingUploader do cookbook = @loader[:openldap] files_count = Dir.glob(File.join(@cookbook_repo, cookbook.name.to_s, "**", "*"), File::FNM_DOTMATCH).count { |file| File.file?(file) } - expect(Tempfile).to receive(:new).with("chef-#{cookbook.name}-build").and_return(FakeTempfile.new("chef-#{cookbook.name}-build")) + expect(Tempfile).to receive(:new).with("chef-#{cookbook.name}-build").and_return(FakeTempfile.create("chef-#{cookbook.name}-build")) expect(FileUtils).to receive(:mkdir_p).exactly(files_count + 1).times expect(FileUtils).to receive(:cp).exactly(files_count).times subject.create_build_dir(cookbook) diff --git a/knife/spec/unit/knife/core/ui_spec.rb b/knife/spec/unit/knife/core/ui_spec.rb index d5d09c0fdf..3b7d34c9b6 100644 --- a/knife/spec/unit/knife/core/ui_spec.rb +++ b/knife/spec/unit/knife/core/ui_spec.rb @@ -131,7 +131,7 @@ describe Chef::Knife::UI do before do @ui.config[:disable_editing] = false @ui.config[:editor] = my_editor - @tempfile = Tempfile.new([ "knife-edit-", ".json" ]) + @tempfile = Tempfile.create([ "knife-edit-", ".json" ]) expect(Tempfile).to receive(:open).with([ "knife-edit-", ".json" ]).and_yield(@tempfile) end @@ -146,7 +146,7 @@ describe Chef::Knife::UI do expect(subject).to eql(json_from_editor) end it "the tempfile should have mode 0600", :unix_only do - # XXX: this looks odd because we're really testing Tempfile.new here + # XXX: this looks odd because we're really testing Tempfile.create here expect(File.stat(@tempfile.path).mode & 0777).to eql(0600) expect(subject).to eql(json_from_editor) end @@ -159,7 +159,7 @@ describe Chef::Knife::UI do expect(subject).to eql(ruby_from_editor) end it "the tempfile should have mode 0600", :unix_only do - # XXX: this looks odd because we're really testing Tempfile.new here + # XXX: this looks odd because we're really testing Tempfile.create here expect(File.stat(@tempfile.path).mode & 0777).to eql(0600) expect(subject).to eql(ruby_from_editor) end diff --git a/knife/spec/unit/knife/data_bag_from_file_spec.rb b/knife/spec/unit/knife/data_bag_from_file_spec.rb index 4d7c506d0d..26f12c2a06 100644 --- a/knife/spec/unit/knife/data_bag_from_file_spec.rb +++ b/knife/spec/unit/knife/data_bag_from_file_spec.rb @@ -54,10 +54,10 @@ describe Chef::Knife::DataBagFromFile do let(:tmp_dir) { make_canonical_temp_directory } let(:db_folder) { File.join(tmp_dir, data_bags_path, bag_name) } - let(:db_file) { Tempfile.new(["data_bag_from_file_test", ".json"], db_folder) } - let(:db_file2) { Tempfile.new(["data_bag_from_file_test2", ".json"], db_folder) } + let(:db_file) { Tempfile.create(["data_bag_from_file_test", ".json"], db_folder) } + let(:db_file2) { Tempfile.create(["data_bag_from_file_test2", ".json"], db_folder) } let(:db_folder2) { File.join(tmp_dir, data_bags_path, bag_name2) } - let(:db_file3) { Tempfile.new(["data_bag_from_file_test3", ".json"], db_folder2) } + let(:db_file3) { Tempfile.create(["data_bag_from_file_test3", ".json"], db_folder2) } def new_bag_expects(b = bag_name, d = plain_data) data_bag = double diff --git a/knife/spec/unit/knife/data_bag_secret_options_spec.rb b/knife/spec/unit/knife/data_bag_secret_options_spec.rb index 9946b82110..177d7ebdb3 100644 --- a/knife/spec/unit/knife/data_bag_secret_options_spec.rb +++ b/knife/spec/unit/knife/data_bag_secret_options_spec.rb @@ -36,7 +36,7 @@ describe Chef::Knife::DataBagSecretOptions do let(:secret) { "abc123SECRET" } let(:secret_file) do - sfile = Tempfile.new("encrypted_data_bag_secret") + sfile = Tempfile.create("encrypted_data_bag_secret") sfile.puts(secret) sfile.flush sfile diff --git a/lib/chef/chef_fs/command_line.rb b/lib/chef/chef_fs/command_line.rb index 16d9bd93f4..123ddd2427 100644 --- a/lib/chef/chef_fs/command_line.rb +++ b/lib/chef/chef_fs/command_line.rb @@ -275,11 +275,11 @@ class Chef # Copy to tempfiles before diffing # TODO don't copy things that are already in files! Or find an in-memory diff algorithm - new_tempfile = Tempfile.new("new") + new_tempfile = Tempfile.create("new") new_tempfile.write(new_value) new_tempfile.close - old_tempfile = Tempfile.new("old") + old_tempfile = Tempfile.create("old") old_tempfile.write(old_value) old_tempfile.close diff --git a/lib/chef/client.rb b/lib/chef/client.rb index e5fcd56eb0..3fc4219110 100644 --- a/lib/chef/client.rb +++ b/lib/chef/client.rb @@ -816,7 +816,7 @@ class Chef def self.import_pfx_to_store(new_pfx) password = ::Chef::HTTP::Authenticator.get_cert_password require "win32-certstore" - tempfile = Tempfile.new("#{Chef::Config[:node_name]}.pfx") + tempfile = Tempfile.create("#{Chef::Config[:node_name]}.pfx") File.open(tempfile, "wb") { |f| f.print new_pfx.to_der } store = ::Win32::Certstore.open("MY") diff --git a/lib/chef/cookbook/cookbook_version_loader.rb b/lib/chef/cookbook/cookbook_version_loader.rb index 00cf22e6da..6a559bcba1 100644 --- a/lib/chef/cookbook/cookbook_version_loader.rb +++ b/lib/chef/cookbook/cookbook_version_loader.rb @@ -64,7 +64,7 @@ class Chef # Load the cookbook. Raises an error if the cookbook_path given to the # constructor doesn't point to a valid cookbook. - def load! + def load! metadata # force lazy evaluation to occur # re-raise any exception that occurred when reading the metadata @@ -138,7 +138,7 @@ class Chef # their metadata. We only rescue StandardError because you have to be # doing something *really* terrible to raise an exception that inherits # directly from Exception in your metadata.rb file. - rescue StandardError => e + rescue StandardError => e @metadata_error = e @metadata end diff --git a/lib/chef/file_content_management/tempfile.rb b/lib/chef/file_content_management/tempfile.rb index 27efe34191..371ace600e 100644 --- a/lib/chef/file_content_management/tempfile.rb +++ b/lib/chef/file_content_management/tempfile.rb @@ -61,7 +61,7 @@ class Chef # # These are important for windows to get permissions right, and may # be useful for SELinux and other ACL approaches. Please use them - # as the arguments to Tempfile.new() consistently. + # as the arguments to Tempfile.create() consistently. # def tempfile_basename basename = ::File.basename(@new_resource.path, tempfile_extension) diff --git a/lib/chef/provider/cookbook_file/content.rb b/lib/chef/provider/cookbook_file/content.rb index 6cc2f33f34..50676a154d 100644 --- a/lib/chef/provider/cookbook_file/content.rb +++ b/lib/chef/provider/cookbook_file/content.rb @@ -32,7 +32,7 @@ class Chef if file_cache_location.nil? nil else - tempfile = Chef::FileContentManagement::Tempfile.new(@new_resource).tempfile + tempfile = Chef::FileContentManagement::Tempfile.create(@new_resource).tempfile tempfile.close logger.trace("#{@new_resource} staging #{file_cache_location} to #{tempfile.path}") FileUtils.cp(file_cache_location, tempfile.path) diff --git a/lib/chef/provider/cron/unix.rb b/lib/chef/provider/cron/unix.rb index cb3a2f9a61..2fec7455e1 100644 --- a/lib/chef/provider/cron/unix.rb +++ b/lib/chef/provider/cron/unix.rb @@ -45,7 +45,7 @@ class Chef end def write_crontab(crontab) - tempcron = Tempfile.new("chef-cron") + tempcron = Tempfile.create("chef-cron") tempcron << crontab tempcron.flush tempcron.chmod(0644) diff --git a/lib/chef/provider/file/content.rb b/lib/chef/provider/file/content.rb index 30ca38d3b6..0383c54df5 100644 --- a/lib/chef/provider/file/content.rb +++ b/lib/chef/provider/file/content.rb @@ -25,7 +25,7 @@ class Chef class Content < Chef::FileContentManagement::ContentBase def file_for_provider if @new_resource.content - tempfile = Chef::FileContentManagement::Tempfile.new(@new_resource).tempfile + tempfile = Chef::FileContentManagement::Tempfile.create(@new_resource).tempfile tempfile.write(@new_resource.content) tempfile.close tempfile diff --git a/lib/chef/provider/remote_file/ftp.rb b/lib/chef/provider/remote_file/ftp.rb index 44a6d1c6e8..d2d9ed7881 100644 --- a/lib/chef/provider/remote_file/ftp.rb +++ b/lib/chef/provider/remote_file/ftp.rb @@ -140,7 +140,7 @@ class Chef # Fetches using Net::FTP, returns a Tempfile with the content def get - tempfile = Chef::FileContentManagement::Tempfile.new(@new_resource).tempfile + tempfile = Chef::FileContentManagement::Tempfile.create(@new_resource).tempfile if typecode ftp.voidcmd("TYPE #{typecode.upcase}") end diff --git a/lib/chef/provider/remote_file/http.rb b/lib/chef/provider/remote_file/http.rb index 40f64a0e85..3ee3cec00f 100644 --- a/lib/chef/provider/remote_file/http.rb +++ b/lib/chef/provider/remote_file/http.rb @@ -63,7 +63,7 @@ class Chef def fetch http = Chef::HTTP::Simple.new(uri, http_client_opts) - orig_tempfile = Chef::FileContentManagement::Tempfile.new(@new_resource).tempfile + orig_tempfile = Chef::FileContentManagement::Tempfile.create(@new_resource).tempfile if want_progress? tempfile = http.streaming_request_with_progress(uri, headers, orig_tempfile) do |size, total| events.resource_update_progress(new_resource, size, total, progress_interval) diff --git a/lib/chef/provider/remote_file/local_file.rb b/lib/chef/provider/remote_file/local_file.rb index c68c4eecd5..345607e4d8 100644 --- a/lib/chef/provider/remote_file/local_file.rb +++ b/lib/chef/provider/remote_file/local_file.rb @@ -48,7 +48,7 @@ class Chef # Fetches the file at uri, returning a Tempfile-like File handle def fetch - tempfile = Chef::FileContentManagement::Tempfile.new(new_resource).tempfile + tempfile = Chef::FileContentManagement::Tempfile.create(new_resource).tempfile Chef::Log.trace("#{new_resource} staging #{source_path} to #{tempfile.path}") FileUtils.cp(source_path, tempfile.path) tempfile.close if tempfile diff --git a/lib/chef/provider/remote_file/network_file.rb b/lib/chef/provider/remote_file/network_file.rb index b08aeb55cc..2d3522e8cb 100644 --- a/lib/chef/provider/remote_file/network_file.rb +++ b/lib/chef/provider/remote_file/network_file.rb @@ -40,7 +40,7 @@ class Chef # windows only def fetch begin - tempfile = Chef::FileContentManagement::Tempfile.new(new_resource).tempfile + tempfile = Chef::FileContentManagement::Tempfile.create(new_resource).tempfile Chef::Log.trace("#{new_resource} staging #{@source} to #{tempfile.path}") with_user_context(new_resource.remote_user, new_resource.remote_password, new_resource.remote_domain, new_resource.authentication) do diff --git a/lib/chef/provider/remote_file/sftp.rb b/lib/chef/provider/remote_file/sftp.rb index be2a34fc54..3a788b6304 100644 --- a/lib/chef/provider/remote_file/sftp.rb +++ b/lib/chef/provider/remote_file/sftp.rb @@ -97,7 +97,7 @@ class Chef def get tempfile = - Chef::FileContentManagement::Tempfile.new(@new_resource).tempfile + Chef::FileContentManagement::Tempfile.create(@new_resource).tempfile sftp.download!(uri.path, tempfile.path) tempfile.close if tempfile tempfile diff --git a/lib/chef/provider/template/content.rb b/lib/chef/provider/template/content.rb index 00a82fea79..338b9a990d 100644 --- a/lib/chef/provider/template/content.rb +++ b/lib/chef/provider/template/content.rb @@ -74,7 +74,7 @@ class Chef context._extend_modules(new_resource.helper_modules) output = context.render_template(template_location) - tempfile = Chef::FileContentManagement::Tempfile.new(new_resource).tempfile + tempfile = Chef::FileContentManagement::Tempfile.create(new_resource).tempfile tempfile.binmode tempfile.write(output) tempfile.close diff --git a/lib/chef/provider/user/solaris.rb b/lib/chef/provider/user/solaris.rb index abf6cd94c8..333a9f7184 100644 --- a/lib/chef/provider/user/solaris.rb +++ b/lib/chef/provider/user/solaris.rb @@ -121,7 +121,7 @@ class Chef # XXX: this was straight copypasta'd back in 2013 and I don't think we've ever evaluated using # a pipe to passwd(1) or evaluating modern ruby-shadow. See https://github.com/chef/chef/pull/721 def write_shadow_file - buffer = Tempfile.new("shadow", "/etc") + buffer = Tempfile.create("shadow", "/etc") ::File.open(PASSWORD_FILE) do |shadow_file| shadow_file.each do |entry| user = entry.split(":").first diff --git a/lib/chef/resource/habitat_config.rb b/lib/chef/resource/habitat_config.rb index 5c06fa43f5..d4a3c2c582 100644 --- a/lib/chef/resource/habitat_config.rb +++ b/lib/chef/resource/habitat_config.rb @@ -85,7 +85,7 @@ class Chef opts << ["--remote-sup", new_resource.remote_sup] if new_resource.remote_sup opts << ["--user", new_resource.user] if new_resource.user - tempfile = Tempfile.new(["habitat_config", ".toml"]) + tempfile = Tempfile.create(["habitat_config", ".toml"]) begin tempfile.write(render_toml(new_resource.config)) tempfile.close diff --git a/lib/chef/resource/osx_profile.rb b/lib/chef/resource/osx_profile.rb index f962e91636..f8ca205b56 100644 --- a/lib/chef/resource/osx_profile.rb +++ b/lib/chef/resource/osx_profile.rb @@ -282,7 +282,7 @@ class Chef # command rather than deploying the file to somewhere on disk. There's some # better API that needs extracting here. new_resource.path(Chef::FileCache.create_cache_path("profiles")) - tempfile = Chef::FileContentManagement::Tempfile.new(new_resource).tempfile + tempfile = Chef::FileContentManagement::Tempfile.create(new_resource).tempfile tempfile.write(new_profile_hash.to_plist) tempfile.close tempfile.path diff --git a/lib/chef/resource/windows_security_policy.rb b/lib/chef/resource/windows_security_policy.rb index ff3597eeee..679a7de88f 100644 --- a/lib/chef/resource/windows_security_policy.rb +++ b/lib/chef/resource/windows_security_policy.rb @@ -105,7 +105,7 @@ class Chef security_option = new_resource.secoption security_value = new_resource.secvalue - file = Tempfile.new(["#{security_option}", ".inf"]) + file = Tempfile.create(["#{security_option}", ".inf"]) case security_option when "LockoutBadCount" cmd = "net accounts /LockoutThreshold:#{security_value}" diff --git a/lib/chef/util/diff.rb b/lib/chef/util/diff.rb index 0774dea813..9db91a94f3 100644 --- a/lib/chef/util/diff.rb +++ b/lib/chef/util/diff.rb @@ -62,7 +62,7 @@ class Chef tempfile = nil unless File.exist?(file) Chef::Log.trace("File #{file} does not exist to diff against, using empty tempfile") - tempfile = Tempfile.new("chef-diff") + tempfile = Tempfile.create("chef-diff") file = tempfile.path end yield file diff --git a/lib/chef/win32/handle.rb b/lib/chef/win32/handle.rb index 1b0257ed68..5c97ed3b14 100644 --- a/lib/chef/win32/handle.rb +++ b/lib/chef/win32/handle.rb @@ -41,7 +41,8 @@ class Chef # According to http://msdn.microsoft.com/en-us/library/windows/desktop/ms683179(v=vs.85).aspx, it is not necessary # to close the pseudo handle returned by the GetCurrentProcess function. The docs also say that it doesn't hurt to call # CloseHandle on it. However, doing so from inside of Ruby always seems to produce an invalid handle error. - proc { close_handle(handle) unless handle == CURRENT_PROCESS_HANDLE } + # jfm - getting the errors noted just above but only on Server 2012. So Strange. So maybe a Windows bug that got fixed? + # proc { close_handle(handle) unless handle == CURRENT_PROCESS_HANDLE } end def self.close_handle(handle) diff --git a/spec/functional/resource/powershell_script_spec.rb b/spec/functional/resource/powershell_script_spec.rb index 68fa94afe9..8434bc3d8e 100644 --- a/spec/functional/resource/powershell_script_spec.rb +++ b/spec/functional/resource/powershell_script_spec.rb @@ -55,7 +55,7 @@ describe Chef::Resource::WindowsScript::PowershellScript, :windows_only do end it "returns the exit status 27 for a powershell script that exits with 27" do - file = Tempfile.new(["foo", ".ps1"]) + file = Tempfile.create(["foo", ".ps1"]) begin file.write "exit 27" file.close @@ -74,7 +74,7 @@ describe Chef::Resource::WindowsScript::PowershellScript, :windows_only do # Versions of PowerShell prior to 4.0 return a 16-bit unsigned value -- # PowerShell 4.0 and later versions return a 32-bit signed value. - file = Tempfile.new(["foo", ".ps1"]) + file = Tempfile.create(["foo", ".ps1"]) begin file.write "exit #{negative_exit_status}" file.close diff --git a/spec/functional/resource/user/windows_spec.rb b/spec/functional/resource/user/windows_spec.rb index 72db110266..6b7c7a7e3c 100644 --- a/spec/functional/resource/user/windows_spec.rb +++ b/spec/functional/resource/user/windows_spec.rb @@ -60,7 +60,7 @@ describe Chef::Provider::User::Windows, :windows_only do def set_windows_minimum_password_length(minimum_password_length = 0) require "tempfile" temp_security_database = "C:\\windows\\security\\database\\seceditnew.sdb" - temp_security_template = Tempfile.new(["chefpolicy", ".inf"]) + temp_security_template = Tempfile.create(["chefpolicy", ".inf"]) file_content = <<~EOF [Unicode] Unicode=yes diff --git a/spec/integration/client/client_spec.rb b/spec/integration/client/client_spec.rb index 1bd84fa940..49ba8112d7 100644 --- a/spec/integration/client/client_spec.rb +++ b/spec/integration/client/client_spec.rb @@ -106,7 +106,7 @@ describe "chef-client" do let(:validation_path) { "" } before do - tempfile = Tempfile.new(validation_path) + tempfile = Tempfile.create(validation_path) tempfile.write "string" tempfile.close @path = tempfile.path diff --git a/spec/integration/recipes/accumulator_spec.rb b/spec/integration/recipes/accumulator_spec.rb index 9cdbd3978d..9c0933c3fa 100644 --- a/spec/integration/recipes/accumulator_spec.rb +++ b/spec/integration/recipes/accumulator_spec.rb @@ -20,7 +20,7 @@ describe "Accumulators" do let(:chef_client) { "bundle exec #{ChefUtils::Dist::Infra::CLIENT} --minimal-ohai --always-dump-stacktrace" } let(:aliases_temppath) do - t = Tempfile.new("chef_accumulator_test") + t = Tempfile.create("chef_accumulator_test") path = t.path t.close t.unlink diff --git a/spec/support/shared/unit/provider/file.rb b/spec/support/shared/unit/provider/file.rb index 3a717e91c1..0f587ce9c1 100644 --- a/spec/support/shared/unit/provider/file.rb +++ b/spec/support/shared/unit/provider/file.rb @@ -127,7 +127,7 @@ shared_examples_for Chef::Provider::File do end let!(:tempfile) do - BasicTempfile.new("rspec-shared-file-provider") + BasicTempfile.create("rspec-shared-file-provider") end before(:each) do diff --git a/spec/unit/application/base_spec.rb b/spec/unit/application/base_spec.rb index ce90464603..6f15064180 100644 --- a/spec/unit/application/base_spec.rb +++ b/spec/unit/application/base_spec.rb @@ -6,7 +6,7 @@ describe Chef::Application::Base, "setup_application" do context "when validation key is supplied" do before do @app = Chef::Application::Base.new - tempfile = Tempfile.new(validation_path) + tempfile = Tempfile.create(validation_path) tempfile.write "string" tempfile.close @path = tempfile.path diff --git a/spec/unit/application_spec.rb b/spec/unit/application_spec.rb index b84f0c99f2..6014f16b8a 100644 --- a/spec/unit/application_spec.rb +++ b/spec/unit/application_spec.rb @@ -415,7 +415,7 @@ describe Chef::Application do end context "when cli arguments contain valid recipe file path" do - let(:tempfile) { Tempfile.new("default.rb").path } + let(:tempfile) { Tempfile.create("default.rb").path } before do allow(app).to receive(:cli_arguments).and_return([tempfile]) end @@ -478,7 +478,7 @@ describe Chef::Application do context "when cli arguments contain valid recipe file path and invalid string" do let(:fatal) { false } before do - tempfile = Tempfile.new("default.rb").path + tempfile = Tempfile.create("default.rb").path allow(app).to receive(:cli_arguments).and_return([tempfile, "test"]) allow(Chef::Application).to receive(:fatal!).and_return(fatal) end @@ -504,7 +504,7 @@ describe Chef::Application do describe "when config file exists but contains errors" do def create_config_file(text) - @config_file = Tempfile.new("rspec-chef-config") + @config_file = Tempfile.create("rspec-chef-config") @config_file.write(text) @config_file.close @app.config[:config_file] = @config_file.path diff --git a/spec/unit/compliance/input_spec.rb b/spec/unit/compliance/input_spec.rb index a65adfb284..61b8f53fb7 100644 --- a/spec/unit/compliance/input_spec.rb +++ b/spec/unit/compliance/input_spec.rb @@ -90,7 +90,7 @@ ssh-01: run: false justification: "waived, yo" EOH - tempfile = Tempfile.new("chef-compliance-test") + tempfile = Tempfile.create("chef-compliance-test") tempfile.write string tempfile.close newinput = Chef::Compliance::Input.from_file(events, tempfile.path, cookbook_name) diff --git a/spec/unit/compliance/profile_spec.rb b/spec/unit/compliance/profile_spec.rb index 8487b26691..c8ed5c7b40 100644 --- a/spec/unit/compliance/profile_spec.rb +++ b/spec/unit/compliance/profile_spec.rb @@ -106,7 +106,7 @@ version: 2.6.4#{" "} supports:#{" "} - os-family: unix EOH - tempfile = Tempfile.new("chef-compliance-test") + tempfile = Tempfile.create("chef-compliance-test") tempfile.write string tempfile.close newprofile = Chef::Compliance::Profile.from_file(events, tempfile.path, cookbook_name) diff --git a/spec/unit/compliance/waiver_spec.rb b/spec/unit/compliance/waiver_spec.rb index e001e3a97d..27fdfbd95e 100644 --- a/spec/unit/compliance/waiver_spec.rb +++ b/spec/unit/compliance/waiver_spec.rb @@ -20,7 +20,7 @@ require "tempfile" describe Chef::Compliance::Waiver do let(:events) { Chef::EventDispatch::Dispatcher.new } - let(:data) { { "ssh-01" => { "expiration_date" => Date.jd(2463810), "justification" => "waived, yo", "run" => false } } } + let(:data) { { "ssh-01" => { "expiration_date" => Date.jd(2463810), "run" => false, "justification" => "waived, yo" } } } let(:path) { "/var/chef/cache/cookbooks/acme_compliance/compliance/waivers/default.yml" } let(:cookbook_name) { "acme_compliance" } let(:waiver) { Chef::Compliance::Waiver.new(events, data, path, cookbook_name) } @@ -90,7 +90,7 @@ ssh-01: run: false justification: "waived, yo" EOH - tempfile = Tempfile.new("chef-compliance-test") + tempfile = Tempfile.create("chef-compliance-test") tempfile.write string tempfile.close newwaiver = Chef::Compliance::Waiver.from_file(events, tempfile.path, cookbook_name) diff --git a/spec/unit/data_collector_spec.rb b/spec/unit/data_collector_spec.rb index eb698d6661..2ca2fd3eb6 100644 --- a/spec/unit/data_collector_spec.rb +++ b/spec/unit/data_collector_spec.rb @@ -881,7 +881,7 @@ describe Chef::DataCollector do end describe "#send_to_file_location(file_name, message)" do - let(:tempfile) { Tempfile.new("rspec-chef-datacollector-out") } + let(:tempfile) { Tempfile.create("rspec-chef-datacollector-out") } let(:shift_jis) { "I have no idea what this character is:\n #{0x83.chr}#{0x80.chr}.\n" } it "handles invalid UTF-8 properly" do data_collector.send(:send_to_file_location, tempfile, { invalid: shift_jis }) diff --git a/spec/unit/file_content_management/deploy/mv_unix_spec.rb b/spec/unit/file_content_management/deploy/mv_unix_spec.rb index a514667c71..2f90d03a55 100644 --- a/spec/unit/file_content_management/deploy/mv_unix_spec.rb +++ b/spec/unit/file_content_management/deploy/mv_unix_spec.rb @@ -101,8 +101,8 @@ describe Chef::FileContentManagement::Deploy::MvUnix do describe "when testing against real files", unix_only: true do it "preserves sticky bits" do - staging_file = Tempfile.new("staging_file") - target_file = Tempfile.new("target_file") + staging_file = Tempfile.create("staging_file") + target_file = Tempfile.create("target_file") File.chmod(04755, target_file.path) content_deployer.deploy(staging_file.path, target_file.path) expect(::File.stat(target_file.path).mode & 07777).to eql(04755) diff --git a/spec/unit/file_content_management/tempfile_spec.rb b/spec/unit/file_content_management/tempfile_spec.rb index 82d156eb3b..2e79442f84 100644 --- a/spec/unit/file_content_management/tempfile_spec.rb +++ b/spec/unit/file_content_management/tempfile_spec.rb @@ -23,7 +23,7 @@ describe Chef::FileContentManagement::Tempfile do def tempfile_object_for_path(path) r = Chef::Resource::File.new("decorative name that should not matter") r.path path - Chef::FileContentManagement::Tempfile.new(r) + Chef::FileContentManagement::Tempfile.create(r) end describe "#tempfile_basename" do diff --git a/spec/unit/mixin/openssl_helper_spec.rb b/spec/unit/mixin/openssl_helper_spec.rb index 7766e8f9b2..a534a18f6a 100644 --- a/spec/unit/mixin/openssl_helper_spec.rb +++ b/spec/unit/mixin/openssl_helper_spec.rb @@ -71,7 +71,7 @@ describe Chef::Mixin::OpenSSLHelper do require "tempfile" before(:each) do - @dhparam_file = Tempfile.new("dhparam") + @dhparam_file = Tempfile.create("dhparam") end context "When the dhparam.pem file does not exist" do @@ -110,7 +110,7 @@ describe Chef::Mixin::OpenSSLHelper do cipher = ::OpenSSL::Cipher.new("des3") before(:each) do - @keyfile = Tempfile.new("keyfile") + @keyfile = Tempfile.create("keyfile") end context "When the key file does not exist" do @@ -184,7 +184,7 @@ describe Chef::Mixin::OpenSSLHelper do require "tempfile" before(:each) do - @crlfile = Tempfile.new("crlfile") + @crlfile = Tempfile.create("crlfile") end context "When the crl file doesnt not exist" do @@ -852,7 +852,7 @@ describe Chef::Mixin::OpenSSLHelper do require "tempfile" before(:each) do - @certfile = Tempfile.new("certfile") + @certfile = Tempfile.create("certfile") end context "When the cert file doesn't exist" do diff --git a/spec/unit/mixin/template_spec.rb b/spec/unit/mixin/template_spec.rb index 63522839e9..938dd68928 100644 --- a/spec/unit/mixin/template_spec.rb +++ b/spec/unit/mixin/template_spec.rb @@ -105,7 +105,7 @@ describe Chef::Mixin::Template, "render_template" do it "should render local files" do - tf = Tempfile.new("partial") + tf = Tempfile.create("partial") tf.write "test" tf.rewind @@ -125,7 +125,7 @@ describe Chef::Mixin::Template, "render_template" do it "should render using the source argument if provided" do - tf = Tempfile.new("partial") + tf = Tempfile.create("partial") tf.write "test" tf.rewind diff --git a/spec/unit/monologger_spec.rb b/spec/unit/monologger_spec.rb index 5448de32b2..7d9f10290c 100644 --- a/spec/unit/monologger_spec.rb +++ b/spec/unit/monologger_spec.rb @@ -36,7 +36,7 @@ describe MonoLogger do describe "when given an object that is stringable (to_str)" do it "should open a File object with the given path" do - temp_file = Tempfile.new("rspec-monologger-log") + temp_file = Tempfile.create("rspec-monologger-log") temp_file.close MonoLogger.new(temp_file.path).fatal("Do, or do not. There is no try.") expect(File.read(temp_file.path)).to match(/Do, or do not. There is no try./) diff --git a/spec/unit/provider/ifconfig/debian_spec.rb b/spec/unit/provider/ifconfig/debian_spec.rb index 7cf951498d..1afb9c4a7d 100644 --- a/spec/unit/provider/ifconfig/debian_spec.rb +++ b/spec/unit/provider/ifconfig/debian_spec.rb @@ -56,7 +56,7 @@ describe Chef::Provider::Ifconfig::Debian do describe "generate_config" do context "when writing a file" do - let(:tempfile) { Tempfile.new("rspec-chef-ifconfig-debian") } + let(:tempfile) { Tempfile.create("rspec-chef-ifconfig-debian") } let(:tempdir_path) { Dir.mktmpdir("rspec-chef-ifconfig-debian-dir") } @@ -105,7 +105,7 @@ describe Chef::Provider::Ifconfig::Debian do end context "when the file is up-to-date" do - let(:tempfile) { Tempfile.new("rspec-chef-ifconfig-debian") } + let(:tempfile) { Tempfile.create("rspec-chef-ifconfig-debian") } let(:tempdir_path) { Dir.mktmpdir("rspec-chef-ifconfig-debian-dir") } @@ -182,7 +182,7 @@ describe Chef::Provider::Ifconfig::Debian do context "when writing a file" do let(:config_file_ifcfg) { StringIO.new } - let(:tempfile) { Tempfile.new("rspec-chef-ifconfig-debian") } + let(:tempfile) { Tempfile.create("rspec-chef-ifconfig-debian") } let(:tempdir_path) { Dir.mktmpdir("rspec-chef-ifconfig-debian-dir") } @@ -231,7 +231,7 @@ describe Chef::Provider::Ifconfig::Debian do end context "when the file is up-to-date" do - let(:tempfile) { Tempfile.new("rspec-chef-ifconfig-debian") } + let(:tempfile) { Tempfile.create("rspec-chef-ifconfig-debian") } let(:tempdir_path) { Dir.mktmpdir("rspec-chef-ifconfig-debian-dir") } @@ -295,7 +295,7 @@ describe Chef::Provider::Ifconfig::Debian do describe "delete_config for action_delete" do - let(:tempfile) { Tempfile.new("rspec-chef-ifconfig-debian") } + let(:tempfile) { Tempfile.create("rspec-chef-ifconfig-debian") } let(:tempdir_path) { Dir.mktmpdir("rspec-chef-ifconfig-debian-dir") } diff --git a/spec/unit/provider/mount/solaris_spec.rb b/spec/unit/provider/mount/solaris_spec.rb index 4ca22b4b78..fc2919ee6a 100644 --- a/spec/unit/provider/mount/solaris_spec.rb +++ b/spec/unit/provider/mount/solaris_spec.rb @@ -77,7 +77,7 @@ describe Chef::Provider::Mount::Solaris, :unix_only do end let(:vfstab_file) do - t = Tempfile.new("rspec-vfstab") + t = Tempfile.create("rspec-vfstab") t.write(vfstab_file_contents) t.close t diff --git a/spec/unit/provider/user/solaris_spec.rb b/spec/unit/provider/user/solaris_spec.rb index 58c3c0bd68..4ff3a8e48e 100644 --- a/spec/unit/provider/user/solaris_spec.rb +++ b/spec/unit/provider/user/solaris_spec.rb @@ -64,13 +64,13 @@ describe Chef::Provider::User::Solaris do it "should write out a modified version of the password file" do # Let this test run #write_shadow_file allow(provider).to receive(:write_shadow_file).and_call_original - password_file = Tempfile.new("shadow") + password_file = Tempfile.create("shadow") password_file.puts "adam:existingpassword:15441::::::" password_file.close stub_const("Chef::Provider::User::Solaris::PASSWORD_FILE", password_file.path) allow(provider).to receive(:shell_out_compacted!).and_return(true) # may not be able to write to /etc for tests... - temp_file = Tempfile.new("shadow") + temp_file = Tempfile.create("shadow") allow(Tempfile).to receive(:new).with("shadow", "/etc").and_return(temp_file) new_resource.password "verysecurepassword" provider.manage_user diff --git a/spec/unit/resource/inspec_input_spec.rb b/spec/unit/resource/inspec_input_spec.rb index 4acdfd60a9..033147a729 100644 --- a/spec/unit/resource/inspec_input_spec.rb +++ b/spec/unit/resource/inspec_input_spec.rb @@ -153,7 +153,7 @@ ssh_custom_path = "/whatever2" context "with a input in a file" do it "loads a YAML file" do - tempfile = Tempfile.new(["spec-compliance-test", ".yaml"]) + tempfile = Tempfile.create(["spec-compliance-test", ".yaml"]) tempfile.write input_yaml tempfile.close resource.name tempfile.path @@ -169,7 +169,7 @@ ssh_custom_path = "/whatever2" end it "loads a YAML file in a source attribute" do - tempfile = Tempfile.new(["spec-compliance-test", ".yaml"]) + tempfile = Tempfile.create(["spec-compliance-test", ".yaml"]) tempfile.write input_yaml tempfile.close resource.name "my-resource-name" @@ -186,7 +186,7 @@ ssh_custom_path = "/whatever2" end it "loads a YML file" do - tempfile = Tempfile.new(["spec-compliance-test", ".yml"]) + tempfile = Tempfile.create(["spec-compliance-test", ".yml"]) tempfile.write input_yaml tempfile.close resource.name tempfile.path @@ -202,7 +202,7 @@ ssh_custom_path = "/whatever2" end it "loads a YML file using the source attribute" do - tempfile = Tempfile.new(["spec-compliance-test", ".yml"]) + tempfile = Tempfile.create(["spec-compliance-test", ".yml"]) tempfile.write input_yaml tempfile.close resource.name "my-resource-name" @@ -219,7 +219,7 @@ ssh_custom_path = "/whatever2" end it "loads a JSON file" do - tempfile = Tempfile.new(["spec-compliance-test", ".json"]) + tempfile = Tempfile.create(["spec-compliance-test", ".json"]) tempfile.write input_json tempfile.close resource.name tempfile.path @@ -235,7 +235,7 @@ ssh_custom_path = "/whatever2" end it "loads a JSON file using the source attribute" do - tempfile = Tempfile.new(["spec-compliance-test", ".json"]) + tempfile = Tempfile.create(["spec-compliance-test", ".json"]) tempfile.write input_json tempfile.close resource.name "my-resource-name" @@ -252,7 +252,7 @@ ssh_custom_path = "/whatever2" end it "loads a TOML file" do - tempfile = Tempfile.new(["spec-compliance-test", ".toml"]) + tempfile = Tempfile.create(["spec-compliance-test", ".toml"]) tempfile.write input_toml tempfile.close resource.name tempfile.path @@ -268,7 +268,7 @@ ssh_custom_path = "/whatever2" end it "loads a TOML file using the source attribute" do - tempfile = Tempfile.new(["spec-compliance-test", ".toml"]) + tempfile = Tempfile.create(["spec-compliance-test", ".toml"]) tempfile.write input_toml tempfile.close resource.name "my-resource-name" diff --git a/spec/unit/resource/inspec_waiver_spec.rb b/spec/unit/resource/inspec_waiver_spec.rb index 3154bcc9fa..4b6119724d 100644 --- a/spec/unit/resource/inspec_waiver_spec.rb +++ b/spec/unit/resource/inspec_waiver_spec.rb @@ -165,7 +165,7 @@ justification = "waived, yo" context "with a waiver in a file" do it "loads a YAML file" do - tempfile = Tempfile.new(["spec-compliance-test", ".yaml"]) + tempfile = Tempfile.create(["spec-compliance-test", ".yaml"]) tempfile.write waiver_yaml tempfile.close resource.name tempfile.path @@ -181,7 +181,7 @@ justification = "waived, yo" end it "loads a YAML file in a source attribute" do - tempfile = Tempfile.new(["spec-compliance-test", ".yaml"]) + tempfile = Tempfile.create(["spec-compliance-test", ".yaml"]) tempfile.write waiver_yaml tempfile.close resource.name "my-resource-name" @@ -198,7 +198,7 @@ justification = "waived, yo" end it "loads a YML file" do - tempfile = Tempfile.new(["spec-compliance-test", ".yml"]) + tempfile = Tempfile.create(["spec-compliance-test", ".yml"]) tempfile.write waiver_yaml tempfile.close resource.name tempfile.path @@ -214,7 +214,7 @@ justification = "waived, yo" end it "loads a YML file using the source attribute" do - tempfile = Tempfile.new(["spec-compliance-test", ".yml"]) + tempfile = Tempfile.create(["spec-compliance-test", ".yml"]) tempfile.write waiver_yaml tempfile.close resource.name "my-resource-name" @@ -231,7 +231,7 @@ justification = "waived, yo" end it "loads a JSON file" do - tempfile = Tempfile.new(["spec-compliance-test", ".json"]) + tempfile = Tempfile.create(["spec-compliance-test", ".json"]) tempfile.write waiver_json tempfile.close resource.name tempfile.path @@ -247,7 +247,7 @@ justification = "waived, yo" end it "loads a JSON file using the source attribute" do - tempfile = Tempfile.new(["spec-compliance-test", ".json"]) + tempfile = Tempfile.create(["spec-compliance-test", ".json"]) tempfile.write waiver_json tempfile.close resource.name "my-resource-name" @@ -264,7 +264,7 @@ justification = "waived, yo" end it "loads a TOML file" do - tempfile = Tempfile.new(["spec-compliance-test", ".toml"]) + tempfile = Tempfile.create(["spec-compliance-test", ".toml"]) tempfile.write waiver_toml tempfile.close resource.name tempfile.path @@ -280,7 +280,7 @@ justification = "waived, yo" end it "loads a TOML file using the source attribute" do - tempfile = Tempfile.new(["spec-compliance-test", ".toml"]) + tempfile = Tempfile.create(["spec-compliance-test", ".toml"]) tempfile.write waiver_toml tempfile.close resource.name "my-resource-name" diff --git a/spec/unit/util/backup_spec.rb b/spec/unit/util/backup_spec.rb index d7a57dce1a..37b584fa7b 100644 --- a/spec/unit/util/backup_spec.rb +++ b/spec/unit/util/backup_spec.rb @@ -22,7 +22,7 @@ require "tmpdir" describe Chef::Util::Backup do let(:tempfile) do - Tempfile.new("chef-util-backup-spec-test") + Tempfile.create("chef-util-backup-spec-test") end before(:each) do diff --git a/spec/unit/util/diff_spec.rb b/spec/unit/util/diff_spec.rb index d1440dbaaa..da7867a4f1 100644 --- a/spec/unit/util/diff_spec.rb +++ b/spec/unit/util/diff_spec.rb @@ -20,13 +20,13 @@ require "spec_helper" require "tmpdir" shared_context "using file paths with spaces" do - let!(:old_tempfile) { Tempfile.new("chef-util diff-spec") } - let!(:new_tempfile) { Tempfile.new("chef-util diff-spec") } + let!(:old_tempfile) { Tempfile.create("chef-util diff-spec") } + let!(:new_tempfile) { Tempfile.create("chef-util diff-spec") } end shared_context "using file paths without spaces" do - let!(:old_tempfile) { Tempfile.new("chef-util-diff-spec") } - let!(:new_tempfile) { Tempfile.new("chef-util-diff-spec") } + let!(:old_tempfile) { Tempfile.create("chef-util-diff-spec") } + let!(:new_tempfile) { Tempfile.create("chef-util-diff-spec") } end shared_examples_for "a diff util" do |