summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
authornimisha <nimisha.sharad@msystechnologies.com>2017-12-19 18:55:55 +0530
committernimisha <nimisha.sharad@msystechnologies.com>2018-01-24 15:00:39 +0530
commit85e0c15d15425978de490bdce7fa7692690e6dc4 (patch)
tree46f0791f15673bd157bd9cba3d628f40e2e183b7 /spec
parentcc9766bd0a98b733eef3e9d40f3eac85a25f7e93 (diff)
downloadchef-85e0c15d15425978de490bdce7fa7692690e6dc4.tar.gz
Fixed/added specs for LogonSession changes
Signed-off-by: nimisha <nimisha.sharad@msystechnologies.com>
Diffstat (limited to 'spec')
-rw-r--r--spec/functional/win32/security_spec.rb27
-rw-r--r--spec/unit/util/windows/logon_session_spec.rb3
-rw-r--r--spec/unit/win32/security_spec.rb15
3 files changed, 44 insertions, 1 deletions
diff --git a/spec/functional/win32/security_spec.rb b/spec/functional/win32/security_spec.rb
index 1caa775481..d35f6dea0b 100644
--- a/spec/functional/win32/security_spec.rb
+++ b/spec/functional/win32/security_spec.rb
@@ -122,4 +122,31 @@ describe "Chef::Win32::Security", :windows_only do
end
end
end
+
+ describe ".get_token_information_elevation_type" do
+ let(:token_rights) { Chef::ReservedNames::Win32::Security::TOKEN_READ }
+
+ let(:token) do
+ Chef::ReservedNames::Win32::Security.open_process_token(
+ Chef::ReservedNames::Win32::Process.get_current_process,
+ token_rights)
+ end
+
+ context "when the token is valid" do
+ let(:token_elevation_type) { [:TokenElevationTypeDefault, :TokenElevationTypeFull, :TokenElevationTypeLimited] }
+
+ it "returns the token elevation type" do
+ elevation_type = Chef::ReservedNames::Win32::Security.get_token_information_elevation_type(token)
+ expect(token_elevation_type).to include(elevation_type)
+ end
+ end
+
+ context "when the token is invalid" do
+ it "raises `handle invalid` error" do
+ # If `OpenProcessToken` is stubbed, `open_process_token` returns an invalid token
+ allow(Chef::ReservedNames::Win32::Security).to receive(:OpenProcessToken).and_return(true)
+ expect { Chef::ReservedNames::Win32::Security.get_token_information_elevation_type(token) }.to raise_error(Chef::Exceptions::Win32APIError)
+ end
+ end
+ end
end
diff --git a/spec/unit/util/windows/logon_session_spec.rb b/spec/unit/util/windows/logon_session_spec.rb
index b9b6c458b6..77915c2ae1 100644
--- a/spec/unit/util/windows/logon_session_spec.rb
+++ b/spec/unit/util/windows/logon_session_spec.rb
@@ -27,7 +27,8 @@ describe ::Chef::Util::Windows::LogonSession do
stub_const("Chef::ReservedNames::Win32::API::System", Class.new )
end
- let(:session) { ::Chef::Util::Windows::LogonSession.new(session_user, password, session_domain) }
+ let(:session) { ::Chef::Util::Windows::LogonSession.new(session_user, password, session_domain, logon_type) }
+ let(:logon_type) { :remote }
shared_examples_for "it received syntactically invalid credentials" do
it "does not raisees an exception when it is initialized" do
diff --git a/spec/unit/win32/security_spec.rb b/spec/unit/win32/security_spec.rb
index 1c755061ce..4e22668a93 100644
--- a/spec/unit/win32/security_spec.rb
+++ b/spec/unit/win32/security_spec.rb
@@ -63,4 +63,19 @@ describe "Chef::Win32::Security", :windows_only do
end
end
end
+
+ describe "self.get_token_information_elevation_type" do
+ let(:token_rights) { Chef::ReservedNames::Win32::Security::TOKEN_READ }
+
+ let(:token) do
+ Chef::ReservedNames::Win32::Security.open_process_token(
+ Chef::ReservedNames::Win32::Process.get_current_process,
+ token_rights)
+ end
+
+ it "raises error if GetTokenInformation fails" do
+ allow(Chef::ReservedNames::Win32::Security).to receive(:GetTokenInformation).and_return(false)
+ expect { Chef::ReservedNames::Win32::Security.get_token_information_elevation_type(token) }.to raise_error(Chef::Exceptions::Win32APIError)
+ end
+ end
end