summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKapil Chouhan <kapil.chouhan@msystechnologies.com>2020-09-09 10:32:56 +0000
committerKapil Chouhan <kapil.chouhan@msystechnologies.com>2020-09-09 12:56:04 +0000
commit1cd71f5ca3e84f307bd01e6624819976436e32be (patch)
treeab122336435969759a7acf6cbd141297521812c1
parent7ca0b99b56022ec04ef4a8f61fc7702ffaa8a765 (diff)
downloadmixlib-shellout-1cd71f5ca3e84f307bd01e6624819976436e32be.tar.gz
Added Dependency of ffi-win31-extensions gem and added test cases
Signed-off-by: Kapil Chouhan <kapil.chouhan@msystechnologies.com>
-rw-r--r--lib/mixlib/shellout/windows/core_ext.rb1
-rw-r--r--mixlib-shellout-universal-mingw32.gemspec1
-rw-r--r--spec/mixlib/shellout_spec.rb15
3 files changed, 17 insertions, 0 deletions
diff --git a/lib/mixlib/shellout/windows/core_ext.rb b/lib/mixlib/shellout/windows/core_ext.rb
index 9004cc3..54bbce6 100644
--- a/lib/mixlib/shellout/windows/core_ext.rb
+++ b/lib/mixlib/shellout/windows/core_ext.rb
@@ -18,6 +18,7 @@
#
require "win32/process"
+require "ffi/win32/extensions"
# Add new constants for Logon
module Process::Constants
diff --git a/mixlib-shellout-universal-mingw32.gemspec b/mixlib-shellout-universal-mingw32.gemspec
index 3a3968d..91b082b 100644
--- a/mixlib-shellout-universal-mingw32.gemspec
+++ b/mixlib-shellout-universal-mingw32.gemspec
@@ -4,5 +4,6 @@ gemspec.platform = Gem::Platform.new(%w{universal mingw32})
gemspec.add_dependency "win32-process", "~> 0.8.2"
gemspec.add_dependency "wmi-lite", "~> 1.0"
+gemspec.add_dependency "ffi-win32-extensions", "~> 1.0.3"
gemspec
diff --git a/spec/mixlib/shellout_spec.rb b/spec/mixlib/shellout_spec.rb
index 0d444a3..7f52084 100644
--- a/spec/mixlib/shellout_spec.rb
+++ b/spec/mixlib/shellout_spec.rb
@@ -658,6 +658,21 @@ describe Mixlib::ShellOut do
expect(running_user).to eql("#{ENV["COMPUTERNAME"].downcase}\\#{user}")
end
+ context "when an alternate user is passed" do
+ let(:env_list) { ["ALLUSERSPROFILE=C:\\ProgramData", "TEMP=C:\\Windows\\TEMP", "TMP=C:\\Windows\\TEMP", "USERDOMAIN=WIN-G06ENRTTKF9", "USERNAME=testuser", "USERPROFILE=C:\\Users\\Default", "windir=C:\\Windows"] }
+ let(:current_env) { ["ALLUSERSPROFILE=C:\\ProgramData", "TEMP=C:\\Users\\ADMINI~1\\AppData\\Local\\Temp\\2", "TMP=C:\\Users\\ADMINI~1\\AppData\\Local\\Temp\\2", "USER=Administrator", "USERDOMAIN=WIN-G06ENRTTKF9", "USERDOMAIN_ROAMINGPROFILE=WIN-G06ENRTTKF9", "USERNAME=Administrator", "USERPROFILE=C:\\Users\\Administrator", "windir=C:\\Windows"] }
+ let(:merged_env) { ["ALLUSERSPROFILE=C:\\ProgramData", "TEMP=C:\\Windows\\TEMP", "TMP=C:\\Windows\\TEMP", "USER=Administrator", "USERDOMAIN=WIN-G06ENRTTKF9", "USERDOMAIN_ROAMINGPROFILE=WIN-G06ENRTTKF9", "USERNAME=testuser", "USERPROFILE=C:\\Users\\Default", "windir=C:\\Windows"] }
+ let(:converted) { { "ALLUSERSPROFILE" => "C:\\ProgramData", "TEMP" => "C:\\Windows\\TEMP", "TMP" => "C:\\Windows\\TEMP", "USERDOMAIN" => "WIN-G06ENRTTKF9", "USERNAME" => "testuser", "USERPROFILE" => "C:\\Users\\Default", "windir" => "C:\\Windows" } }
+
+ it "merge environment variables" do
+ expect(Process.merge_env_variables(env_list, current_env)).to eql(merged_env)
+ end
+
+ it "Convert an array to a hash" do
+ expect(Process.to_hash(env_list)).to eql(converted)
+ end
+ end
+
context "when :elevated => true" do
context "when user and password are passed" do
let(:options) { { user: user, password: password, elevated: true } }