OLD | NEW |
1 // Copyright (c) 2014 The Chromium Authors. All rights reserved. | 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 | 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 "base/run_loop.h" | 5 #include "base/run_loop.h" |
6 #include "net/android/dummy_spnego_authenticator.h" | 6 #include "net/android/dummy_spnego_authenticator.h" |
7 #include "net/android/http_auth_negotiate_android.h" | 7 #include "net/android/http_auth_negotiate_android.h" |
8 #include "net/base/net_errors.h" | 8 #include "net/base/net_errors.h" |
9 #include "net/base/test_completion_callback.h" | 9 #include "net/base/test_completion_callback.h" |
10 #include "net/http/http_auth_challenge_tokenizer.h" | 10 #include "net/http/http_auth_challenge_tokenizer.h" |
(...skipping 24 matching lines...) Expand all Loading... |
35 DummySpnegoAuthenticator::RemoveTestAccounts(); | 35 DummySpnegoAuthenticator::RemoveTestAccounts(); |
36 } | 36 } |
37 | 37 |
38 TEST(HttpAuthNegotiateAndroidTest, ParseChallenge_FirstRound) { | 38 TEST(HttpAuthNegotiateAndroidTest, ParseChallenge_FirstRound) { |
39 // The first round should just consist of an unadorned "Negotiate" header. | 39 // The first round should just consist of an unadorned "Negotiate" header. |
40 HttpAuthNegotiateAndroid auth("org.chromium.test.DummySpnegoAuthenticator"); | 40 HttpAuthNegotiateAndroid auth("org.chromium.test.DummySpnegoAuthenticator"); |
41 std::string challenge_text = "Negotiate"; | 41 std::string challenge_text = "Negotiate"; |
42 HttpAuthChallengeTokenizer challenge(challenge_text.begin(), | 42 HttpAuthChallengeTokenizer challenge(challenge_text.begin(), |
43 challenge_text.end()); | 43 challenge_text.end()); |
44 EXPECT_EQ(HttpAuth::AUTHORIZATION_RESULT_ACCEPT, | 44 EXPECT_EQ(HttpAuth::AUTHORIZATION_RESULT_ACCEPT, |
45 auth.ParseChallenge(&challenge)); | 45 auth.ParseChallenge(challenge)); |
46 } | 46 } |
47 | 47 |
48 TEST(HttpAuthNegotiateAndroidTest, ParseChallenge_UnexpectedTokenFirstRound) { | 48 TEST(HttpAuthNegotiateAndroidTest, ParseChallenge_UnexpectedTokenFirstRound) { |
49 // If the first round challenge has an additional authentication token, it | 49 // If the first round challenge has an additional authentication token, it |
50 // should be treated as an invalid challenge from the server. | 50 // should be treated as an invalid challenge from the server. |
51 HttpAuthNegotiateAndroid auth("org.chromium.test.DummySpnegoAuthenticator"); | 51 HttpAuthNegotiateAndroid auth("org.chromium.test.DummySpnegoAuthenticator"); |
52 std::string challenge_text = "Negotiate Zm9vYmFy"; | 52 std::string challenge_text = "Negotiate Zm9vYmFy"; |
53 HttpAuthChallengeTokenizer challenge(challenge_text.begin(), | 53 HttpAuthChallengeTokenizer challenge(challenge_text.begin(), |
54 challenge_text.end()); | 54 challenge_text.end()); |
55 EXPECT_EQ(HttpAuth::AUTHORIZATION_RESULT_INVALID, | 55 EXPECT_EQ(HttpAuth::AUTHORIZATION_RESULT_INVALID, |
56 auth.ParseChallenge(&challenge)); | 56 auth.ParseChallenge(challenge)); |
57 } | 57 } |
58 | 58 |
59 TEST(HttpAuthNegotiateAndroidTest, ParseChallenge_TwoRounds) { | 59 TEST(HttpAuthNegotiateAndroidTest, ParseChallenge_TwoRounds) { |
60 // The first round should just have "Negotiate", and the second round should | 60 // The first round should just have "Negotiate", and the second round should |
61 // have a valid base64 token associated with it. | 61 // have a valid base64 token associated with it. |
62 HttpAuthNegotiateAndroid auth("org.chromium.test.DummySpnegoAuthenticator"); | 62 HttpAuthNegotiateAndroid auth("org.chromium.test.DummySpnegoAuthenticator"); |
63 std::string first_challenge_text = "Negotiate"; | 63 std::string first_challenge_text = "Negotiate"; |
64 HttpAuthChallengeTokenizer first_challenge(first_challenge_text.begin(), | 64 HttpAuthChallengeTokenizer first_challenge(first_challenge_text.begin(), |
65 first_challenge_text.end()); | 65 first_challenge_text.end()); |
66 EXPECT_EQ(HttpAuth::AUTHORIZATION_RESULT_ACCEPT, | 66 EXPECT_EQ(HttpAuth::AUTHORIZATION_RESULT_ACCEPT, |
67 auth.ParseChallenge(&first_challenge)); | 67 auth.ParseChallenge(first_challenge)); |
68 | 68 |
69 std::string second_challenge_text = "Negotiate Zm9vYmFy"; | 69 std::string second_challenge_text = "Negotiate Zm9vYmFy"; |
70 HttpAuthChallengeTokenizer second_challenge(second_challenge_text.begin(), | 70 HttpAuthChallengeTokenizer second_challenge(second_challenge_text.begin(), |
71 second_challenge_text.end()); | 71 second_challenge_text.end()); |
72 EXPECT_EQ(HttpAuth::AUTHORIZATION_RESULT_ACCEPT, | 72 EXPECT_EQ(HttpAuth::AUTHORIZATION_RESULT_ACCEPT, |
73 auth.ParseChallenge(&second_challenge)); | 73 auth.ParseChallenge(second_challenge)); |
74 } | 74 } |
75 | 75 |
76 TEST(HttpAuthNegotiateAndroidTest, ParseChallenge_MissingTokenSecondRound) { | 76 TEST(HttpAuthNegotiateAndroidTest, ParseChallenge_MissingTokenSecondRound) { |
77 // If a later-round challenge is simply "Negotiate", it should be treated as | 77 // If a later-round challenge is simply "Negotiate", it should be treated as |
78 // an authentication challenge rejection from the server or proxy. | 78 // an authentication challenge rejection from the server or proxy. |
79 HttpAuthNegotiateAndroid auth("org.chromium.test.DummySpnegoAuthenticator"); | 79 HttpAuthNegotiateAndroid auth("org.chromium.test.DummySpnegoAuthenticator"); |
80 std::string first_challenge_text = "Negotiate"; | 80 std::string first_challenge_text = "Negotiate"; |
81 HttpAuthChallengeTokenizer first_challenge(first_challenge_text.begin(), | 81 HttpAuthChallengeTokenizer first_challenge(first_challenge_text.begin(), |
82 first_challenge_text.end()); | 82 first_challenge_text.end()); |
83 EXPECT_EQ(HttpAuth::AUTHORIZATION_RESULT_ACCEPT, | 83 EXPECT_EQ(HttpAuth::AUTHORIZATION_RESULT_ACCEPT, |
84 auth.ParseChallenge(&first_challenge)); | 84 auth.ParseChallenge(first_challenge)); |
85 | 85 |
86 std::string second_challenge_text = "Negotiate"; | 86 std::string second_challenge_text = "Negotiate"; |
87 HttpAuthChallengeTokenizer second_challenge(second_challenge_text.begin(), | 87 HttpAuthChallengeTokenizer second_challenge(second_challenge_text.begin(), |
88 second_challenge_text.end()); | 88 second_challenge_text.end()); |
89 EXPECT_EQ(HttpAuth::AUTHORIZATION_RESULT_REJECT, | 89 EXPECT_EQ(HttpAuth::AUTHORIZATION_RESULT_REJECT, |
90 auth.ParseChallenge(&second_challenge)); | 90 auth.ParseChallenge(second_challenge)); |
91 } | 91 } |
92 | 92 |
93 } // namespace android | 93 } // namespace android |
94 } // namespace net | 94 } // namespace net |
OLD | NEW |