Roll src/third_party/WebKit 18ea028:62591a8 (svn 201988:201989)
[chromium-blink-merge.git] / net / android / http_auth_negotiate_android_unittest.cc
blobb1e178f588d0be3c2905e868be3f3d5c5cfbb814
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.
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"
13 namespace net {
14 namespace android {
16 TEST(HttpAuthNegotiateAndroidTest, GenerateAuthToken) {
17 DummySpnegoAuthenticator::EnsureTestAccountExists();
19 std::string auth_token;
21 DummySpnegoAuthenticator authenticator;
22 net::test::GssContextMockImpl mockContext;
23 authenticator.ExpectSecurityContext("Negotiate", GSS_S_COMPLETE, 0,
24 mockContext, "", "DummyToken");
26 HttpAuthNegotiateAndroid auth("org.chromium.test.DummySpnegoAuthenticator");
27 EXPECT_TRUE(auth.Init());
29 TestCompletionCallback callback;
30 EXPECT_EQ(OK, callback.GetResult(auth.GenerateAuthToken(
31 nullptr, "Dummy", &auth_token, callback.callback())));
33 EXPECT_EQ("Negotiate DummyToken", auth_token);
35 DummySpnegoAuthenticator::RemoveTestAccounts();
38 TEST(HttpAuthNegotiateAndroidTest, ParseChallenge_FirstRound) {
39 // The first round should just consist of an unadorned "Negotiate" header.
40 HttpAuthNegotiateAndroid auth("org.chromium.test.DummySpnegoAuthenticator");
41 std::string challenge_text = "Negotiate";
42 HttpAuthChallengeTokenizer challenge(challenge_text.begin(),
43 challenge_text.end());
44 EXPECT_EQ(HttpAuth::AUTHORIZATION_RESULT_ACCEPT,
45 auth.ParseChallenge(&challenge));
48 TEST(HttpAuthNegotiateAndroidTest, ParseChallenge_UnexpectedTokenFirstRound) {
49 // If the first round challenge has an additional authentication token, it
50 // should be treated as an invalid challenge from the server.
51 HttpAuthNegotiateAndroid auth("org.chromium.test.DummySpnegoAuthenticator");
52 std::string challenge_text = "Negotiate Zm9vYmFy";
53 HttpAuthChallengeTokenizer challenge(challenge_text.begin(),
54 challenge_text.end());
55 EXPECT_EQ(HttpAuth::AUTHORIZATION_RESULT_INVALID,
56 auth.ParseChallenge(&challenge));
59 TEST(HttpAuthNegotiateAndroidTest, ParseChallenge_TwoRounds) {
60 // The first round should just have "Negotiate", and the second round should
61 // have a valid base64 token associated with it.
62 HttpAuthNegotiateAndroid auth("org.chromium.test.DummySpnegoAuthenticator");
63 std::string first_challenge_text = "Negotiate";
64 HttpAuthChallengeTokenizer first_challenge(first_challenge_text.begin(),
65 first_challenge_text.end());
66 EXPECT_EQ(HttpAuth::AUTHORIZATION_RESULT_ACCEPT,
67 auth.ParseChallenge(&first_challenge));
69 std::string second_challenge_text = "Negotiate Zm9vYmFy";
70 HttpAuthChallengeTokenizer second_challenge(second_challenge_text.begin(),
71 second_challenge_text.end());
72 EXPECT_EQ(HttpAuth::AUTHORIZATION_RESULT_ACCEPT,
73 auth.ParseChallenge(&second_challenge));
76 TEST(HttpAuthNegotiateAndroidTest, ParseChallenge_MissingTokenSecondRound) {
77 // If a later-round challenge is simply "Negotiate", it should be treated as
78 // an authentication challenge rejection from the server or proxy.
79 HttpAuthNegotiateAndroid auth("org.chromium.test.DummySpnegoAuthenticator");
80 std::string first_challenge_text = "Negotiate";
81 HttpAuthChallengeTokenizer first_challenge(first_challenge_text.begin(),
82 first_challenge_text.end());
83 EXPECT_EQ(HttpAuth::AUTHORIZATION_RESULT_ACCEPT,
84 auth.ParseChallenge(&first_challenge));
86 std::string second_challenge_text = "Negotiate";
87 HttpAuthChallengeTokenizer second_challenge(second_challenge_text.begin(),
88 second_challenge_text.end());
89 EXPECT_EQ(HttpAuth::AUTHORIZATION_RESULT_REJECT,
90 auth.ParseChallenge(&second_challenge));
93 } // namespace android
94 } // namespace net