blob: f0652d36652f8458733d6e11050e173f0972e88d [file] [log] [blame]
[email protected]3ad259a2010-07-16 17:26:471// 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.
4
5#ifndef NET_HTTP_MOCK_GSSAPI_LIBRARY_POSIX_H_
6#define NET_HTTP_MOCK_GSSAPI_LIBRARY_POSIX_H_
[email protected]32b76ef2010-07-26 23:08:247#pragma once
[email protected]3ad259a2010-07-16 17:26:478
9#include <list>
[email protected]3ad259a2010-07-16 17:26:4710#include <string>
11
12#include "base/gtest_prod_util.h"
13#include "net/http/http_auth_gssapi_posix.h"
14#include "net/third_party/gssapi/gssapi.h"
15
16namespace net {
17
18namespace test {
19
20class GssContextMockImpl {
21 public:
22 GssContextMockImpl();
23 GssContextMockImpl(const GssContextMockImpl& other);
24 GssContextMockImpl(const char* src_name,
25 const char* targ_name,
26 OM_uint32 lifetime_rec,
27 const gss_OID_desc& mech_type,
28 OM_uint32 ctx_flags,
29 int locally_initiated,
30 int open);
31 ~GssContextMockImpl();
32
33 void Assign(const GssContextMockImpl& other);
34
35 std::string src_name;
36 std::string targ_name;
37 OM_uint32 lifetime_rec;
38 gss_OID_desc mech_type;
39 OM_uint32 ctx_flags;
40 int locally_initiated;
41 int open;
42};
43
44// The MockGSSAPILibrary class is intended for unit tests which want to bypass
45// the system GSSAPI library calls.
46class MockGSSAPILibrary : public GSSAPILibrary {
47 public:
[email protected]d100e44f2011-01-26 22:47:1148 // 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 };
[email protected]3ad259a2010-07-16 17:26:4757
58 MockGSSAPILibrary();
59 virtual ~MockGSSAPILibrary();
60
[email protected]d100e44f2011-01-26 22:47:1161 // 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
[email protected]3ad259a2010-07-16 17:26:47103 // GSSAPILibrary methods:
104
105 // Initializes the library, including any necessary dynamic libraries.
106 // This is done separately from construction (which happens at startup time)
107 // in order to delay work until the class is actually needed.
108 virtual bool Init();
109
110 // These methods match the ones in the GSSAPI library.
111 virtual OM_uint32 import_name(
112 OM_uint32* minor_status,
113 const gss_buffer_t input_name_buffer,
114 const gss_OID input_name_type,
115 gss_name_t* output_name);
116 virtual OM_uint32 release_name(
117 OM_uint32* minor_status,
118 gss_name_t* input_name);
119 virtual OM_uint32 release_buffer(
120 OM_uint32* minor_status,
121 gss_buffer_t buffer);
122 virtual OM_uint32 display_name(
123 OM_uint32* minor_status,
124 const gss_name_t input_name,
125 gss_buffer_t output_name_buffer,
126 gss_OID* output_name_type);
127 virtual OM_uint32 display_status(
128 OM_uint32* minor_status,
129 OM_uint32 status_value,
130 int status_type,
131 const gss_OID mech_type,
132 OM_uint32* message_contex,
133 gss_buffer_t status_string);
134 virtual OM_uint32 init_sec_context(
135 OM_uint32* minor_status,
136 const gss_cred_id_t initiator_cred_handle,
137 gss_ctx_id_t* context_handle,
138 const gss_name_t target_name,
139 const gss_OID mech_type,
140 OM_uint32 req_flags,
141 OM_uint32 time_req,
142 const gss_channel_bindings_t input_chan_bindings,
143 const gss_buffer_t input_token,
144 gss_OID* actual_mech_type,
145 gss_buffer_t output_token,
146 OM_uint32* ret_flags,
147 OM_uint32* time_rec);
148 virtual OM_uint32 wrap_size_limit(
149 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);
155 virtual OM_uint32 delete_sec_context(
156 OM_uint32* minor_status,
157 gss_ctx_id_t* context_handle,
158 gss_buffer_t output_token);
159 virtual OM_uint32 inquire_context(
160 OM_uint32* minor_status,
161 const gss_ctx_id_t context_handle,
162 gss_name_t* src_name,
163 gss_name_t* targ_name,
164 OM_uint32* lifetime_rec,
165 gss_OID* mech_type,
166 OM_uint32* ctx_flags,
167 int* locally_initiated,
168 int* open);
169
[email protected]3ad259a2010-07-16 17:26:47170 private:
171 FRIEND_TEST_ALL_PREFIXES(HttpAuthGSSAPIPOSIXTest, GSSAPICycle);
172
173 // |expected_security_queries| contains an ordered list of expected
174 // |init_sec_context()| calls and the return values for those
175 // calls.
176 std::list<SecurityContextQuery> expected_security_queries_;
177};
178
179} // namespace test
180
181} // namespace net
182
183#endif // NET_HTTP_MOCK_GSSAPI_LIBRARY_POSIX_H_
184