summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNimisha Sharad <nimisha.sharad@msystechnologies.com>2017-07-26 21:55:32 +0530
committerBryan McLellan <btm@loftninjas.org>2017-07-26 12:25:32 -0400
commitc2047dde3ecd39188ac3fd5e367613d0b5e4af64 (patch)
tree4963e50ca89399a9224360169662c08cd47daba9
parent7d7cb3e3d7a22908e80dcd8f8541e5537a1b1629 (diff)
downloadchef-c2047dde3ecd39188ac3fd5e367613d0b5e4af64.tar.gz
[MSYS-629] Added username/password validation for elevated option (#6293)
* Added username/password validation for elevated option with specs Signed-off-by: nimisha <nimisha.sharad@clogeny.com>
-rw-r--r--lib/chef/resource/execute.rb4
-rw-r--r--spec/unit/resource/execute_spec.rb22
2 files changed, 25 insertions, 1 deletions
diff --git a/lib/chef/resource/execute.rb b/lib/chef/resource/execute.rb
index 32198e5db0..ba1b8ae6e3 100644
--- a/lib/chef/resource/execute.rb
+++ b/lib/chef/resource/execute.rb
@@ -162,6 +162,10 @@ class Chef
if specified_user && password.nil?
raise ArgumentError, "A value for `password` must be specified when a value for `user` is specified on the Windows platform"
end
+
+ if elevated && !specified_user && !password
+ raise ArgumentError, "`elevated` option should be passed only with `username` and `password`."
+ end
else
if password || specified_domain
raise Exceptions::UnsupportedPlatform, "Values for `domain` and `password` are only supported on the Windows platform"
diff --git a/spec/unit/resource/execute_spec.rb b/spec/unit/resource/execute_spec.rb
index 69e4e91f2a..575c80ba2f 100644
--- a/spec/unit/resource/execute_spec.rb
+++ b/spec/unit/resource/execute_spec.rb
@@ -77,7 +77,7 @@ describe Chef::Resource::Execute do
shared_examples_for "it received invalid credentials" do
describe "the validation method" do
it "should raise an error" do
- expect { execute_resource.validate_identity_platform(username, password, domain) }.to raise_error(ArgumentError)
+ expect { execute_resource.validate_identity_platform(username, password, domain, elevated) }.to raise_error(ArgumentError)
end
end
end
@@ -113,6 +113,7 @@ describe Chef::Resource::Execute do
context "when a valid username is specified" do
let(:username) { "starchild" }
+ let(:elevated) { false }
context "when a valid domain is specified" do
let(:domain) { "mothership" }
@@ -129,6 +130,7 @@ describe Chef::Resource::Execute do
context "when the domain is not specified" do
let(:domain) { nil }
+ let(:elevated) { false }
context "when the password is not specified" do
let(:password) { nil }
@@ -179,6 +181,24 @@ describe Chef::Resource::Execute do
it_behaves_like "it received invalid username and domain"
end
end
+
+ context "when elevated is passed" do
+ let(:elevated) { true }
+
+ context "when username and password are not passed" do
+ let(:username) { nil }
+ let(:domain) { nil }
+ let(:password) { nil }
+ it_behaves_like "it received invalid credentials"
+ end
+
+ context "when username and password are passed" do
+ let(:username) { "user" }
+ let(:domain) { nil }
+ let(:password) { "we.funk!" }
+ it_behaves_like "it received valid credentials"
+ end
+ end
end
context "when not running on Windows" do