Fix nullptr crash in OnEmbed
[chromium-blink-merge.git] / net / http / mock_sspi_library_win.h
blobb042ebf6ca19625921688150724e337c3697a300
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef NET_HTTP_MOCK_SSPI_LIBRARY_WIN_H_
6 #define NET_HTTP_MOCK_SSPI_LIBRARY_WIN_H_
8 #include <list>
9 #include <set>
11 #include "net/http/http_auth_sspi_win.h"
13 namespace net {
15 // The MockSSPILibrary class is intended for unit tests which want to bypass
16 // the system SSPI library calls.
17 class MockSSPILibrary : public SSPILibrary {
18 public:
19 MockSSPILibrary();
20 ~MockSSPILibrary() override;
22 // TODO(cbentzel): Only QuerySecurityPackageInfo and FreeContextBuffer
23 // are properly handled currently.
24 // SSPILibrary methods:
25 SECURITY_STATUS AcquireCredentialsHandle(LPWSTR pszPrincipal,
26 LPWSTR pszPackage,
27 unsigned long fCredentialUse,
28 void* pvLogonId,
29 void* pvAuthData,
30 SEC_GET_KEY_FN pGetKeyFn,
31 void* pvGetKeyArgument,
32 PCredHandle phCredential,
33 PTimeStamp ptsExpiry) override;
34 SECURITY_STATUS InitializeSecurityContext(PCredHandle phCredential,
35 PCtxtHandle phContext,
36 SEC_WCHAR* pszTargetName,
37 unsigned long fContextReq,
38 unsigned long Reserved1,
39 unsigned long TargetDataRep,
40 PSecBufferDesc pInput,
41 unsigned long Reserved2,
42 PCtxtHandle phNewContext,
43 PSecBufferDesc pOutput,
44 unsigned long* contextAttr,
45 PTimeStamp ptsExpiry) override;
46 SECURITY_STATUS QuerySecurityPackageInfo(LPWSTR pszPackageName,
47 PSecPkgInfoW* pkgInfo) override;
48 SECURITY_STATUS FreeCredentialsHandle(PCredHandle phCredential) override;
49 SECURITY_STATUS DeleteSecurityContext(PCtxtHandle phContext) override;
50 SECURITY_STATUS FreeContextBuffer(PVOID pvContextBuffer) override;
52 // Establishes an expectation for a |QuerySecurityPackageInfo()| call.
54 // Each expectation established by |ExpectSecurityQueryPackageInfo()| must be
55 // matched by a call to |QuerySecurityPackageInfo()| during the lifetime of
56 // the MockSSPILibrary. The |expected_package| argument must equal the
57 // |*pszPackageName| argument to |QuerySecurityPackageInfo()| for there to be
58 // a match. The expectations also establish an explicit ordering.
60 // For example, this sequence will be successful.
61 // MockSSPILibrary lib;
62 // lib.ExpectQuerySecurityPackageInfo(L"NTLM", ...)
63 // lib.ExpectQuerySecurityPackageInfo(L"Negotiate", ...)
64 // lib.QuerySecurityPackageInfo(L"NTLM", ...)
65 // lib.QuerySecurityPackageInfo(L"Negotiate", ...)
67 // This sequence will fail since the queries do not occur in the order
68 // established by the expectations.
69 // MockSSPILibrary lib;
70 // lib.ExpectQuerySecurityPackageInfo(L"NTLM", ...)
71 // lib.ExpectQuerySecurityPackageInfo(L"Negotiate", ...)
72 // lib.QuerySecurityPackageInfo(L"Negotiate", ...)
73 // lib.QuerySecurityPackageInfo(L"NTLM", ...)
75 // This sequence will fail because there were not enough queries.
76 // MockSSPILibrary lib;
77 // lib.ExpectQuerySecurityPackageInfo(L"NTLM", ...)
78 // lib.ExpectQuerySecurityPackageInfo(L"Negotiate", ...)
79 // lib.QuerySecurityPackageInfo(L"NTLM", ...)
81 // |response_code| is used as the return value for
82 // |QuerySecurityPackageInfo()|. If |response_code| is SEC_E_OK,
83 // an expectation is also set for a call to |FreeContextBuffer()| after
84 // the matching |QuerySecurityPackageInfo()| is called.
86 // |package_info| is assigned to |*pkgInfo| in |QuerySecurityPackageInfo|.
87 // The lifetime of |*package_info| should last at least until the matching
88 // |QuerySecurityPackageInfo()| is called.
89 void ExpectQuerySecurityPackageInfo(const std::wstring& expected_package,
90 SECURITY_STATUS response_code,
91 PSecPkgInfoW package_info);
93 private:
94 struct PackageQuery {
95 std::wstring expected_package;
96 SECURITY_STATUS response_code;
97 PSecPkgInfoW package_info;
100 // expected_package_queries contains an ordered list of expected
101 // |QuerySecurityPackageInfo()| calls and the return values for those
102 // calls.
103 std::list<PackageQuery> expected_package_queries_;
105 // Set of packages which should be freed.
106 std::set<PSecPkgInfoW> expected_freed_packages_;
109 } // namespace net
111 #endif // NET_HTTP_MOCK_SSPI_LIBRARY_WIN_H_