OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "net/http/http_auth_challenge_tokenizer.h" | 5 #include "net/http/http_auth_challenge_tokenizer.h" |
6 #include "net/http/http_auth_multi_round_parse.h" | 6 #include "net/http/http_auth_multi_round_parse.h" |
7 #include "testing/gtest/include/gtest/gtest.h" | 7 #include "testing/gtest/include/gtest/gtest.h" |
8 | 8 |
9 namespace net { | 9 namespace net { |
10 | 10 |
11 TEST(HttpAuthHandlerNegotiateParseTest, ParseFirstRoundChallenge) { | 11 TEST(HttpAuthHandlerNegotiateParseTest, ParseFirstRoundChallenge) { |
12 // The first round should just consist of an unadorned header with the scheme | 12 // The first round should just consist of an unadorned header with the scheme |
13 // name. | 13 // name. |
14 std::string challenge_text = "DummyScheme"; | 14 std::string challenge_text = "DummyScheme"; |
15 HttpAuthChallengeTokenizer challenge(challenge_text.begin(), | 15 HttpAuthChallengeTokenizer challenge(challenge_text.begin(), |
16 challenge_text.end()); | 16 challenge_text.end()); |
17 EXPECT_EQ(HttpAuth::AUTHORIZATION_RESULT_ACCEPT, | 17 EXPECT_EQ(HttpAuth::AUTHORIZATION_RESULT_ACCEPT, |
18 ParseFirstRoundChallenge("dummyscheme", &challenge)); | 18 ParseFirstRoundChallenge("dummyscheme", challenge)); |
19 } | 19 } |
20 | 20 |
21 TEST(HttpAuthHandlerNegotiateParseTest, | 21 TEST(HttpAuthHandlerNegotiateParseTest, |
22 ParseFirstNegotiateChallenge_UnexpectedToken) { | 22 ParseFirstNegotiateChallenge_UnexpectedToken) { |
23 // If the first round challenge has an additional authentication token, it | 23 // If the first round challenge has an additional authentication token, it |
24 // should be treated as an invalid challenge from the server. | 24 // should be treated as an invalid challenge from the server. |
25 std::string challenge_text = "Negotiate Zm9vYmFy"; | 25 std::string challenge_text = "Negotiate Zm9vYmFy"; |
26 HttpAuthChallengeTokenizer challenge(challenge_text.begin(), | 26 HttpAuthChallengeTokenizer challenge(challenge_text.begin(), |
27 challenge_text.end()); | 27 challenge_text.end()); |
28 EXPECT_EQ(HttpAuth::AUTHORIZATION_RESULT_INVALID, | 28 EXPECT_EQ(HttpAuth::AUTHORIZATION_RESULT_INVALID, |
29 ParseFirstRoundChallenge("negotiate", &challenge)); | 29 ParseFirstRoundChallenge("negotiate", challenge)); |
30 } | 30 } |
31 | 31 |
32 TEST(HttpAuthHandlerNegotiateParseTest, | 32 TEST(HttpAuthHandlerNegotiateParseTest, |
33 ParseFirstNegotiateChallenge_BadScheme) { | 33 ParseFirstNegotiateChallenge_BadScheme) { |
34 std::string challenge_text = "DummyScheme"; | 34 std::string challenge_text = "DummyScheme"; |
35 HttpAuthChallengeTokenizer challenge(challenge_text.begin(), | 35 HttpAuthChallengeTokenizer challenge(challenge_text.begin(), |
36 challenge_text.end()); | 36 challenge_text.end()); |
37 EXPECT_EQ(HttpAuth::AUTHORIZATION_RESULT_INVALID, | 37 EXPECT_EQ(HttpAuth::AUTHORIZATION_RESULT_INVALID, |
38 ParseFirstRoundChallenge("negotiate", &challenge)); | 38 ParseFirstRoundChallenge("negotiate", challenge)); |
39 } | 39 } |
40 | 40 |
41 TEST(HttpAuthHandlerNegotiateParseTest, ParseLaterRoundChallenge) { | 41 TEST(HttpAuthHandlerNegotiateParseTest, ParseLaterRoundChallenge) { |
42 // Later rounds should always have a Base64 encoded token. | 42 // Later rounds should always have a Base64 encoded token. |
43 std::string challenge_text = "Negotiate Zm9vYmFy"; | 43 std::string challenge_text = "Negotiate Zm9vYmFy"; |
44 HttpAuthChallengeTokenizer challenge(challenge_text.begin(), | 44 HttpAuthChallengeTokenizer challenge(challenge_text.begin(), |
45 challenge_text.end()); | 45 challenge_text.end()); |
46 std::string encoded_token; | 46 std::string encoded_token; |
47 std::string decoded_token; | 47 std::string decoded_token; |
48 EXPECT_EQ(HttpAuth::AUTHORIZATION_RESULT_ACCEPT, | 48 EXPECT_EQ(HttpAuth::AUTHORIZATION_RESULT_ACCEPT, |
49 ParseLaterRoundChallenge("negotiate", &challenge, &encoded_token, | 49 ParseLaterRoundChallenge("negotiate", challenge, &encoded_token, |
50 &decoded_token)); | 50 &decoded_token)); |
51 EXPECT_EQ("Zm9vYmFy", encoded_token); | 51 EXPECT_EQ("Zm9vYmFy", encoded_token); |
52 EXPECT_EQ("foobar", decoded_token); | 52 EXPECT_EQ("foobar", decoded_token); |
53 } | 53 } |
54 | 54 |
55 TEST(HttpAuthHandlerNegotiateParseTest, | 55 TEST(HttpAuthHandlerNegotiateParseTest, |
56 ParseAnotherNegotiateChallenge_MissingToken) { | 56 ParseAnotherNegotiateChallenge_MissingToken) { |
57 std::string challenge_text = "Negotiate"; | 57 std::string challenge_text = "Negotiate"; |
58 HttpAuthChallengeTokenizer challenge(challenge_text.begin(), | 58 HttpAuthChallengeTokenizer challenge(challenge_text.begin(), |
59 challenge_text.end()); | 59 challenge_text.end()); |
60 std::string encoded_token; | 60 std::string encoded_token; |
61 std::string decoded_token; | 61 std::string decoded_token; |
62 EXPECT_EQ(HttpAuth::AUTHORIZATION_RESULT_REJECT, | 62 EXPECT_EQ(HttpAuth::AUTHORIZATION_RESULT_REJECT, |
63 ParseLaterRoundChallenge("negotiate", &challenge, &encoded_token, | 63 ParseLaterRoundChallenge("negotiate", challenge, &encoded_token, |
64 &decoded_token)); | 64 &decoded_token)); |
65 } | 65 } |
66 | 66 |
67 TEST(HttpAuthHandlerNegotiateParseTest, | 67 TEST(HttpAuthHandlerNegotiateParseTest, |
68 ParseAnotherNegotiateChallenge_InvalidToken) { | 68 ParseAnotherNegotiateChallenge_InvalidToken) { |
69 std::string challenge_text = "Negotiate ***"; | 69 std::string challenge_text = "Negotiate ***"; |
70 HttpAuthChallengeTokenizer challenge(challenge_text.begin(), | 70 HttpAuthChallengeTokenizer challenge(challenge_text.begin(), |
71 challenge_text.end()); | 71 challenge_text.end()); |
72 std::string encoded_token; | 72 std::string encoded_token; |
73 std::string decoded_token; | 73 std::string decoded_token; |
74 EXPECT_EQ(HttpAuth::AUTHORIZATION_RESULT_INVALID, | 74 EXPECT_EQ(HttpAuth::AUTHORIZATION_RESULT_INVALID, |
75 ParseLaterRoundChallenge("negotiate", &challenge, &encoded_token, | 75 ParseLaterRoundChallenge("negotiate", challenge, &encoded_token, |
76 &decoded_token)); | 76 &decoded_token)); |
77 } | 77 } |
78 } | 78 } |
OLD | NEW |