summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
authorKapil Chouhan <kapil.chouhan@msystechnologies.com>2019-05-02 17:02:25 +0530
committerBryan McLellan <btm@loftninjas.org>2019-05-17 09:52:40 -0400
commitea1fca6c894295c926b94c652014c9a1be7388fc (patch)
tree6a3b737eb3db4ec6b94e3d782b556860957b5f49 /spec
parent0de8b639e354e863e94be7701d991ab411fb27bf (diff)
downloadchef-ea1fca6c894295c926b94c652014c9a1be7388fc.tar.gz
Fix for Chef::Exceptions::Win32APIError: The operation completed successfully
Signed-off-by: Kapil Chouhan <kapil.chouhan@msystechnologies.com>
Diffstat (limited to 'spec')
-rw-r--r--spec/unit/win32/security_spec.rb25
1 files changed, 25 insertions, 0 deletions
diff --git a/spec/unit/win32/security_spec.rb b/spec/unit/win32/security_spec.rb
index b5e441f2a0..3c612aef10 100644
--- a/spec/unit/win32/security_spec.rb
+++ b/spec/unit/win32/security_spec.rb
@@ -106,4 +106,29 @@ describe "Chef::Win32::Security", :windows_only do
expect { Chef::ReservedNames::Win32::Security.get_token_information_elevation_type(token) }.to raise_error(Chef::Exceptions::Win32APIError)
end
end
+
+ describe "self.lookup_account_name" do
+ let(:security_class) { Chef::ReservedNames::Win32::Security }
+
+ context "when FFI::LastError.error result is ERROR_INSUFFICIENT_BUFFER" do
+ it "does not raise the exception" do
+ expect(FFI::LastError).to receive(:error).and_return(122)
+ expect { security_class.lookup_account_name "system" }.to_not raise_error
+ end
+ end
+
+ context "when operation completed successfully and FFI::LastError.error result is NO_ERROR" do
+ it "does not raise the exception" do
+ expect(FFI::LastError).to receive(:error).and_return(0)
+ expect { security_class.lookup_account_name "system" }.to_not raise_error
+ end
+ end
+
+ context "when FFI::LastError.error result is not ERROR_INSUFFICIENT_BUFFER and not NO_ERROR" do
+ it "raises Chef::ReservedNames::Win32::Error.raise! exception" do
+ expect(FFI::LastError).to receive(:error).and_return(123).at_least(:once)
+ expect { security_class.lookup_account_name "system" }.to raise_error
+ end
+ end
+ end
end