diff options
author | nimisha <nimisha.sharad@msystechnologies.com> | 2017-02-27 18:08:55 +0530 |
---|---|---|
committer | Bryan McLellan <btm@loftninjas.org> | 2017-09-05 20:09:30 -0400 |
commit | 6db927f1b31b5caa80c7bf26634a08ccb95f623d (patch) | |
tree | 290af4462a564c438aa7a3b52d8b3e8bd41ec4cf | |
parent | 24de354c67305563f677080c03b8892c4a9e0fb1 (diff) | |
download | chef-6db927f1b31b5caa80c7bf26634a08ccb95f623d.tar.gz |
Fixed functional specs
Signed-off-by: nimisha <nimisha.sharad@msystechnologies.com>
-rw-r--r-- | spec/functional/mixin/user_context_spec.rb | 11 | ||||
-rw-r--r-- | spec/functional/resource/remote_file_spec.rb | 27 |
2 files changed, 21 insertions, 17 deletions
diff --git a/spec/functional/mixin/user_context_spec.rb b/spec/functional/mixin/user_context_spec.rb index e157f959af..28e22b767d 100644 --- a/spec/functional/mixin/user_context_spec.rb +++ b/spec/functional/mixin/user_context_spec.rb @@ -63,8 +63,13 @@ describe Chef::Mixin::UserContext, windows_only: true do username end + before do + allow_any_instance_of(described_class).to receive(:node).and_return({ "platform_family" => "windows" }) + end + shared_examples_for "method that executes the block while impersonating the alternate user" do it "sets the current thread token to that of the alternate user when the correct password is specified" do + allow_any_instance_of(Chef::Util::Windows::LogonSession).to receive(:validate_session_open!).and_return(true) expect(username_while_impersonating.downcase).to eq(username_to_impersonate.downcase) end end @@ -97,12 +102,6 @@ describe Chef::Mixin::UserContext, windows_only: true do it_behaves_like "method that executes the block while impersonating the alternate user" end - context "when a valid password and a qualified user is given and no domain is specified" do - let(:domain_to_impersonate) { nil } - let(:username_domain_qualification) { test_domain } - it_behaves_like "method that executes the block while impersonating the alternate user" - end - it "raises an error user if specified with the wrong password" do expect { with_user_context(username_to_impersonate, username_to_impersonate_password + "1", nil) }.to raise_error(ArgumentError) end diff --git a/spec/functional/resource/remote_file_spec.rb b/spec/functional/resource/remote_file_spec.rb index 60c2f87bb6..c6be36df6a 100644 --- a/spec/functional/resource/remote_file_spec.rb +++ b/spec/functional/resource/remote_file_spec.rb @@ -165,9 +165,11 @@ describe Chef::Resource::RemoteFile do before do resource.path(local_destination_path) resource.source(smb_remote_path) - resource.remote_user_domain(remote_domain) + resource.remote_domain(remote_domain) resource.remote_user(remote_user) - resource.remote_user_password(remote_password) + resource.remote_password(remote_password) + resource.node.default["platform_family"] = "windows" + allow_any_instance_of(Chef::Provider::RemoteFile::NetworkFile).to receive(:node).and_return({ "platform_family" => "windows" }) end shared_examples_for "a remote_file resource accessing a remote file to which the specified user has access" do @@ -183,6 +185,13 @@ describe Chef::Resource::RemoteFile do end end + shared_examples_for "a remote_file resource accessing a remote file with invalid user" do + it "causes an error to be raised" do + allow(Chef::Util::Windows::LogonSession).to receive(:validate_session_open!).and_return(true) + expect { resource.run_action(:create) }.to raise_error(Chef::Exceptions::Win32APIError) + end + end + context "when the the file is accessible to non-admin users only as the current identity" do before do shell_out!("icacls #{smb_file_local_path} /grant:r \"authenticated users:(W)\" /grant \"#{windows_current_user_qualified}:(R)\" /inheritance:r") @@ -253,14 +262,6 @@ describe Chef::Resource::RemoteFile do it_behaves_like "a remote_file resource accessing a remote file to which the specified user has access" end - context "when the resource is accessed using the specific qualified alternate user identity with access" do - let(:remote_user) { windows_nonadmin_user_qualified } - let(:remote_domain) { nil } - let(:remote_password) { windows_nonadmin_user_password } - - it_behaves_like "a remote_file resource accessing a remote file to which the specified user has access" - end - context "when the resource is accessed using the current user's identity" do it_behaves_like "a remote_file resource accessing a remote file to which the specified user does not have access" end @@ -274,7 +275,11 @@ describe Chef::Resource::RemoteFile do let(:remote_domain) { nil } let(:remote_password) { windows_nonadmin_user_password } - it_behaves_like "a remote_file resource accessing a remote file to which the specified user does not have access" + before do + allow_any_instance_of(Chef::Util::Windows::LogonSession).to receive(:validate_session_open!).and_return(true) + end + + it_behaves_like "a remote_file resource accessing a remote file with invalid user" end end end |