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

Side by Side Diff: net/android/http_auth_negotiate_android_unittest.cc

Issue 1128043007: Support Kerberos on Android (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix Android GN build Created 5 years, 6 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
(Empty)
1 // Copyright (c) 2014 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 #include "base/run_loop.h"
6 #include "net/android/dummy_spnego_authenticator.h"
7 #include "net/android/http_auth_negotiate_android.h"
8 #include "net/base/net_errors.h"
9 #include "net/base/test_completion_callback.h"
10 #include "net/http/http_auth_challenge_tokenizer.h"
11 #include "testing/gtest/include/gtest/gtest.h"
12
13 namespace net {
14 namespace android {
15
16 TEST(HttpAuthNegotiateAndroidTest, GenerateAuthToken) {
17 DummySpnegoAuthenticator::EnsureTestAccountExists();
18
19 std::string auth_token;
20
21 DummySpnegoAuthenticator::SetNextResult(0, "DummyToken");
22
23 HttpAuthNegotiateAndroid auth("org.chromium.test.DummySpnegoAuthenticator");
24 EXPECT_TRUE(auth.Init());
25
26 TestCompletionCallback callback;
27 EXPECT_EQ(ERR_IO_PENDING,
28 auth.GenerateAuthToken(nullptr, "Dummy", &auth_token,
29 callback.callback()));
30
31 EXPECT_EQ(OK, callback.WaitForResult());
Ryan Sleevi 2015/06/29 13:56:45 HANG BUG: Is auth.GenerateAuthToken returns a valu
aberent 2015/07/02 21:13:35 Done.
32 EXPECT_EQ("Negotiate DummyToken", auth_token);
33
34 DummySpnegoAuthenticator::RemoveTestAccounts();
35 }
36
37 TEST(HttpAuthNegotiateAndroidTest, ParseChallenge_FirstRound) {
38 // The first round should just consist of an unadorned "Negotiate" header.
39 HttpAuthNegotiateAndroid auth("org.chromium.test.DummySpnegoAuthenticator");
40 std::string challenge_text = "Negotiate";
41 HttpAuthChallengeTokenizer challenge(challenge_text.begin(),
42 challenge_text.end());
43 EXPECT_EQ(HttpAuth::AUTHORIZATION_RESULT_ACCEPT,
44 auth.ParseChallenge(&challenge));
45 }
46
47 TEST(HttpAuthNegotiateAndroidTest, ParseChallenge_UnexpectedTokenFirstRound) {
48 // If the first round challenge has an additional authentication token, it
49 // should be treated as an invalid challenge from the server.
50 HttpAuthNegotiateAndroid auth("org.chromium.test.DummySpnegoAuthenticator");
51 std::string challenge_text = "Negotiate Zm9vYmFy";
52 HttpAuthChallengeTokenizer challenge(challenge_text.begin(),
53 challenge_text.end());
54 EXPECT_EQ(HttpAuth::AUTHORIZATION_RESULT_INVALID,
55 auth.ParseChallenge(&challenge));
56 }
57
58 TEST(HttpAuthNegotiateAndroidTest, ParseChallenge_TwoRounds) {
59 // The first round should just have "Negotiate", and the second round should
60 // have a valid base64 token associated with it.
61 HttpAuthNegotiateAndroid auth("org.chromium.test.DummySpnegoAuthenticator");
62 std::string first_challenge_text = "Negotiate";
63 HttpAuthChallengeTokenizer first_challenge(first_challenge_text.begin(),
64 first_challenge_text.end());
65 EXPECT_EQ(HttpAuth::AUTHORIZATION_RESULT_ACCEPT,
66 auth.ParseChallenge(&first_challenge));
67
68 std::string second_challenge_text = "Negotiate Zm9vYmFy";
69 HttpAuthChallengeTokenizer second_challenge(second_challenge_text.begin(),
70 second_challenge_text.end());
71 EXPECT_EQ(HttpAuth::AUTHORIZATION_RESULT_ACCEPT,
72 auth.ParseChallenge(&second_challenge));
73 }
74
75 TEST(HttpAuthNegotiateAndroidTest, ParseChallenge_MissingTokenSecondRound) {
76 // If a later-round challenge is simply "Negotiate", it should be treated as
77 // an authentication challenge rejection from the server or proxy.
78 HttpAuthNegotiateAndroid auth("org.chromium.test.DummySpnegoAuthenticator");
79 std::string first_challenge_text = "Negotiate";
80 HttpAuthChallengeTokenizer first_challenge(first_challenge_text.begin(),
81 first_challenge_text.end());
82 EXPECT_EQ(HttpAuth::AUTHORIZATION_RESULT_ACCEPT,
83 auth.ParseChallenge(&first_challenge));
84
85 std::string second_challenge_text = "Negotiate";
86 HttpAuthChallengeTokenizer second_challenge(second_challenge_text.begin(),
87 second_challenge_text.end());
88 EXPECT_EQ(HttpAuth::AUTHORIZATION_RESULT_REJECT,
89 auth.ParseChallenge(&second_challenge));
90 }
91
92 } // namespace android
93 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698