Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(72)

Side by Side Diff: net/http/http_auth_gssapi_posix_unittest.cc

Issue 1383613002: [net/http auth] Cleanup. Method names, and constness. Base URL: https://chromium.googlesource.com/chromium/src.git@mock-auth-handler-generalization
Patch Set: Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « net/http/http_auth_gssapi_posix.cc ('k') | net/http/http_auth_handler.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 #include "net/http/http_auth_gssapi_posix.h" 5 #include "net/http/http_auth_gssapi_posix.h"
6 6
7 #include "base/basictypes.h" 7 #include "base/basictypes.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/memory/scoped_ptr.h" 9 #include "base/memory/scoped_ptr.h"
10 #include "base/native_library.h" 10 #include "base/native_library.h"
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after
184 184
185 TEST(HttpAuthGSSAPITest, ParseChallenge_FirstRound) { 185 TEST(HttpAuthGSSAPITest, ParseChallenge_FirstRound) {
186 // The first round should just consist of an unadorned "Negotiate" header. 186 // The first round should just consist of an unadorned "Negotiate" header.
187 test::MockGSSAPILibrary mock_library; 187 test::MockGSSAPILibrary mock_library;
188 HttpAuthGSSAPI auth_gssapi(&mock_library, "negotiate", 188 HttpAuthGSSAPI auth_gssapi(&mock_library, "negotiate",
189 CHROME_GSS_SPNEGO_MECH_OID_DESC); 189 CHROME_GSS_SPNEGO_MECH_OID_DESC);
190 std::string challenge_text = "Negotiate"; 190 std::string challenge_text = "Negotiate";
191 HttpAuthChallengeTokenizer challenge(challenge_text.begin(), 191 HttpAuthChallengeTokenizer challenge(challenge_text.begin(),
192 challenge_text.end()); 192 challenge_text.end());
193 EXPECT_EQ(HttpAuth::AUTHORIZATION_RESULT_ACCEPT, 193 EXPECT_EQ(HttpAuth::AUTHORIZATION_RESULT_ACCEPT,
194 auth_gssapi.ParseChallenge(&challenge)); 194 auth_gssapi.ParseChallenge(challenge));
195 } 195 }
196 196
197 TEST(HttpAuthGSSAPITest, ParseChallenge_TwoRounds) { 197 TEST(HttpAuthGSSAPITest, ParseChallenge_TwoRounds) {
198 // The first round should just have "Negotiate", and the second round should 198 // The first round should just have "Negotiate", and the second round should
199 // have a valid base64 token associated with it. 199 // have a valid base64 token associated with it.
200 test::MockGSSAPILibrary mock_library; 200 test::MockGSSAPILibrary mock_library;
201 HttpAuthGSSAPI auth_gssapi(&mock_library, "negotiate", 201 HttpAuthGSSAPI auth_gssapi(&mock_library, "negotiate",
202 CHROME_GSS_SPNEGO_MECH_OID_DESC); 202 CHROME_GSS_SPNEGO_MECH_OID_DESC);
203 std::string first_challenge_text = "Negotiate"; 203 std::string first_challenge_text = "Negotiate";
204 HttpAuthChallengeTokenizer first_challenge(first_challenge_text.begin(), 204 HttpAuthChallengeTokenizer first_challenge(first_challenge_text.begin(),
205 first_challenge_text.end()); 205 first_challenge_text.end());
206 EXPECT_EQ(HttpAuth::AUTHORIZATION_RESULT_ACCEPT, 206 EXPECT_EQ(HttpAuth::AUTHORIZATION_RESULT_ACCEPT,
207 auth_gssapi.ParseChallenge(&first_challenge)); 207 auth_gssapi.ParseChallenge(first_challenge));
208 208
209 // Generate an auth token and create another thing. 209 // Generate an auth token and create another thing.
210 EstablishInitialContext(&mock_library); 210 EstablishInitialContext(&mock_library);
211 std::string auth_token; 211 std::string auth_token;
212 EXPECT_EQ(OK, auth_gssapi.GenerateAuthToken(NULL, "HTTP/intranet.google.com", 212 EXPECT_EQ(OK, auth_gssapi.GenerateAuthToken(NULL, "HTTP/intranet.google.com",
213 &auth_token, 213 &auth_token,
214 base::Bind(&UnexpectedCallback))); 214 base::Bind(&UnexpectedCallback)));
215 215
216 std::string second_challenge_text = "Negotiate Zm9vYmFy"; 216 std::string second_challenge_text = "Negotiate Zm9vYmFy";
217 HttpAuthChallengeTokenizer second_challenge(second_challenge_text.begin(), 217 HttpAuthChallengeTokenizer second_challenge(second_challenge_text.begin(),
218 second_challenge_text.end()); 218 second_challenge_text.end());
219 EXPECT_EQ(HttpAuth::AUTHORIZATION_RESULT_ACCEPT, 219 EXPECT_EQ(HttpAuth::AUTHORIZATION_RESULT_ACCEPT,
220 auth_gssapi.ParseChallenge(&second_challenge)); 220 auth_gssapi.ParseChallenge(second_challenge));
221 } 221 }
222 222
223 TEST(HttpAuthGSSAPITest, ParseChallenge_UnexpectedTokenFirstRound) { 223 TEST(HttpAuthGSSAPITest, ParseChallenge_UnexpectedTokenFirstRound) {
224 // If the first round challenge has an additional authentication token, it 224 // If the first round challenge has an additional authentication token, it
225 // should be treated as an invalid challenge from the server. 225 // should be treated as an invalid challenge from the server.
226 test::MockGSSAPILibrary mock_library; 226 test::MockGSSAPILibrary mock_library;
227 HttpAuthGSSAPI auth_gssapi(&mock_library, "negotiate", 227 HttpAuthGSSAPI auth_gssapi(&mock_library, "negotiate",
228 CHROME_GSS_SPNEGO_MECH_OID_DESC); 228 CHROME_GSS_SPNEGO_MECH_OID_DESC);
229 std::string challenge_text = "Negotiate Zm9vYmFy"; 229 std::string challenge_text = "Negotiate Zm9vYmFy";
230 HttpAuthChallengeTokenizer challenge(challenge_text.begin(), 230 HttpAuthChallengeTokenizer challenge(challenge_text.begin(),
231 challenge_text.end()); 231 challenge_text.end());
232 EXPECT_EQ(HttpAuth::AUTHORIZATION_RESULT_INVALID, 232 EXPECT_EQ(HttpAuth::AUTHORIZATION_RESULT_INVALID,
233 auth_gssapi.ParseChallenge(&challenge)); 233 auth_gssapi.ParseChallenge(challenge));
234 } 234 }
235 235
236 TEST(HttpAuthGSSAPITest, ParseChallenge_MissingTokenSecondRound) { 236 TEST(HttpAuthGSSAPITest, ParseChallenge_MissingTokenSecondRound) {
237 // If a later-round challenge is simply "Negotiate", it should be treated as 237 // If a later-round challenge is simply "Negotiate", it should be treated as
238 // an authentication challenge rejection from the server or proxy. 238 // an authentication challenge rejection from the server or proxy.
239 test::MockGSSAPILibrary mock_library; 239 test::MockGSSAPILibrary mock_library;
240 HttpAuthGSSAPI auth_gssapi(&mock_library, "negotiate", 240 HttpAuthGSSAPI auth_gssapi(&mock_library, "negotiate",
241 CHROME_GSS_SPNEGO_MECH_OID_DESC); 241 CHROME_GSS_SPNEGO_MECH_OID_DESC);
242 std::string first_challenge_text = "Negotiate"; 242 std::string first_challenge_text = "Negotiate";
243 HttpAuthChallengeTokenizer first_challenge(first_challenge_text.begin(), 243 HttpAuthChallengeTokenizer first_challenge(first_challenge_text.begin(),
244 first_challenge_text.end()); 244 first_challenge_text.end());
245 EXPECT_EQ(HttpAuth::AUTHORIZATION_RESULT_ACCEPT, 245 EXPECT_EQ(HttpAuth::AUTHORIZATION_RESULT_ACCEPT,
246 auth_gssapi.ParseChallenge(&first_challenge)); 246 auth_gssapi.ParseChallenge(first_challenge));
247 247
248 EstablishInitialContext(&mock_library); 248 EstablishInitialContext(&mock_library);
249 std::string auth_token; 249 std::string auth_token;
250 EXPECT_EQ(OK, auth_gssapi.GenerateAuthToken(NULL, "HTTP/intranet.google.com", 250 EXPECT_EQ(OK, auth_gssapi.GenerateAuthToken(NULL, "HTTP/intranet.google.com",
251 &auth_token, 251 &auth_token,
252 base::Bind(&UnexpectedCallback))); 252 base::Bind(&UnexpectedCallback)));
253 std::string second_challenge_text = "Negotiate"; 253 std::string second_challenge_text = "Negotiate";
254 HttpAuthChallengeTokenizer second_challenge(second_challenge_text.begin(), 254 HttpAuthChallengeTokenizer second_challenge(second_challenge_text.begin(),
255 second_challenge_text.end()); 255 second_challenge_text.end());
256 EXPECT_EQ(HttpAuth::AUTHORIZATION_RESULT_REJECT, 256 EXPECT_EQ(HttpAuth::AUTHORIZATION_RESULT_REJECT,
257 auth_gssapi.ParseChallenge(&second_challenge)); 257 auth_gssapi.ParseChallenge(second_challenge));
258 } 258 }
259 259
260 TEST(HttpAuthGSSAPITest, ParseChallenge_NonBase64EncodedToken) { 260 TEST(HttpAuthGSSAPITest, ParseChallenge_NonBase64EncodedToken) {
261 // If a later-round challenge has an invalid base64 encoded token, it should 261 // If a later-round challenge has an invalid base64 encoded token, it should
262 // be treated as an invalid challenge. 262 // be treated as an invalid challenge.
263 test::MockGSSAPILibrary mock_library; 263 test::MockGSSAPILibrary mock_library;
264 HttpAuthGSSAPI auth_gssapi(&mock_library, "negotiate", 264 HttpAuthGSSAPI auth_gssapi(&mock_library, "negotiate",
265 CHROME_GSS_SPNEGO_MECH_OID_DESC); 265 CHROME_GSS_SPNEGO_MECH_OID_DESC);
266 std::string first_challenge_text = "Negotiate"; 266 std::string first_challenge_text = "Negotiate";
267 HttpAuthChallengeTokenizer first_challenge(first_challenge_text.begin(), 267 HttpAuthChallengeTokenizer first_challenge(first_challenge_text.begin(),
268 first_challenge_text.end()); 268 first_challenge_text.end());
269 EXPECT_EQ(HttpAuth::AUTHORIZATION_RESULT_ACCEPT, 269 EXPECT_EQ(HttpAuth::AUTHORIZATION_RESULT_ACCEPT,
270 auth_gssapi.ParseChallenge(&first_challenge)); 270 auth_gssapi.ParseChallenge(first_challenge));
271 271
272 EstablishInitialContext(&mock_library); 272 EstablishInitialContext(&mock_library);
273 std::string auth_token; 273 std::string auth_token;
274 EXPECT_EQ(OK, auth_gssapi.GenerateAuthToken(NULL, "HTTP/intranet.google.com", 274 EXPECT_EQ(OK, auth_gssapi.GenerateAuthToken(NULL, "HTTP/intranet.google.com",
275 &auth_token, 275 &auth_token,
276 base::Bind(&UnexpectedCallback))); 276 base::Bind(&UnexpectedCallback)));
277 std::string second_challenge_text = "Negotiate =happyjoy="; 277 std::string second_challenge_text = "Negotiate =happyjoy=";
278 HttpAuthChallengeTokenizer second_challenge(second_challenge_text.begin(), 278 HttpAuthChallengeTokenizer second_challenge(second_challenge_text.begin(),
279 second_challenge_text.end()); 279 second_challenge_text.end());
280 EXPECT_EQ(HttpAuth::AUTHORIZATION_RESULT_INVALID, 280 EXPECT_EQ(HttpAuth::AUTHORIZATION_RESULT_INVALID,
281 auth_gssapi.ParseChallenge(&second_challenge)); 281 auth_gssapi.ParseChallenge(second_challenge));
282 } 282 }
283 283
284 } // namespace net 284 } // namespace net
OLDNEW
« no previous file with comments | « net/http/http_auth_gssapi_posix.cc ('k') | net/http/http_auth_handler.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698