OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef NET_HTTP_MOCK_GSSAPI_LIBRARY_POSIX_H_ | 5 #ifndef NET_HTTP_MOCK_GSSAPI_LIBRARY_POSIX_H_ |
6 #define NET_HTTP_MOCK_GSSAPI_LIBRARY_POSIX_H_ | 6 #define NET_HTTP_MOCK_GSSAPI_LIBRARY_POSIX_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include <list> | 9 #include <list> |
10 #include <string> | 10 #include <string> |
(...skipping 27 matching lines...) Expand all Loading... |
38 gss_OID_desc mech_type; | 38 gss_OID_desc mech_type; |
39 OM_uint32 ctx_flags; | 39 OM_uint32 ctx_flags; |
40 int locally_initiated; | 40 int locally_initiated; |
41 int open; | 41 int open; |
42 }; | 42 }; |
43 | 43 |
44 // The MockGSSAPILibrary class is intended for unit tests which want to bypass | 44 // The MockGSSAPILibrary class is intended for unit tests which want to bypass |
45 // the system GSSAPI library calls. | 45 // the system GSSAPI library calls. |
46 class MockGSSAPILibrary : public GSSAPILibrary { | 46 class MockGSSAPILibrary : public GSSAPILibrary { |
47 public: | 47 public: |
| 48 // Unit tests need access to this. "Friend"ing didn't help. |
| 49 struct SecurityContextQuery { |
| 50 std::string expected_package; |
| 51 OM_uint32 response_code; |
| 52 OM_uint32 minor_response_code; |
| 53 test::GssContextMockImpl context_info; |
| 54 gss_buffer_desc expected_input_token; |
| 55 gss_buffer_desc output_token; |
| 56 }; |
48 | 57 |
49 MockGSSAPILibrary(); | 58 MockGSSAPILibrary(); |
50 virtual ~MockGSSAPILibrary(); | 59 virtual ~MockGSSAPILibrary(); |
51 | 60 |
| 61 // Establishes an expectation for a |init_sec_context()| call. |
| 62 // |
| 63 // Each expectation established by |ExpectSecurityContext()| must be |
| 64 // matched by a call to |init_sec_context()| during the lifetime of |
| 65 // the MockGSSAPILibrary. The |expected_package| argument must equal the |
| 66 // value associated with the |target_name| argument to |init_sec_context()| |
| 67 // for there to be a match. The expectations also establish an explicit |
| 68 // ordering. |
| 69 // |
| 70 // For example, this sequence will be successful. |
| 71 // MockGSSAPILibrary lib; |
| 72 // lib.ExpectSecurityContext("NTLM", ...) |
| 73 // lib.ExpectSecurityContext("Negotiate", ...) |
| 74 // lib.init_sec_context("NTLM", ...) |
| 75 // lib.init_sec_context("Negotiate", ...) |
| 76 // |
| 77 // This sequence will fail since the queries do not occur in the order |
| 78 // established by the expectations. |
| 79 // MockGSSAPILibrary lib; |
| 80 // lib.ExpectSecurityContext("NTLM", ...) |
| 81 // lib.ExpectSecurityContext("Negotiate", ...) |
| 82 // lib.init_sec_context("Negotiate", ...) |
| 83 // lib.init_sec_context("NTLM", ...) |
| 84 // |
| 85 // This sequence will fail because there were not enough queries. |
| 86 // MockGSSAPILibrary lib; |
| 87 // lib.ExpectSecurityContext("NTLM", ...) |
| 88 // lib.ExpectSecurityContext("Negotiate", ...) |
| 89 // lib.init_sec_context("NTLM", ...) |
| 90 // |
| 91 // |response_code| is used as the return value for |init_sec_context()|. |
| 92 // If |response_code| is GSS_S_COMPLETE, |
| 93 // |
| 94 // |context_info| is the expected value of the |**context_handle| in after |
| 95 // |init_sec_context()| returns. |
| 96 void ExpectSecurityContext(const std::string& expected_package, |
| 97 OM_uint32 response_code, |
| 98 OM_uint32 minor_response_code, |
| 99 const test::GssContextMockImpl& context_info, |
| 100 const gss_buffer_desc& expected_input_token, |
| 101 const gss_buffer_desc& output_token); |
| 102 |
52 // GSSAPILibrary methods: | 103 // GSSAPILibrary methods: |
53 | 104 |
54 // Initializes the library, including any necessary dynamic libraries. | 105 // Initializes the library, including any necessary dynamic libraries. |
55 // This is done separately from construction (which happens at startup time) | 106 // This is done separately from construction (which happens at startup time) |
56 // in order to delay work until the class is actually needed. | 107 // in order to delay work until the class is actually needed. |
57 virtual bool Init(); | 108 virtual bool Init(); |
58 | 109 |
59 // These methods match the ones in the GSSAPI library. | 110 // These methods match the ones in the GSSAPI library. |
60 virtual OM_uint32 import_name( | 111 virtual OM_uint32 import_name( |
61 OM_uint32* minor_status, | 112 OM_uint32* minor_status, |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
109 OM_uint32* minor_status, | 160 OM_uint32* minor_status, |
110 const gss_ctx_id_t context_handle, | 161 const gss_ctx_id_t context_handle, |
111 gss_name_t* src_name, | 162 gss_name_t* src_name, |
112 gss_name_t* targ_name, | 163 gss_name_t* targ_name, |
113 OM_uint32* lifetime_rec, | 164 OM_uint32* lifetime_rec, |
114 gss_OID* mech_type, | 165 gss_OID* mech_type, |
115 OM_uint32* ctx_flags, | 166 OM_uint32* ctx_flags, |
116 int* locally_initiated, | 167 int* locally_initiated, |
117 int* open); | 168 int* open); |
118 | 169 |
119 // Establishes an expectation for a |init_sec_context()| call. | |
120 // | |
121 // Each expectation established by |ExpectSecurityContext()| must be | |
122 // matched by a call to |init_sec_context()| during the lifetime of | |
123 // the MockGSSAPILibrary. The |expected_package| argument must equal the | |
124 // value associated with the |target_name| argument to |init_sec_context()| | |
125 // for there to be a match. The expectations also establish an explicit | |
126 // ordering. | |
127 // | |
128 // For example, this sequence will be successful. | |
129 // MockGSSAPILibrary lib; | |
130 // lib.ExpectSecurityContext("NTLM", ...) | |
131 // lib.ExpectSecurityContext("Negotiate", ...) | |
132 // lib.init_sec_context("NTLM", ...) | |
133 // lib.init_sec_context("Negotiate", ...) | |
134 // | |
135 // This sequence will fail since the queries do not occur in the order | |
136 // established by the expectations. | |
137 // MockGSSAPILibrary lib; | |
138 // lib.ExpectSecurityContext("NTLM", ...) | |
139 // lib.ExpectSecurityContext("Negotiate", ...) | |
140 // lib.init_sec_context("Negotiate", ...) | |
141 // lib.init_sec_context("NTLM", ...) | |
142 // | |
143 // This sequence will fail because there were not enough queries. | |
144 // MockGSSAPILibrary lib; | |
145 // lib.ExpectSecurityContext("NTLM", ...) | |
146 // lib.ExpectSecurityContext("Negotiate", ...) | |
147 // lib.init_sec_context("NTLM", ...) | |
148 // | |
149 // |response_code| is used as the return value for |init_sec_context()|. | |
150 // If |response_code| is GSS_S_COMPLETE, | |
151 // | |
152 // |context_info| is the expected value of the |**context_handle| in after | |
153 // |init_sec_context()| returns. | |
154 void ExpectSecurityContext(const std::string& expected_package, | |
155 OM_uint32 response_code, | |
156 OM_uint32 minor_response_code, | |
157 const test::GssContextMockImpl& context_info, | |
158 const gss_buffer_desc& expected_input_token, | |
159 const gss_buffer_desc& output_token); | |
160 | |
161 // Unit tests need access to this. "Friend"ing didn't help. | |
162 struct SecurityContextQuery { | |
163 std::string expected_package; | |
164 OM_uint32 response_code; | |
165 OM_uint32 minor_response_code; | |
166 test::GssContextMockImpl context_info; | |
167 gss_buffer_desc expected_input_token; | |
168 gss_buffer_desc output_token; | |
169 }; | |
170 | |
171 private: | 170 private: |
172 FRIEND_TEST_ALL_PREFIXES(HttpAuthGSSAPIPOSIXTest, GSSAPICycle); | 171 FRIEND_TEST_ALL_PREFIXES(HttpAuthGSSAPIPOSIXTest, GSSAPICycle); |
173 | 172 |
174 // |expected_security_queries| contains an ordered list of expected | 173 // |expected_security_queries| contains an ordered list of expected |
175 // |init_sec_context()| calls and the return values for those | 174 // |init_sec_context()| calls and the return values for those |
176 // calls. | 175 // calls. |
177 std::list<SecurityContextQuery> expected_security_queries_; | 176 std::list<SecurityContextQuery> expected_security_queries_; |
178 }; | 177 }; |
179 | 178 |
180 } // namespace test | 179 } // namespace test |
181 | 180 |
182 } // namespace net | 181 } // namespace net |
183 | 182 |
184 #endif // NET_HTTP_MOCK_GSSAPI_LIBRARY_POSIX_H_ | 183 #endif // NET_HTTP_MOCK_GSSAPI_LIBRARY_POSIX_H_ |
185 | 184 |
OLD | NEW |