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

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: Deal with comments and build and test failures. 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 EnsureSpnegoTestAccountExists();
18
19 std::string auth_token;
20
21 HttpAuthNegotiateAndroid auth("org.chromium.test.DummySpnegoAuthenticator");
22 EXPECT_TRUE(auth.Init());
23
24 TestCompletionCallback callback;
25 EXPECT_EQ(ERR_IO_PENDING,
26 auth.GenerateAuthToken(nullptr, "Dummy", &auth_token,
27 callback.callback()));
28
29 callback.WaitForResult();
30 EXPECT_EQ("Negotiate DummyToken", auth_token);
31
32 RemoveSpnegoTestAccounts();
33 }
34
35 TEST(HttpAuthNegotiateAndroidTest, ParseChallenge_FirstRound) {
36 // The first round should just consist of an unadorned "Negotiate" header.
37 HttpAuthNegotiateAndroid auth("org.chromium.test.DummySpnegoAuthenticator");
38 std::string challenge_text = "Negotiate";
39 HttpAuthChallengeTokenizer challenge(challenge_text.begin(),
40 challenge_text.end());
41 EXPECT_EQ(HttpAuth::AUTHORIZATION_RESULT_ACCEPT,
42 auth.ParseChallenge(&challenge));
43 }
44
45 TEST(HttpAuthNegotiateAndroidTest, ParseChallenge_UnexpectedTokenFirstRound) {
46 // If the first round challenge has an additional authentication token, it
47 // should be treated as an invalid challenge from the server.
48 HttpAuthNegotiateAndroid auth("org.chromium.test.DummySpnegoAuthenticator");
49 std::string challenge_text = "Negotiate Zm9vYmFy";
50 HttpAuthChallengeTokenizer challenge(challenge_text.begin(),
51 challenge_text.end());
52 EXPECT_EQ(HttpAuth::AUTHORIZATION_RESULT_INVALID,
53 auth.ParseChallenge(&challenge));
54 }
55
56 TEST(HttpAuthNegotiateAndroidTest, ParseChallenge_TwoRounds) {
57 // The first round should just have "Negotiate", and the second round should
58 // have a valid base64 token associated with it.
59 HttpAuthNegotiateAndroid auth("org.chromium.test.DummySpnegoAuthenticator");
60 std::string first_challenge_text = "Negotiate";
61 HttpAuthChallengeTokenizer first_challenge(first_challenge_text.begin(),
62 first_challenge_text.end());
63 EXPECT_EQ(HttpAuth::AUTHORIZATION_RESULT_ACCEPT,
64 auth.ParseChallenge(&first_challenge));
65
66 std::string second_challenge_text = "Negotiate Zm9vYmFy";
67 HttpAuthChallengeTokenizer second_challenge(second_challenge_text.begin(),
68 second_challenge_text.end());
69 EXPECT_EQ(HttpAuth::AUTHORIZATION_RESULT_ACCEPT,
70 auth.ParseChallenge(&second_challenge));
71 }
72
73 TEST(HttpAuthNegotiateAndroidTest, ParseChallenge_MissingTokenSecondRound) {
74 // If a later-round challenge is simply "Negotiate", it should be treated as
75 // an authentication challenge rejection from the server or proxy.
76 HttpAuthNegotiateAndroid auth("org.chromium.test.DummySpnegoAuthenticator");
77 std::string first_challenge_text = "Negotiate";
78 HttpAuthChallengeTokenizer first_challenge(first_challenge_text.begin(),
79 first_challenge_text.end());
80 EXPECT_EQ(HttpAuth::AUTHORIZATION_RESULT_ACCEPT,
81 auth.ParseChallenge(&first_challenge));
82
83 std::string second_challenge_text = "Negotiate";
84 HttpAuthChallengeTokenizer second_challenge(second_challenge_text.begin(),
85 second_challenge_text.end());
86 EXPECT_EQ(HttpAuth::AUTHORIZATION_RESULT_REJECT,
87 auth.ParseChallenge(&second_challenge));
88 }
89
90 } // namespace android
91 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698