summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/mixlib/shellout/windows.rb8
-rw-r--r--spec/mixlib/shellout_spec.rb16
2 files changed, 21 insertions, 3 deletions
diff --git a/lib/mixlib/shellout/windows.rb b/lib/mixlib/shellout/windows.rb
index b586a5f..226c7c4 100644
--- a/lib/mixlib/shellout/windows.rb
+++ b/lib/mixlib/shellout/windows.rb
@@ -36,6 +36,14 @@ module Mixlib
raise InvalidCommandOption, "You must supply a password when supplying a user in windows"
end
+ if !opts[:user] && opts[:password]
+ raise InvalidCommandOption, "You must supply a user when supplying a password in windows"
+ end
+
+ if opts[:elevated] && !opts[:user] && !opts[:password]
+ raise InvalidCommandOption, "`elevated` option should be passed only with `username` and `password`."
+ end
+
if opts[:elevated] && opts[:elevated] != true && opts[:elevated] != false
raise InvalidCommandOption, "Invalid value passed for `elevated`. Please provide true/false."
end
diff --git a/spec/mixlib/shellout_spec.rb b/spec/mixlib/shellout_spec.rb
index 57c1403..3848c5e 100644
--- a/spec/mixlib/shellout_spec.rb
+++ b/spec/mixlib/shellout_spec.rb
@@ -657,10 +657,20 @@ describe Mixlib::ShellOut do
end
context "when :elevated => true" do
- let(:options) { { :user => user, :password => password, :elevated => true } }
+ context "when user and password are passed" do
+ let(:options) { { :user => user, :password => password, :elevated => true } }
- it "raises error" do
- expect { running_user }.to raise_error(/the user has not been granted the requested logon type at this computer/)
+ it "raises permission related error" do
+ expect { running_user }.to raise_error(/the user has not been granted the requested logon type at this computer/)
+ end
+ end
+
+ context "when user and password are not passed" do
+ let(:options) { { :elevated => true } }
+
+ it "raises error" do
+ expect { running_user }.to raise_error("`elevated` option should be passed only with `username` and `password`.")
+ end
end
end
end