Switch global error menu icon to vectorized MD asset
[chromium-blink-merge.git] / net / http / mock_gssapi_library_posix.h
blob3d5f248a035454482a03109ced2ba930c443ffcd
1 // Copyright (c) 2011 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_GSSAPI_LIBRARY_POSIX_H_
6 #define NET_HTTP_MOCK_GSSAPI_LIBRARY_POSIX_H_
8 #include <list>
9 #include <string>
11 #include "base/gtest_prod_util.h"
12 #include "net/http/http_auth_gssapi_posix.h"
14 namespace net {
16 namespace test {
18 class GssContextMockImpl {
19 public:
20 GssContextMockImpl();
21 GssContextMockImpl(const GssContextMockImpl& other);
22 GssContextMockImpl(const char* src_name,
23 const char* targ_name,
24 OM_uint32 lifetime_rec,
25 const gss_OID_desc& mech_type,
26 OM_uint32 ctx_flags,
27 int locally_initiated,
28 int open);
29 ~GssContextMockImpl();
31 void Assign(const GssContextMockImpl& other);
33 std::string src_name;
34 std::string targ_name;
35 OM_uint32 lifetime_rec;
36 gss_OID_desc mech_type;
37 OM_uint32 ctx_flags;
38 int locally_initiated;
39 int open;
42 // The MockGSSAPILibrary class is intended for unit tests which want to bypass
43 // the system GSSAPI library calls.
44 class MockGSSAPILibrary : public GSSAPILibrary {
45 public:
46 // Unit tests need access to this. "Friend"ing didn't help.
47 struct SecurityContextQuery {
48 SecurityContextQuery();
49 SecurityContextQuery(const std::string& expected_package,
50 OM_uint32 response_code,
51 OM_uint32 minor_response_code,
52 const test::GssContextMockImpl& context_info,
53 const char* expected_input_token,
54 const char* output_token);
55 ~SecurityContextQuery();
57 std::string expected_package;
58 OM_uint32 response_code;
59 OM_uint32 minor_response_code;
60 test::GssContextMockImpl context_info;
61 gss_buffer_desc expected_input_token;
62 gss_buffer_desc output_token;
65 MockGSSAPILibrary();
66 ~MockGSSAPILibrary() override;
68 // Establishes an expectation for a |init_sec_context()| call.
70 // Each expectation established by |ExpectSecurityContext()| must be
71 // matched by a call to |init_sec_context()| during the lifetime of
72 // the MockGSSAPILibrary. The |expected_package| argument must equal the
73 // value associated with the |target_name| argument to |init_sec_context()|
74 // for there to be a match. The expectations also establish an explicit
75 // ordering.
77 // For example, this sequence will be successful.
78 // MockGSSAPILibrary lib;
79 // lib.ExpectSecurityContext("NTLM", ...)
80 // lib.ExpectSecurityContext("Negotiate", ...)
81 // lib.init_sec_context("NTLM", ...)
82 // lib.init_sec_context("Negotiate", ...)
84 // This sequence will fail since the queries do not occur in the order
85 // established by the expectations.
86 // MockGSSAPILibrary lib;
87 // lib.ExpectSecurityContext("NTLM", ...)
88 // lib.ExpectSecurityContext("Negotiate", ...)
89 // lib.init_sec_context("Negotiate", ...)
90 // lib.init_sec_context("NTLM", ...)
92 // This sequence will fail because there were not enough queries.
93 // MockGSSAPILibrary lib;
94 // lib.ExpectSecurityContext("NTLM", ...)
95 // lib.ExpectSecurityContext("Negotiate", ...)
96 // lib.init_sec_context("NTLM", ...)
98 // |response_code| is used as the return value for |init_sec_context()|.
99 // If |response_code| is GSS_S_COMPLETE,
101 // |context_info| is the expected value of the |**context_handle| in after
102 // |init_sec_context()| returns.
103 void ExpectSecurityContext(const std::string& expected_package,
104 OM_uint32 response_code,
105 OM_uint32 minor_response_code,
106 const test::GssContextMockImpl& context_info,
107 const gss_buffer_desc& expected_input_token,
108 const gss_buffer_desc& output_token);
110 // GSSAPILibrary methods:
112 // Initializes the library, including any necessary dynamic libraries.
113 // This is done separately from construction (which happens at startup time)
114 // in order to delay work until the class is actually needed.
115 bool Init() override;
117 // These methods match the ones in the GSSAPI library.
118 OM_uint32 import_name(OM_uint32* minor_status,
119 const gss_buffer_t input_name_buffer,
120 const gss_OID input_name_type,
121 gss_name_t* output_name) override;
122 OM_uint32 release_name(OM_uint32* minor_status,
123 gss_name_t* input_name) override;
124 OM_uint32 release_buffer(OM_uint32* minor_status,
125 gss_buffer_t buffer) override;
126 OM_uint32 display_name(OM_uint32* minor_status,
127 const gss_name_t input_name,
128 gss_buffer_t output_name_buffer,
129 gss_OID* output_name_type) override;
130 OM_uint32 display_status(OM_uint32* minor_status,
131 OM_uint32 status_value,
132 int status_type,
133 const gss_OID mech_type,
134 OM_uint32* message_contex,
135 gss_buffer_t status_string) override;
136 OM_uint32 init_sec_context(OM_uint32* minor_status,
137 const gss_cred_id_t initiator_cred_handle,
138 gss_ctx_id_t* context_handle,
139 const gss_name_t target_name,
140 const gss_OID mech_type,
141 OM_uint32 req_flags,
142 OM_uint32 time_req,
143 const gss_channel_bindings_t input_chan_bindings,
144 const gss_buffer_t input_token,
145 gss_OID* actual_mech_type,
146 gss_buffer_t output_token,
147 OM_uint32* ret_flags,
148 OM_uint32* time_rec) override;
149 OM_uint32 wrap_size_limit(OM_uint32* minor_status,
150 const gss_ctx_id_t context_handle,
151 int conf_req_flag,
152 gss_qop_t qop_req,
153 OM_uint32 req_output_size,
154 OM_uint32* max_input_size) override;
155 OM_uint32 delete_sec_context(OM_uint32* minor_status,
156 gss_ctx_id_t* context_handle,
157 gss_buffer_t output_token) override;
158 OM_uint32 inquire_context(OM_uint32* minor_status,
159 const gss_ctx_id_t context_handle,
160 gss_name_t* src_name,
161 gss_name_t* targ_name,
162 OM_uint32* lifetime_rec,
163 gss_OID* mech_type,
164 OM_uint32* ctx_flags,
165 int* locally_initiated,
166 int* open) override;
168 private:
169 FRIEND_TEST_ALL_PREFIXES(HttpAuthGSSAPIPOSIXTest, GSSAPICycle);
171 // |expected_security_queries| contains an ordered list of expected
172 // |init_sec_context()| calls and the return values for those
173 // calls.
174 std::list<SecurityContextQuery> expected_security_queries_;
177 } // namespace test
179 } // namespace net
181 #endif // NET_HTTP_MOCK_GSSAPI_LIBRARY_POSIX_H_