From ab73a82301a4b92f6fa6146a3d37a2a8e85e3fe8 Mon Sep 17 00:00:00 2001 From: Nimisha Sharad Date: Wed, 9 Aug 2017 20:46:52 +0530 Subject: [MSYS-629] Added username,password validation for elavated option (#151) * Added username,password validation for elavated option Signed-off-by: nimisha --- lib/mixlib/shellout/windows.rb | 8 ++++++++ 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 -- cgit v1.2.1