summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
authornimisha <nimisha.sharad@msystechnologies.com>2017-02-24 18:46:51 +0530
committerBryan McLellan <btm@loftninjas.org>2017-09-05 20:09:30 -0400
commit24de354c67305563f677080c03b8892c4a9e0fb1 (patch)
tree9e3657586d78f843aa3e139ecccba9d67e72efaf /spec
parent35f4cafac60770b59853d7e12b418f1971d234db (diff)
downloadchef-24de354c67305563f677080c03b8892c4a9e0fb1.tar.gz
Fixing specs
Signed-off-by: nimisha <nimisha.sharad@msystechnologies.com>
Diffstat (limited to 'spec')
-rw-r--r--spec/support/shared/functional/execute_resource.rb2
-rw-r--r--spec/unit/mixin/user_context_spec.rb21
-rw-r--r--spec/unit/mixin/user_identity_spec.rb201
-rw-r--r--spec/unit/provider/remote_file/fetcher_spec.rb1
-rw-r--r--spec/unit/provider/remote_file/network_file_spec.rb8
-rw-r--r--spec/unit/util/windows/logon_session_spec.rb22
6 files changed, 20 insertions, 235 deletions
diff --git a/spec/support/shared/functional/execute_resource.rb b/spec/support/shared/functional/execute_resource.rb
index 29b9a5fb9f..4f7cea1cd1 100644
--- a/spec/support/shared/functional/execute_resource.rb
+++ b/spec/support/shared/functional/execute_resource.rb
@@ -147,4 +147,4 @@ shared_examples_for "a resource with a guard specifying an alternate user identi
end
end
end
-end \ No newline at end of file
+end
diff --git a/spec/unit/mixin/user_context_spec.rb b/spec/unit/mixin/user_context_spec.rb
index 00306592ec..f2119b6dbc 100644
--- a/spec/unit/mixin/user_context_spec.rb
+++ b/spec/unit/mixin/user_context_spec.rb
@@ -41,6 +41,7 @@ describe "a class that mixes in user_context" do
before do
allow(::Chef::Platform).to receive(:windows?).and_return(true)
allow(::Chef::Util::Windows::LogonSession).to receive(:new).and_return(logon_session)
+ allow(instance_with_user_context).to receive(:node).and_return({ "platform_family" => "windows" })
end
let(:logon_session) { instance_double("::Chef::Util::Windows::LogonSession", :set_user_context => nil, :open => nil, :close => nil) }
@@ -49,22 +50,6 @@ describe "a class that mixes in user_context" do
expect { instance_with_user_context.with_context(nil, nil, nil) {} }.not_to raise_error
end
- it "raises an exception if the user is supplied but not the domain and password" do
- expect { instance_with_user_context.with_context("kamilah", nil, nil) {} }.to raise_error(ArgumentError)
- end
-
- it "raises an exception if the domain is supplied but not the user and password" do
- expect { instance_with_user_context.with_context(nil, "xanadu", nil) {} }.to raise_error(ArgumentError)
- end
-
- it "raises an exception if the password is supplied but not the user and domain" do
- expect { instance_with_user_context.with_context(nil, nil, "chef4life") {} }.to raise_error(ArgumentError)
- end
-
- it "raises an exception if the user and domain is supplied but the password is not" do
- expect { instance_with_user_context.with_context("kamilah", "xanadu", nil) {} }.to raise_error(ArgumentError)
- end
-
context "when given valid user credentials" do
before do
expect(::Chef::Util::Windows::LogonSession).to receive(:new).and_return(logon_session)
@@ -94,7 +79,7 @@ describe "a class that mixes in user_context" do
end
context "when the block raises an exception" do
- class UserContextTestException < Exception
+ class UserContextTestException < RuntimeError
end
let(:block_parameter) { Proc.new { raise UserContextTextException } }
@@ -114,7 +99,7 @@ describe "a class that mixes in user_context" do
context "when not running on Windows" do
before do
- allow(::Chef::Platform).to receive(:windows?).and_return(false)
+ allow(instance_with_user_context).to receive(:node).and_return({ "platform_family" => "ubuntu" })
end
it "raises a ::Chef::Exceptions::UnsupportedPlatform exception" do
diff --git a/spec/unit/mixin/user_identity_spec.rb b/spec/unit/mixin/user_identity_spec.rb
deleted file mode 100644
index 799260b25a..0000000000
--- a/spec/unit/mixin/user_identity_spec.rb
+++ /dev/null
@@ -1,201 +0,0 @@
-#
-# Author:: Adam Edwards (<adamed@chef.io>)
-# Copyright:: Copyright (c) 2015 Chef Software, Inc.
-# License:: Apache License, Version 2.0
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-#
-
-require "spec_helper"
-require "chef/mixin/user_identity"
-
-shared_examples_for "it received valid credentials" do
- describe "the validation method" do
- it "should not raise an error" do
- expect { instance_with_identity.validate(username, password, domain) }.not_to raise_error
- end
- end
-
- describe "the name qualification method" do
- it "should correctly translate the user and domain" do
- identity = nil
- expect { identity = instance_with_identity.qualify_name(username, domain) }.not_to raise_error
- expect(identity[:domain]).to eq(domain)
- expect(identity[:user]).to eq(username)
- end
- end
-end
-
-shared_examples_for "it received invalid credentials" do
- describe "the validation method" do
- it "should raise an error" do
- expect { instance_with_identity.validate(username, password, domain) }.to raise_error(ArgumentError)
- end
- end
-end
-
-shared_examples_for "it received credentials that are not valid on the platform" do
- describe "the validation method" do
- it "should raise an error" do
- expect { instance_with_identity.validate(username, password, domain) }.to raise_error(Chef::Exceptions::UnsupportedPlatform)
- end
- end
-end
-
-shared_examples_for "a consumer of the ::Chef::Mixin::UserIdentity mixin" do
- context "when running on Windows" do
- before do
- allow(::Chef::Platform).to receive(:windows?).and_return(true)
- end
-
- context "when no user, domain, or password is specified" do
- let(:username) { nil }
- let(:domain) { nil }
- let(:password) { nil }
- it_behaves_like "it received valid credentials"
- end
-
- context "when a valid username is specified" do
- let(:username) { "starchild" }
- context "when a valid domain is specified" do
- let(:domain) { "mothership" }
-
- context "when the password is not specified" do
- let(:password) { nil }
- it_behaves_like "it received invalid credentials"
- end
-
- context "when the password is specified" do
- let(:password) { "we.funk!" }
- it_behaves_like "it received valid credentials"
- end
- end
-
- context "when the domain is not specified" do
- let(:domain) { nil }
-
- context "when the password is not specified" do
- let(:password) { nil }
- it_behaves_like "it received invalid credentials"
- end
-
- context "when the password is specified" do
- let(:password) { "we.funk!" }
- it_behaves_like "it received valid credentials"
- end
- end
- end
-
- context "when the username is not specified" do
- let(:username) { nil }
-
- context "when the password is specified and the domain is not" do
- let(:password) { "we.funk!" }
- let(:domain) { nil }
- it_behaves_like "it received invalid credentials"
- end
-
- context "when the domain is specified and the password is not" do
- let(:domain) { "mothership" }
- let(:password) { nil }
- it_behaves_like "it received invalid credentials"
- end
-
- context "when the domain and password are specified" do
- let(:domain) { "mothership" }
- let(:password) { "we.funk!" }
- it_behaves_like "it received invalid credentials"
- end
- end
- end
-
- context "when not running on Windows" do
- before do
- allow(::Chef::Platform).to receive(:windows?).and_return(false)
- end
-
- context "when no user, domain, or password is specified" do
- let(:username) { nil }
- let(:domain) { nil }
- let(:password) { nil }
- it_behaves_like "it received valid credentials"
- end
-
- context "when the user is specified and the domain and password are not" do
- let(:username) { "starchild" }
- let(:domain) { nil }
- let(:password) { nil }
- it_behaves_like "it received valid credentials"
-
- context "when the password is specified and the domain is not" do
- let(:password) { "we.funk!" }
- let(:domain) { nil }
- it_behaves_like "it received credentials that are not valid on the platform"
- end
-
- context "when the domain is specified and the password is not" do
- let(:domain) { "mothership" }
- let(:password) { nil }
- it_behaves_like "it received credentials that are not valid on the platform"
- end
-
- context "when the domain and password are specified" do
- let(:domain) { "mothership" }
- let(:password) { "we.funk!" }
- it_behaves_like "it received credentials that are not valid on the platform"
- end
- end
-
- context "when the user is not specified" do
- let(:username) { nil }
- context "when the domain is specified" do
- let(:domain) { "mothership" }
- context "when the password is specified" do
- let(:password) { "we.funk!" }
- it_behaves_like "it received credentials that are not valid on the platform"
- end
-
- context "when password is not specified" do
- let(:password) { nil }
- it_behaves_like "it received credentials that are not valid on the platform"
- end
- end
-
- context "when the domain is not specified" do
- let(:domain) { nil }
- context "when the password is specified" do
- let(:password) { "we.funk!" }
- it_behaves_like "it received credentials that are not valid on the platform"
- end
- end
- end
- end
-end
-
-describe "a class that mixes in user_identity" do
- let(:instance_with_identity) do
- class IdentityClass
- include ::Chef::Mixin::UserIdentity
- def validate(*args)
- validate_identity(*args)
- end
-
- def qualify_name(*args)
- qualify_user(*args)
- end
- end
- IdentityClass.new
- end
-
- it_behaves_like "a consumer of the ::Chef::Mixin::UserIdentity mixin"
-end
diff --git a/spec/unit/provider/remote_file/fetcher_spec.rb b/spec/unit/provider/remote_file/fetcher_spec.rb
index 0fa213cdb2..f5b32800f2 100644
--- a/spec/unit/provider/remote_file/fetcher_spec.rb
+++ b/spec/unit/provider/remote_file/fetcher_spec.rb
@@ -27,6 +27,7 @@ describe Chef::Provider::RemoteFile::Fetcher do
describe "when passed a network share" do
before do
expect(Chef::Provider::RemoteFile::NetworkFile).to receive(:new).and_return(fetcher_instance)
+ allow(Chef::Platform).to receive(:windows?).and_return(true)
end
context "when host is a name" do
diff --git a/spec/unit/provider/remote_file/network_file_spec.rb b/spec/unit/provider/remote_file/network_file_spec.rb
index 52743c0830..621d2769a4 100644
--- a/spec/unit/provider/remote_file/network_file_spec.rb
+++ b/spec/unit/provider/remote_file/network_file_spec.rb
@@ -20,10 +20,6 @@
require "spec_helper"
describe Chef::Provider::RemoteFile::NetworkFile do
- before do
- allow(::Chef::Platform).to receive(:windows?).and_return(true)
- end
-
let(:source) { "\\\\foohost\\fooshare\\Foo.tar.gz" }
let(:new_resource) { Chef::Resource::RemoteFile.new("network file (new_resource)") }
@@ -36,6 +32,10 @@ describe Chef::Provider::RemoteFile::NetworkFile do
let(:chef_tempfile) { double("Chef::FileContentManagement::Tempfile", :tempfile => tempfile) }
let(:source_file) { double("::File", :read => nil) }
+ before do
+ allow(fetcher).to receive(:node).and_return({ "platform_family" => "windows" })
+ end
+
it "stages the local file to a temporary file" do
expect(Chef::FileContentManagement::Tempfile).to receive(:new).with(new_resource).and_return(chef_tempfile)
expect(::File).to receive(:open).with(source, "rb").and_return(source_file)
diff --git a/spec/unit/util/windows/logon_session_spec.rb b/spec/unit/util/windows/logon_session_spec.rb
index 492c204298..7c5e7c76c9 100644
--- a/spec/unit/util/windows/logon_session_spec.rb
+++ b/spec/unit/util/windows/logon_session_spec.rb
@@ -37,7 +37,7 @@ describe ::Chef::Util::Windows::LogonSession do
shared_examples_for "it received an incorrect username and password combination" do
before do
- expect(Chef::ReservedNames::Win32::API::Security).to receive(:LogonUserW).and_return(0)
+ expect(Chef::ReservedNames::Win32::API::Security).to receive(:LogonUserW).and_return(false)
end
it "raises a Chef::Exceptions::Win32APIError exception when the open method is called" do
@@ -49,14 +49,14 @@ describe ::Chef::Util::Windows::LogonSession do
shared_examples_for "it received valid credentials" do
it "does not raise an exception when the open method is called" do
- expect(Chef::ReservedNames::Win32::API::Security).to receive(:LogonUserW).and_return(1)
+ expect(Chef::ReservedNames::Win32::API::Security).to receive(:LogonUserW).and_return(true)
expect { session.open }.not_to raise_error
end
end
shared_examples_for "the session is not open" do
it "does not raise an exception when #open is called" do
- expect(Chef::ReservedNames::Win32::API::Security).to receive(:LogonUserW).and_return(1)
+ expect(Chef::ReservedNames::Win32::API::Security).to receive(:LogonUserW).and_return(true)
expect { session.open }.not_to raise_error
end
@@ -169,7 +169,7 @@ describe ::Chef::Util::Windows::LogonSession do
let(:session_domain) { "fairyland" }
before do
- expect(Chef::ReservedNames::Win32::API::Security).to receive(:LogonUserW).and_return(1)
+ expect(Chef::ReservedNames::Win32::API::Security).to receive(:LogonUserW).and_return(true)
expect { session.open }.not_to raise_error
end
@@ -191,13 +191,13 @@ describe ::Chef::Util::Windows::LogonSession do
end
it "can impersonate the user" do
- expect(Chef::ReservedNames::Win32::API::Security).to receive(:ImpersonateLoggedOnUser).and_return(1)
+ expect(Chef::ReservedNames::Win32::API::Security).to receive(:ImpersonateLoggedOnUser).and_return(true)
expect { session.set_user_context }.not_to raise_error
end
context "when #set_user_context fails due to low resources causing a failure to impersonate" do
before do
- expect(Chef::ReservedNames::Win32::API::Security).to receive(:ImpersonateLoggedOnUser).and_return(0)
+ expect(Chef::ReservedNames::Win32::API::Security).to receive(:ImpersonateLoggedOnUser).and_return(false)
end
it "raises an exception when #set_user_context fails because impersonation failed" do
@@ -216,7 +216,7 @@ describe ::Chef::Util::Windows::LogonSession do
context "when #set_user_context successfully impersonates the user" do
before do
- expect(Chef::ReservedNames::Win32::API::Security).to receive(:ImpersonateLoggedOnUser).and_return(1)
+ expect(Chef::ReservedNames::Win32::API::Security).to receive(:ImpersonateLoggedOnUser).and_return(true)
expect { session.set_user_context }.not_to raise_error
end
@@ -228,14 +228,14 @@ describe ::Chef::Util::Windows::LogonSession do
describe "the impersonation will be reverted" do
before do
- expect(Chef::ReservedNames::Win32::API::Security).to receive(:RevertToSelf)
+ expect(Chef::ReservedNames::Win32::API::Security).to receive(:RevertToSelf).and_return(true)
end
it_behaves_like "the session is open"
end
context "when the attempt to revert impersonation fails" do
before do
- expect(Chef::ReservedNames::Win32::API::Security).to receive(:RevertToSelf).and_return(0)
+ expect(Chef::ReservedNames::Win32::API::Security).to receive(:RevertToSelf).and_return(false)
end
it "raises an exception when #restore_user_context is called" do
@@ -253,7 +253,7 @@ describe ::Chef::Util::Windows::LogonSession do
context "when revert continues to fail" do
before do
- expect(Chef::ReservedNames::Win32::API::Security).to receive(:RevertToSelf).and_return(0)
+ expect(Chef::ReservedNames::Win32::API::Security).to receive(:RevertToSelf).and_return(false)
end
it "raises an exception when #close is called and impersonation fails" do
expect { session.close }.to raise_error(Chef::Exceptions::Win32APIError)
@@ -262,7 +262,7 @@ describe ::Chef::Util::Windows::LogonSession do
context "when revert stops failing and succeeds" do
before do
- expect(Chef::ReservedNames::Win32::API::Security).to receive(:RevertToSelf).and_return(1)
+ expect(Chef::ReservedNames::Win32::API::Security).to receive(:RevertToSelf).and_return(true)
end
it "does not raise an exception when #restore_user_context is called" do