From 57968d656aee21c91fe19fe7ffaf292279a648f0 Mon Sep 17 00:00:00 2001 From: mwrock Date: Wed, 18 Nov 2020 11:14:51 -0800 Subject: [PATCH] fix broken windows tests Signed-off-by: mwrock --- .expeditor/verify.pipeline.yml | 1 + spec/mixlib/shellout_spec.rb | 19 ++++++++++--------- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/.expeditor/verify.pipeline.yml b/.expeditor/verify.pipeline.yml index ba3874ea..5a69b50d 100644 --- a/.expeditor/verify.pipeline.yml +++ b/.expeditor/verify.pipeline.yml @@ -52,3 +52,4 @@ steps: executor: docker: host_os: windows + user: 'NT AUTHORITY\SYSTEM' diff --git a/spec/mixlib/shellout_spec.rb b/spec/mixlib/shellout_spec.rb index 867644e6..dce47ddc 100644 --- a/spec/mixlib/shellout_spec.rb +++ b/spec/mixlib/shellout_spec.rb @@ -637,7 +637,12 @@ # to match how whoami returns the information it "should run as current user" do - expect(running_user).to eql("#{ENV["USERDOMAIN"].downcase}\\#{ENV["USERNAME"].downcase}") + if ENV["USERNAME"] == "#{ENV["COMPUTERNAME"]}$" + expected_user = "nt authority\\system" + else + expected_user = "#{ENV["USERDOMAIN"].downcase}\\#{ENV["USERNAME"].downcase}" + end + expect(running_user).to eql(expected_user) end end @@ -787,16 +792,12 @@ end context "when not using a batch file" do - let(:cmd) { "#{executable_file_name} #{script_name}" } - - let(:executable_file_name) { "\"#{dir}/Ruby Parser.exe\"".tap(&make_executable!) } - let(:make_executable!) { lambda { |filename| Mixlib::ShellOut.new("copy \"#{full_path_to_ruby}\" #{filename}").run_command } } - let(:script_content) { "print \"#{expected_output}\"" } + let(:cmd) { "#{executable_file_name} -command #{script_content}" } + let(:executable_file_name) { "\"#{dir}/Powershell Parser.exe\"".tap(&make_executable!) } + let(:make_executable!) { lambda { |filename| Mixlib::ShellOut.new("copy \"c:\\windows\\system32\\WindowsPowerShell\\v1.0\\powershell.exe\" #{filename}").run_command } } + let(:script_content) { "Write-Host \"#{expected_output}\"" } let(:expected_output) { "Random #{rand(10000)}" } - let(:full_path_to_ruby) { ENV["PATH"].split(";").map(&try_ruby).reject(&:nil?).first } - let(:try_ruby) { lambda { |path| "#{path}\\ruby.exe" if File.executable? "#{path}\\ruby.exe" } } - it "should execute" do is_expected.to eql(expected_output) end