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