diff options
author | Nimisha Sharad <nimisha.sharad@msystechnologies.com> | 2017-08-09 20:46:52 +0530 |
---|---|---|
committer | Bryan McLellan <btm@loftninjas.org> | 2017-08-09 11:16:52 -0400 |
commit | ab73a82301a4b92f6fa6146a3d37a2a8e85e3fe8 (patch) | |
tree | 927e18ad2aeeaca7733e3860f250f607883f453f | |
parent | 1fc2b032f1c5aec68b08556d178551392a6db616 (diff) | |
download | mixlib-shellout-ab73a82301a4b92f6fa6146a3d37a2a8e85e3fe8.tar.gz |
[MSYS-629] Added username,password validation for elavated option (#151)
* Added username,password validation for elavated option
Signed-off-by: nimisha <nimisha.sharad@clogeny.com>
-rw-r--r-- | lib/mixlib/shellout/windows.rb | 8 | ||||
-rw-r--r-- | spec/mixlib/shellout_spec.rb | 16 |
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 |