OLD | NEW |
(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 authenticator; |
| 22 net::test::GssContextMockImpl mockContext; |
| 23 authenticator.ExpectSecurityContext("Negotiate", GSS_S_COMPLETE, 0, |
| 24 mockContext, "", "DummyToken"); |
| 25 |
| 26 HttpAuthNegotiateAndroid auth("org.chromium.test.DummySpnegoAuthenticator"); |
| 27 EXPECT_TRUE(auth.Init()); |
| 28 |
| 29 TestCompletionCallback callback; |
| 30 EXPECT_EQ(OK, callback.GetResult(auth.GenerateAuthToken( |
| 31 nullptr, "Dummy", &auth_token, callback.callback()))); |
| 32 |
| 33 EXPECT_EQ("Negotiate DummyToken", auth_token); |
| 34 |
| 35 DummySpnegoAuthenticator::RemoveTestAccounts(); |
| 36 } |
| 37 |
| 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)); |
| 46 } |
| 47 |
| 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)); |
| 57 } |
| 58 |
| 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)); |
| 68 |
| 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)); |
| 74 } |
| 75 |
| 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)); |
| 85 |
| 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)); |
| 91 } |
| 92 |
| 93 } // namespace android |
| 94 } // namespace net |
OLD | NEW |