diff options
author | Thom May <thom@chef.io> | 2016-07-05 15:22:32 +0100 |
---|---|---|
committer | Thom May <thom@chef.io> | 2016-07-07 15:23:41 +0100 |
commit | c54428b1928815b752de079cfe7df55a52b09775 (patch) | |
tree | 70dcf0b968f4c38b9845cc9409c00c310ba20f49 /spec/unit | |
parent | 8d88150bb10c40d725d8f0b297fc63763a95db07 (diff) | |
download | chef-c54428b1928815b752de079cfe7df55a52b09775.tar.gz |
Use Mixlib::Archive to extract tarballs
this allows us to be truely cross platform, and also to ignore unsafe
paths and permissions.
Signed-off-by: Thom May <thom@chef.io>
Diffstat (limited to 'spec/unit')
-rw-r--r-- | spec/unit/application/solo_spec.rb | 12 | ||||
-rw-r--r-- | spec/unit/knife/cookbook_site_install_spec.rb | 2 |
2 files changed, 8 insertions, 6 deletions
diff --git a/spec/unit/application/solo_spec.rb b/spec/unit/application/solo_spec.rb index b1931414cc..686ae745d8 100644 --- a/spec/unit/application/solo_spec.rb +++ b/spec/unit/application/solo_spec.rb @@ -120,9 +120,10 @@ Enable chef-client interval runs by setting `:client_fork = true` in your config expect(app).to receive(:open).with("http://junglist.gen.nz/recipes.tgz").and_yield(tarfile) expect(File).to receive(:open).with("#{Dir.tmpdir}/chef-solo/recipes.tgz", "wb").and_yield(target_file) - shellout = instance_double("Mixlib::ShellOut", run_command: nil, error!: nil, stdout: "") + archive = double(Mixlib::Archive) - expect(app).to receive(:shell_out!).with("tar zxvf #{Dir.tmpdir}/chef-solo/recipes.tgz -C #{Dir.tmpdir}/chef-solo").and_return(shellout) + expect(Mixlib::Archive).to receive(:new).with("#{Dir.tmpdir}/chef-solo/recipes.tgz").and_return(archive) + expect(archive).to receive(:extract).with("#{Dir.tmpdir}/chef-solo", { perms: false, ignore: /^\.$/ }) app.reconfigure expect(target_file.string).to eq("remote_tarball_content") end @@ -136,11 +137,10 @@ Enable chef-client interval runs by setting `:client_fork = true` in your config Chef::Config[:cookbook_path] = "#{Dir.tmpdir}/chef-solo/cookbooks" expect(FileUtils).to receive(:mkdir_p).with("#{Dir.tmpdir}/chef-solo").and_return(true) - allow(Chef::Mixin::Command).to receive(:run_command).and_return(true) + archive = double(Mixlib::Archive) - shellout = instance_double("Mixlib::ShellOut", run_command: nil, error!: nil, stdout: "") - - expect(app).to receive(:shell_out!).with("tar zxvf #{Dir.tmpdir}/chef-solo/recipes.tgz -C #{Dir.tmpdir}/chef-solo").and_return(shellout) + expect(Mixlib::Archive).to receive(:new).with("#{Dir.tmpdir}/chef-solo/recipes.tgz").and_return(archive) + expect(archive).to receive(:extract).with("#{Dir.tmpdir}/chef-solo", { perms: false, ignore: /^\.$/ }) expect(app).to receive(:fetch_recipe_tarball).ordered expect(Chef::ConfigFetcher).to receive(:new).ordered.and_return(config_fetcher) app.reconfigure diff --git a/spec/unit/knife/cookbook_site_install_spec.rb b/spec/unit/knife/cookbook_site_install_spec.rb index d60443d779..1549245ea3 100644 --- a/spec/unit/knife/cookbook_site_install_spec.rb +++ b/spec/unit/knife/cookbook_site_install_spec.rb @@ -23,6 +23,7 @@ describe Chef::Knife::CookbookSiteInstall do let(:stdout) { StringIO.new } let(:stderr) { StringIO.new } let(:downloader) { Hash.new } + let(:archive) { double(Mixlib::Archive, extract: true) } let(:repo) { double(:sanity_check => true, :reset_to_default_state => true, :prepare_to_import => true, :finalize_updates_to => true, :merge_updates_from => true) } @@ -48,6 +49,7 @@ describe Chef::Knife::CookbookSiteInstall do allow(File).to receive(:unlink) allow(File).to receive(:rmtree) allow(knife).to receive(:shell_out!).and_return(true) + allow(Mixlib::Archive).to receive(:new).and_return(archive) # CookbookSiteDownload Stup allow(knife).to receive(:download_cookbook_to).and_return(downloader) |