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

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

Issue 8340026: Use AuthCredentials throughout the network stack instead of username/password. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: mac compile fix Created 9 years, 1 month 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) 2011 The Chromium Authors. All rights reserved. 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 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 184 matching lines...) Expand 10 before | Expand all | Expand 10 after
195 CHROME_GSS_KRB5_MECH_OID_DESC); 195 CHROME_GSS_KRB5_MECH_OID_DESC);
196 std::string first_challenge_text = "Negotiate"; 196 std::string first_challenge_text = "Negotiate";
197 HttpAuth::ChallengeTokenizer first_challenge(first_challenge_text.begin(), 197 HttpAuth::ChallengeTokenizer first_challenge(first_challenge_text.begin(),
198 first_challenge_text.end()); 198 first_challenge_text.end());
199 EXPECT_EQ(HttpAuth::AUTHORIZATION_RESULT_ACCEPT, 199 EXPECT_EQ(HttpAuth::AUTHORIZATION_RESULT_ACCEPT,
200 auth_gssapi.ParseChallenge(&first_challenge)); 200 auth_gssapi.ParseChallenge(&first_challenge));
201 201
202 // Generate an auth token and create another thing. 202 // Generate an auth token and create another thing.
203 EstablishInitialContext(&mock_library); 203 EstablishInitialContext(&mock_library);
204 std::string auth_token; 204 std::string auth_token;
205 EXPECT_EQ(OK, auth_gssapi.GenerateAuthToken(NULL, NULL, 205 EXPECT_EQ(OK, auth_gssapi.GenerateAuthToken(NULL, L"HTTP/intranet.google.com",
206 L"HTTP/intranet.google.com",
207 &auth_token)); 206 &auth_token));
208 207
209 std::string second_challenge_text = "Negotiate Zm9vYmFy"; 208 std::string second_challenge_text = "Negotiate Zm9vYmFy";
210 HttpAuth::ChallengeTokenizer second_challenge(second_challenge_text.begin(), 209 HttpAuth::ChallengeTokenizer second_challenge(second_challenge_text.begin(),
211 second_challenge_text.end()); 210 second_challenge_text.end());
212 EXPECT_EQ(HttpAuth::AUTHORIZATION_RESULT_ACCEPT, 211 EXPECT_EQ(HttpAuth::AUTHORIZATION_RESULT_ACCEPT,
213 auth_gssapi.ParseChallenge(&second_challenge)); 212 auth_gssapi.ParseChallenge(&second_challenge));
214 } 213 }
215 214
216 TEST(HttpAuthGSSAPITest, ParseChallenge_UnexpectedTokenFirstRound) { 215 TEST(HttpAuthGSSAPITest, ParseChallenge_UnexpectedTokenFirstRound) {
(...skipping 16 matching lines...) Expand all
233 HttpAuthGSSAPI auth_gssapi(&mock_library, "Negotiate", 232 HttpAuthGSSAPI auth_gssapi(&mock_library, "Negotiate",
234 CHROME_GSS_KRB5_MECH_OID_DESC); 233 CHROME_GSS_KRB5_MECH_OID_DESC);
235 std::string first_challenge_text = "Negotiate"; 234 std::string first_challenge_text = "Negotiate";
236 HttpAuth::ChallengeTokenizer first_challenge(first_challenge_text.begin(), 235 HttpAuth::ChallengeTokenizer first_challenge(first_challenge_text.begin(),
237 first_challenge_text.end()); 236 first_challenge_text.end());
238 EXPECT_EQ(HttpAuth::AUTHORIZATION_RESULT_ACCEPT, 237 EXPECT_EQ(HttpAuth::AUTHORIZATION_RESULT_ACCEPT,
239 auth_gssapi.ParseChallenge(&first_challenge)); 238 auth_gssapi.ParseChallenge(&first_challenge));
240 239
241 EstablishInitialContext(&mock_library); 240 EstablishInitialContext(&mock_library);
242 std::string auth_token; 241 std::string auth_token;
243 EXPECT_EQ(OK, auth_gssapi.GenerateAuthToken(NULL, NULL, 242 EXPECT_EQ(OK, auth_gssapi.GenerateAuthToken(NULL, L"HTTP/intranet.google.com",
244 L"HTTP/intranet.google.com",
245 &auth_token)); 243 &auth_token));
246 std::string second_challenge_text = "Negotiate"; 244 std::string second_challenge_text = "Negotiate";
247 HttpAuth::ChallengeTokenizer second_challenge(second_challenge_text.begin(), 245 HttpAuth::ChallengeTokenizer second_challenge(second_challenge_text.begin(),
248 second_challenge_text.end()); 246 second_challenge_text.end());
249 EXPECT_EQ(HttpAuth::AUTHORIZATION_RESULT_REJECT, 247 EXPECT_EQ(HttpAuth::AUTHORIZATION_RESULT_REJECT,
250 auth_gssapi.ParseChallenge(&second_challenge)); 248 auth_gssapi.ParseChallenge(&second_challenge));
251 } 249 }
252 250
253 TEST(HttpAuthGSSAPITest, ParseChallenge_NonBase64EncodedToken) { 251 TEST(HttpAuthGSSAPITest, ParseChallenge_NonBase64EncodedToken) {
254 // If a later-round challenge has an invalid base64 encoded token, it should 252 // If a later-round challenge has an invalid base64 encoded token, it should
255 // be treated as an invalid challenge. 253 // be treated as an invalid challenge.
256 test::MockGSSAPILibrary mock_library; 254 test::MockGSSAPILibrary mock_library;
257 HttpAuthGSSAPI auth_gssapi(&mock_library, "Negotiate", 255 HttpAuthGSSAPI auth_gssapi(&mock_library, "Negotiate",
258 CHROME_GSS_KRB5_MECH_OID_DESC); 256 CHROME_GSS_KRB5_MECH_OID_DESC);
259 std::string first_challenge_text = "Negotiate"; 257 std::string first_challenge_text = "Negotiate";
260 HttpAuth::ChallengeTokenizer first_challenge(first_challenge_text.begin(), 258 HttpAuth::ChallengeTokenizer first_challenge(first_challenge_text.begin(),
261 first_challenge_text.end()); 259 first_challenge_text.end());
262 EXPECT_EQ(HttpAuth::AUTHORIZATION_RESULT_ACCEPT, 260 EXPECT_EQ(HttpAuth::AUTHORIZATION_RESULT_ACCEPT,
263 auth_gssapi.ParseChallenge(&first_challenge)); 261 auth_gssapi.ParseChallenge(&first_challenge));
264 262
265 EstablishInitialContext(&mock_library); 263 EstablishInitialContext(&mock_library);
266 std::string auth_token; 264 std::string auth_token;
267 EXPECT_EQ(OK, auth_gssapi.GenerateAuthToken(NULL, NULL, 265 EXPECT_EQ(OK, auth_gssapi.GenerateAuthToken(NULL, L"HTTP/intranet.google.com",
268 L"HTTP/intranet.google.com",
269 &auth_token)); 266 &auth_token));
270 std::string second_challenge_text = "Negotiate =happyjoy="; 267 std::string second_challenge_text = "Negotiate =happyjoy=";
271 HttpAuth::ChallengeTokenizer second_challenge(second_challenge_text.begin(), 268 HttpAuth::ChallengeTokenizer second_challenge(second_challenge_text.begin(),
272 second_challenge_text.end()); 269 second_challenge_text.end());
273 EXPECT_EQ(HttpAuth::AUTHORIZATION_RESULT_INVALID, 270 EXPECT_EQ(HttpAuth::AUTHORIZATION_RESULT_INVALID,
274 auth_gssapi.ParseChallenge(&second_challenge)); 271 auth_gssapi.ParseChallenge(&second_challenge));
275 } 272 }
276 273
277 } // namespace net 274 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698