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

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

Issue 1128043007: Support Kerberos on Android (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix cbentzel@'s nits Created 5 years, 5 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
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 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
64 const_cast<char*>(kInitialAuthResponse)}; 64 const_cast<char*>(kInitialAuthResponse)};
65 library->ExpectSecurityContext( 65 library->ExpectSecurityContext(
66 "Negotiate", 66 "Negotiate",
67 GSS_S_CONTINUE_NEEDED, 67 GSS_S_CONTINUE_NEEDED,
68 0, 68 0,
69 context_info, 69 context_info,
70 in_buffer, 70 in_buffer,
71 out_buffer); 71 out_buffer);
72 } 72 }
73 73
74 void UnexpectedCallback(int result) {
75 // At present getting tokens from gssapi is fully synchronous, so the callback
76 // should never be called.
77 ADD_FAILURE();
78 }
79
74 } // namespace 80 } // namespace
75 81
76 TEST(HttpAuthGSSAPIPOSIXTest, GSSAPIStartup) { 82 TEST(HttpAuthGSSAPIPOSIXTest, GSSAPIStartup) {
77 // TODO(ahendrickson): Manipulate the libraries and paths to test each of the 83 // TODO(ahendrickson): Manipulate the libraries and paths to test each of the
78 // libraries we expect, and also whether or not they have the interface 84 // libraries we expect, and also whether or not they have the interface
79 // functions we want. 85 // functions we want.
80 scoped_ptr<GSSAPILibrary> gssapi(new GSSAPISharedLibrary(std::string())); 86 scoped_ptr<GSSAPILibrary> gssapi(new GSSAPISharedLibrary(std::string()));
81 DCHECK(gssapi.get()); 87 DCHECK(gssapi.get());
82 EXPECT_TRUE(gssapi.get()->Init()); 88 EXPECT_TRUE(gssapi.get()->Init());
83 } 89 }
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
197 std::string first_challenge_text = "Negotiate"; 203 std::string first_challenge_text = "Negotiate";
198 HttpAuthChallengeTokenizer first_challenge(first_challenge_text.begin(), 204 HttpAuthChallengeTokenizer first_challenge(first_challenge_text.begin(),
199 first_challenge_text.end()); 205 first_challenge_text.end());
200 EXPECT_EQ(HttpAuth::AUTHORIZATION_RESULT_ACCEPT, 206 EXPECT_EQ(HttpAuth::AUTHORIZATION_RESULT_ACCEPT,
201 auth_gssapi.ParseChallenge(&first_challenge)); 207 auth_gssapi.ParseChallenge(&first_challenge));
202 208
203 // Generate an auth token and create another thing. 209 // Generate an auth token and create another thing.
204 EstablishInitialContext(&mock_library); 210 EstablishInitialContext(&mock_library);
205 std::string auth_token; 211 std::string auth_token;
206 EXPECT_EQ(OK, auth_gssapi.GenerateAuthToken(NULL, "HTTP/intranet.google.com", 212 EXPECT_EQ(OK, auth_gssapi.GenerateAuthToken(NULL, "HTTP/intranet.google.com",
207 &auth_token)); 213 &auth_token,
214 base::Bind(&UnexpectedCallback)));
208 215
209 std::string second_challenge_text = "Negotiate Zm9vYmFy"; 216 std::string second_challenge_text = "Negotiate Zm9vYmFy";
210 HttpAuthChallengeTokenizer second_challenge(second_challenge_text.begin(), 217 HttpAuthChallengeTokenizer second_challenge(second_challenge_text.begin(),
211 second_challenge_text.end()); 218 second_challenge_text.end());
212 EXPECT_EQ(HttpAuth::AUTHORIZATION_RESULT_ACCEPT, 219 EXPECT_EQ(HttpAuth::AUTHORIZATION_RESULT_ACCEPT,
213 auth_gssapi.ParseChallenge(&second_challenge)); 220 auth_gssapi.ParseChallenge(&second_challenge));
214 } 221 }
215 222
216 TEST(HttpAuthGSSAPITest, ParseChallenge_UnexpectedTokenFirstRound) { 223 TEST(HttpAuthGSSAPITest, ParseChallenge_UnexpectedTokenFirstRound) {
217 // If the first round challenge has an additional authentication token, it 224 // If the first round challenge has an additional authentication token, it
(...skipping 16 matching lines...) Expand all
234 CHROME_GSS_SPNEGO_MECH_OID_DESC); 241 CHROME_GSS_SPNEGO_MECH_OID_DESC);
235 std::string first_challenge_text = "Negotiate"; 242 std::string first_challenge_text = "Negotiate";
236 HttpAuthChallengeTokenizer first_challenge(first_challenge_text.begin(), 243 HttpAuthChallengeTokenizer first_challenge(first_challenge_text.begin(),
237 first_challenge_text.end()); 244 first_challenge_text.end());
238 EXPECT_EQ(HttpAuth::AUTHORIZATION_RESULT_ACCEPT, 245 EXPECT_EQ(HttpAuth::AUTHORIZATION_RESULT_ACCEPT,
239 auth_gssapi.ParseChallenge(&first_challenge)); 246 auth_gssapi.ParseChallenge(&first_challenge));
240 247
241 EstablishInitialContext(&mock_library); 248 EstablishInitialContext(&mock_library);
242 std::string auth_token; 249 std::string auth_token;
243 EXPECT_EQ(OK, auth_gssapi.GenerateAuthToken(NULL, "HTTP/intranet.google.com", 250 EXPECT_EQ(OK, auth_gssapi.GenerateAuthToken(NULL, "HTTP/intranet.google.com",
244 &auth_token)); 251 &auth_token,
252 base::Bind(&UnexpectedCallback)));
245 std::string second_challenge_text = "Negotiate"; 253 std::string second_challenge_text = "Negotiate";
246 HttpAuthChallengeTokenizer second_challenge(second_challenge_text.begin(), 254 HttpAuthChallengeTokenizer second_challenge(second_challenge_text.begin(),
247 second_challenge_text.end()); 255 second_challenge_text.end());
248 EXPECT_EQ(HttpAuth::AUTHORIZATION_RESULT_REJECT, 256 EXPECT_EQ(HttpAuth::AUTHORIZATION_RESULT_REJECT,
249 auth_gssapi.ParseChallenge(&second_challenge)); 257 auth_gssapi.ParseChallenge(&second_challenge));
250 } 258 }
251 259
252 TEST(HttpAuthGSSAPITest, ParseChallenge_NonBase64EncodedToken) { 260 TEST(HttpAuthGSSAPITest, ParseChallenge_NonBase64EncodedToken) {
253 // 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
254 // be treated as an invalid challenge. 262 // be treated as an invalid challenge.
255 test::MockGSSAPILibrary mock_library; 263 test::MockGSSAPILibrary mock_library;
256 HttpAuthGSSAPI auth_gssapi(&mock_library, "Negotiate", 264 HttpAuthGSSAPI auth_gssapi(&mock_library, "Negotiate",
257 CHROME_GSS_SPNEGO_MECH_OID_DESC); 265 CHROME_GSS_SPNEGO_MECH_OID_DESC);
258 std::string first_challenge_text = "Negotiate"; 266 std::string first_challenge_text = "Negotiate";
259 HttpAuthChallengeTokenizer first_challenge(first_challenge_text.begin(), 267 HttpAuthChallengeTokenizer first_challenge(first_challenge_text.begin(),
260 first_challenge_text.end()); 268 first_challenge_text.end());
261 EXPECT_EQ(HttpAuth::AUTHORIZATION_RESULT_ACCEPT, 269 EXPECT_EQ(HttpAuth::AUTHORIZATION_RESULT_ACCEPT,
262 auth_gssapi.ParseChallenge(&first_challenge)); 270 auth_gssapi.ParseChallenge(&first_challenge));
263 271
264 EstablishInitialContext(&mock_library); 272 EstablishInitialContext(&mock_library);
265 std::string auth_token; 273 std::string auth_token;
266 EXPECT_EQ(OK, auth_gssapi.GenerateAuthToken(NULL, "HTTP/intranet.google.com", 274 EXPECT_EQ(OK, auth_gssapi.GenerateAuthToken(NULL, "HTTP/intranet.google.com",
267 &auth_token)); 275 &auth_token,
276 base::Bind(&UnexpectedCallback)));
268 std::string second_challenge_text = "Negotiate =happyjoy="; 277 std::string second_challenge_text = "Negotiate =happyjoy=";
269 HttpAuthChallengeTokenizer second_challenge(second_challenge_text.begin(), 278 HttpAuthChallengeTokenizer second_challenge(second_challenge_text.begin(),
270 second_challenge_text.end()); 279 second_challenge_text.end());
271 EXPECT_EQ(HttpAuth::AUTHORIZATION_RESULT_INVALID, 280 EXPECT_EQ(HttpAuth::AUTHORIZATION_RESULT_INVALID,
272 auth_gssapi.ParseChallenge(&second_challenge)); 281 auth_gssapi.ParseChallenge(&second_challenge));
273 } 282 }
274 283
275 } // namespace net 284 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698