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_
11 #include "base/gtest_prod_util.h"
12 #include "net/http/http_auth_gssapi_posix.h"
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>
28 class 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
,
37 int locally_initiated
,
39 ~GssContextMockImpl();
41 void Assign(const GssContextMockImpl
& other
);
44 std::string targ_name
;
45 OM_uint32 lifetime_rec
;
46 gss_OID_desc mech_type
;
48 int locally_initiated
;
52 // The MockGSSAPILibrary class is intended for unit tests which want to bypass
53 // the system GSSAPI library calls.
54 class MockGSSAPILibrary
: public GSSAPILibrary
{
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();
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
;
76 ~MockGSSAPILibrary() override
;
78 // Establishes an expectation for a |init_sec_context()| call.
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
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", ...)
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", ...)
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", ...)
108 // |response_code| is used as the return value for |init_sec_context()|.
109 // If |response_code| is GSS_S_COMPLETE,
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
);
120 // GSSAPILibrary methods:
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
;
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
,
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
,
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
,
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
,
174 OM_uint32
* ctx_flags
,
175 int* locally_initiated
,
179 FRIEND_TEST_ALL_PREFIXES(HttpAuthGSSAPIPOSIXTest
, GSSAPICycle
);
181 // |expected_security_queries| contains an ordered list of expected
182 // |init_sec_context()| calls and the return values for those
184 std::list
<SecurityContextQuery
> expected_security_queries_
;
191 #endif // NET_HTTP_MOCK_GSSAPI_LIBRARY_POSIX_H_