Chromium Code Reviews| 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/message_loop/message_loop.h" | |
| 6 #include "base/test/test_ui_thread_android.h" | |
| 7 #include "net/android/http_android_auth_negotiate.h" | |
| 8 #include "net/base/net_errors.h" | |
| 9 #include "net/http/http_auth_challenge_tokenizer.h" | |
| 10 #include "testing/gtest/include/gtest/gtest.h" | |
| 11 | |
| 12 namespace net { | |
| 13 namespace android { | |
| 14 namespace { | |
|
Bernhard Bauer
2015/06/10 17:11:03
Can you add some empty lines? In particular around
aberent
2015/06/15 15:52:19
Done.
| |
| 15 bool resultReceived = false; | |
|
Bernhard Bauer
2015/06/10 17:11:03
This should be unix_hacker_style, no?
aberent
2015/06/15 15:52:19
Done.
| |
| 16 std::string* auth_token = new std::string(); | |
|
Bernhard Bauer
2015/06/10 17:11:03
It doesn't look like this needs to be global.
aberent
2015/06/15 15:52:19
Done.
| |
| 17 base::MessageLoop* message_loop; | |
| 18 | |
| 19 void DummyCallback(int /*result*/) { | |
| 20 resultReceived = true; | |
| 21 message_loop->Quit(); | |
| 22 } | |
| 23 | |
| 24 } // namespace | |
| 25 | |
| 26 TEST(AndroidAuthNegotiateTest, GenerateAuthToken) { | |
| 27 AndroidAuthNegotiate auth("org.chromium.test.DummySpnegoAuthenticator", | |
| 28 "Negotiate"); | |
| 29 EXPECT_TRUE(auth.Init()); | |
| 30 | |
| 31 base::StartTestUiThreadLooper(); | |
| 32 | |
| 33 EXPECT_EQ(auth.GenerateAuthToken(nullptr, "Dummy", auth_token, | |
| 34 base::Bind(&DummyCallback)), | |
| 35 ERR_IO_PENDING); | |
|
Bernhard Bauer
2015/06/10 17:11:02
Put the expected value first for nicer error messa
aberent
2015/06/15 15:52:19
Done.
| |
| 36 | |
| 37 message_loop = base::MessageLoop::current(); | |
|
Bernhard Bauer
2015/06/10 17:11:03
Use base::RunLoop() instead of manually pumping th
aberent
2015/06/15 15:52:19
Done.
| |
| 38 message_loop->Run(); | |
| 39 | |
| 40 EXPECT_TRUE(resultReceived); | |
| 41 EXPECT_EQ(*auth_token, "Negotiate DummyToken"); | |
| 42 } | |
| 43 | |
| 44 TEST(AndroidAuthNegotiateTest, ParseChallenge_FirstRound) { | |
| 45 // The first round should just consist of an unadorned "Negotiate" header. | |
| 46 AndroidAuthNegotiate auth("org.chromium.test.DummySpnegoAuthenticator", | |
| 47 "Negotiate"); | |
| 48 std::string challenge_text = "Negotiate"; | |
| 49 HttpAuthChallengeTokenizer challenge(challenge_text.begin(), | |
| 50 challenge_text.end()); | |
| 51 EXPECT_EQ(HttpAuth::AUTHORIZATION_RESULT_ACCEPT, | |
| 52 auth.ParseChallenge(&challenge)); | |
| 53 } | |
| 54 | |
| 55 TEST(AndroidAuthNegotiateTest, ParseChallenge_UnexpectedTokenFirstRound) { | |
| 56 // If the first round challenge has an additional authentication token, it | |
| 57 // should be treated as an invalid challenge from the server. | |
| 58 AndroidAuthNegotiate auth("org.chromium.test.DummySpnegoAuthenticator", | |
| 59 "Negotiate"); | |
| 60 std::string challenge_text = "Negotiate Zm9vYmFy"; | |
| 61 HttpAuthChallengeTokenizer challenge(challenge_text.begin(), | |
| 62 challenge_text.end()); | |
| 63 EXPECT_EQ(HttpAuth::AUTHORIZATION_RESULT_INVALID, | |
| 64 auth.ParseChallenge(&challenge)); | |
| 65 } | |
| 66 | |
| 67 TEST(AndroidAuthNegotiateTest, ParseChallenge_TwoRounds) { | |
| 68 // The first round should just have "Negotiate", and the second round should | |
| 69 // have a valid base64 token associated with it. | |
| 70 AndroidAuthNegotiate auth("org.chromium.test.DummySpnegoAuthenticator", | |
| 71 "Negotiate"); | |
| 72 std::string first_challenge_text = "Negotiate"; | |
| 73 HttpAuthChallengeTokenizer first_challenge(first_challenge_text.begin(), | |
| 74 first_challenge_text.end()); | |
| 75 EXPECT_EQ(HttpAuth::AUTHORIZATION_RESULT_ACCEPT, | |
| 76 auth.ParseChallenge(&first_challenge)); | |
| 77 | |
| 78 std::string second_challenge_text = "Negotiate Zm9vYmFy"; | |
| 79 HttpAuthChallengeTokenizer second_challenge(second_challenge_text.begin(), | |
| 80 second_challenge_text.end()); | |
| 81 EXPECT_EQ(HttpAuth::AUTHORIZATION_RESULT_ACCEPT, | |
| 82 auth.ParseChallenge(&second_challenge)); | |
| 83 } | |
| 84 | |
| 85 TEST(AndroidAuthNegotiateTest, ParseChallenge_MissingTokenSecondRound) { | |
| 86 // If a later-round challenge is simply "Negotiate", it should be treated as | |
| 87 // an authentication challenge rejection from the server or proxy. | |
| 88 AndroidAuthNegotiate auth("org.chromium.test.DummySpnegoAuthenticator", | |
| 89 "Negotiate"); | |
| 90 std::string first_challenge_text = "Negotiate"; | |
| 91 HttpAuthChallengeTokenizer first_challenge(first_challenge_text.begin(), | |
| 92 first_challenge_text.end()); | |
| 93 EXPECT_EQ(HttpAuth::AUTHORIZATION_RESULT_ACCEPT, | |
| 94 auth.ParseChallenge(&first_challenge)); | |
| 95 | |
| 96 std::string second_challenge_text = "Negotiate"; | |
| 97 HttpAuthChallengeTokenizer second_challenge(second_challenge_text.begin(), | |
| 98 second_challenge_text.end()); | |
| 99 EXPECT_EQ(HttpAuth::AUTHORIZATION_RESULT_REJECT, | |
| 100 auth.ParseChallenge(&second_challenge)); | |
| 101 } | |
| 102 | |
| 103 } // namespace android | |
| 104 } // namespace net | |
| OLD | NEW |