diff options
author | Bryan McLellan <btm@loftninjas.org> | 2019-05-10 10:16:18 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-05-10 10:16:18 -0400 |
commit | 6b7d5cbd601724ae7c6f8aac2f96e629d3e6910a (patch) | |
tree | 858f3170fc299968b4793549e38fae2216e74ab2 | |
parent | d606a41b1ee6167c77a0684f242d7a42da61b92e (diff) | |
parent | 0a8d0d20b4f3fc62eb768a40301d3046de09dd7a (diff) | |
download | chef-6b7d5cbd601724ae7c6f8aac2f96e629d3e6910a.tar.gz |
Merge pull request #8451 from MsysTechnologiesllc/Kapil/MSYS-996_Win32APIError_The_operation_completed_successfully
Fix for Chef::Exceptions::Win32APIError: The operation completed successfully.
-rw-r--r-- | lib/chef/win32/security.rb | 2 | ||||
-rw-r--r-- | spec/unit/win32/security_spec.rb | 25 |
2 files changed, 26 insertions, 1 deletions
diff --git a/lib/chef/win32/security.rb b/lib/chef/win32/security.rb index 0d2a2ee470..6d9d359130 100644 --- a/lib/chef/win32/security.rb +++ b/lib/chef/win32/security.rb @@ -404,7 +404,7 @@ class Chef system_name = system_name.to_wstring if system_name if LookupAccountNameW(system_name, name.to_wstring, nil, sid_size, nil, referenced_domain_name_size, nil) raise "Expected ERROR_INSUFFICIENT_BUFFER from LookupAccountName, and got no error!" - elsif FFI::LastError.error != ERROR_INSUFFICIENT_BUFFER + elsif !([NO_ERROR, ERROR_INSUFFICIENT_BUFFER].include?(FFI::LastError.error)) Chef::ReservedNames::Win32::Error.raise! end 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 |