OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/basictypes.h" | 5 #include "base/basictypes.h" |
6 #include "net/base/net_errors.h" | 6 #include "net/base/net_errors.h" |
7 #include "net/http/http_auth_challenge_tokenizer.h" | 7 #include "net/http/http_auth_challenge_tokenizer.h" |
8 #include "net/http/http_auth_sspi_win.h" | 8 #include "net/http/http_auth_sspi_win.h" |
9 #include "net/http/mock_sspi_library_win.h" | 9 #include "net/http/mock_sspi_library_win.h" |
10 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
11 | 11 |
12 namespace net { | 12 namespace net { |
13 | 13 |
14 namespace { | 14 namespace { |
15 | 15 |
16 void MatchDomainUserAfterSplit(const std::wstring& combined, | 16 void MatchDomainUserAfterSplit(const std::wstring& combined, |
17 const std::wstring& expected_domain, | 17 const std::wstring& expected_domain, |
18 const std::wstring& expected_user) { | 18 const std::wstring& expected_user) { |
19 std::wstring actual_domain; | 19 std::wstring actual_domain; |
20 std::wstring actual_user; | 20 std::wstring actual_user; |
21 SplitDomainAndUser(combined, &actual_domain, &actual_user); | 21 SplitDomainAndUser(combined, &actual_domain, &actual_user); |
22 EXPECT_EQ(expected_domain, actual_domain); | 22 EXPECT_EQ(expected_domain, actual_domain); |
23 EXPECT_EQ(expected_user, actual_user); | 23 EXPECT_EQ(expected_user, actual_user); |
24 } | 24 } |
25 | 25 |
26 const ULONG kMaxTokenLength = 100; | 26 const ULONG kMaxTokenLength = 100; |
27 | 27 |
| 28 void UnexpectedCallback(int result) { |
| 29 // At present getting tokens from gssapi is fully synchronous, so the callback |
| 30 // should never be called. |
| 31 ADD_FAILURE(); |
| 32 } |
| 33 |
28 } // namespace | 34 } // namespace |
29 | 35 |
30 TEST(HttpAuthSSPITest, SplitUserAndDomain) { | 36 TEST(HttpAuthSSPITest, SplitUserAndDomain) { |
31 MatchDomainUserAfterSplit(L"foobar", L"", L"foobar"); | 37 MatchDomainUserAfterSplit(L"foobar", L"", L"foobar"); |
32 MatchDomainUserAfterSplit(L"FOO\\bar", L"FOO", L"bar"); | 38 MatchDomainUserAfterSplit(L"FOO\\bar", L"FOO", L"bar"); |
33 } | 39 } |
34 | 40 |
35 TEST(HttpAuthSSPITest, DetermineMaxTokenLength_Normal) { | 41 TEST(HttpAuthSSPITest, DetermineMaxTokenLength_Normal) { |
36 SecPkgInfoW package_info; | 42 SecPkgInfoW package_info; |
37 memset(&package_info, 0x0, sizeof(package_info)); | 43 memset(&package_info, 0x0, sizeof(package_info)); |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
77 NEGOSSP_NAME, kMaxTokenLength); | 83 NEGOSSP_NAME, kMaxTokenLength); |
78 std::string first_challenge_text = "Negotiate"; | 84 std::string first_challenge_text = "Negotiate"; |
79 HttpAuthChallengeTokenizer first_challenge(first_challenge_text.begin(), | 85 HttpAuthChallengeTokenizer first_challenge(first_challenge_text.begin(), |
80 first_challenge_text.end()); | 86 first_challenge_text.end()); |
81 EXPECT_EQ(HttpAuth::AUTHORIZATION_RESULT_ACCEPT, | 87 EXPECT_EQ(HttpAuth::AUTHORIZATION_RESULT_ACCEPT, |
82 auth_sspi.ParseChallenge(&first_challenge)); | 88 auth_sspi.ParseChallenge(&first_challenge)); |
83 | 89 |
84 // Generate an auth token and create another thing. | 90 // Generate an auth token and create another thing. |
85 std::string auth_token; | 91 std::string auth_token; |
86 EXPECT_EQ(OK, auth_sspi.GenerateAuthToken(NULL, "HTTP/intranet.google.com", | 92 EXPECT_EQ(OK, auth_sspi.GenerateAuthToken(NULL, "HTTP/intranet.google.com", |
87 &auth_token)); | 93 &auth_token, |
| 94 base::Bind(&UnexpectedCallback))); |
88 | 95 |
89 std::string second_challenge_text = "Negotiate Zm9vYmFy"; | 96 std::string second_challenge_text = "Negotiate Zm9vYmFy"; |
90 HttpAuthChallengeTokenizer second_challenge(second_challenge_text.begin(), | 97 HttpAuthChallengeTokenizer second_challenge(second_challenge_text.begin(), |
91 second_challenge_text.end()); | 98 second_challenge_text.end()); |
92 EXPECT_EQ(HttpAuth::AUTHORIZATION_RESULT_ACCEPT, | 99 EXPECT_EQ(HttpAuth::AUTHORIZATION_RESULT_ACCEPT, |
93 auth_sspi.ParseChallenge(&second_challenge)); | 100 auth_sspi.ParseChallenge(&second_challenge)); |
94 } | 101 } |
95 | 102 |
96 TEST(HttpAuthSSPITest, ParseChallenge_UnexpectedTokenFirstRound) { | 103 TEST(HttpAuthSSPITest, ParseChallenge_UnexpectedTokenFirstRound) { |
97 // If the first round challenge has an additional authentication token, it | 104 // If the first round challenge has an additional authentication token, it |
(...skipping 15 matching lines...) Expand all Loading... |
113 HttpAuthSSPI auth_sspi(&mock_library, "Negotiate", | 120 HttpAuthSSPI auth_sspi(&mock_library, "Negotiate", |
114 NEGOSSP_NAME, kMaxTokenLength); | 121 NEGOSSP_NAME, kMaxTokenLength); |
115 std::string first_challenge_text = "Negotiate"; | 122 std::string first_challenge_text = "Negotiate"; |
116 HttpAuthChallengeTokenizer first_challenge(first_challenge_text.begin(), | 123 HttpAuthChallengeTokenizer first_challenge(first_challenge_text.begin(), |
117 first_challenge_text.end()); | 124 first_challenge_text.end()); |
118 EXPECT_EQ(HttpAuth::AUTHORIZATION_RESULT_ACCEPT, | 125 EXPECT_EQ(HttpAuth::AUTHORIZATION_RESULT_ACCEPT, |
119 auth_sspi.ParseChallenge(&first_challenge)); | 126 auth_sspi.ParseChallenge(&first_challenge)); |
120 | 127 |
121 std::string auth_token; | 128 std::string auth_token; |
122 EXPECT_EQ(OK, auth_sspi.GenerateAuthToken(NULL, "HTTP/intranet.google.com", | 129 EXPECT_EQ(OK, auth_sspi.GenerateAuthToken(NULL, "HTTP/intranet.google.com", |
123 &auth_token)); | 130 &auth_token, |
| 131 base::Bind(&UnexpectedCallback))); |
124 std::string second_challenge_text = "Negotiate"; | 132 std::string second_challenge_text = "Negotiate"; |
125 HttpAuthChallengeTokenizer second_challenge(second_challenge_text.begin(), | 133 HttpAuthChallengeTokenizer second_challenge(second_challenge_text.begin(), |
126 second_challenge_text.end()); | 134 second_challenge_text.end()); |
127 EXPECT_EQ(HttpAuth::AUTHORIZATION_RESULT_REJECT, | 135 EXPECT_EQ(HttpAuth::AUTHORIZATION_RESULT_REJECT, |
128 auth_sspi.ParseChallenge(&second_challenge)); | 136 auth_sspi.ParseChallenge(&second_challenge)); |
129 } | 137 } |
130 | 138 |
131 TEST(HttpAuthSSPITest, ParseChallenge_NonBase64EncodedToken) { | 139 TEST(HttpAuthSSPITest, ParseChallenge_NonBase64EncodedToken) { |
132 // If a later-round challenge has an invalid base64 encoded token, it should | 140 // If a later-round challenge has an invalid base64 encoded token, it should |
133 // be treated as an invalid challenge. | 141 // be treated as an invalid challenge. |
134 MockSSPILibrary mock_library; | 142 MockSSPILibrary mock_library; |
135 HttpAuthSSPI auth_sspi(&mock_library, "Negotiate", | 143 HttpAuthSSPI auth_sspi(&mock_library, "Negotiate", |
136 NEGOSSP_NAME, kMaxTokenLength); | 144 NEGOSSP_NAME, kMaxTokenLength); |
137 std::string first_challenge_text = "Negotiate"; | 145 std::string first_challenge_text = "Negotiate"; |
138 HttpAuthChallengeTokenizer first_challenge(first_challenge_text.begin(), | 146 HttpAuthChallengeTokenizer first_challenge(first_challenge_text.begin(), |
139 first_challenge_text.end()); | 147 first_challenge_text.end()); |
140 EXPECT_EQ(HttpAuth::AUTHORIZATION_RESULT_ACCEPT, | 148 EXPECT_EQ(HttpAuth::AUTHORIZATION_RESULT_ACCEPT, |
141 auth_sspi.ParseChallenge(&first_challenge)); | 149 auth_sspi.ParseChallenge(&first_challenge)); |
142 | 150 |
143 std::string auth_token; | 151 std::string auth_token; |
144 EXPECT_EQ(OK, auth_sspi.GenerateAuthToken(NULL, "HTTP/intranet.google.com", | 152 EXPECT_EQ(OK, auth_sspi.GenerateAuthToken(NULL, "HTTP/intranet.google.com", |
145 &auth_token)); | 153 &auth_token, |
| 154 base::Bind(&UnexpectedCallback))); |
146 std::string second_challenge_text = "Negotiate =happyjoy="; | 155 std::string second_challenge_text = "Negotiate =happyjoy="; |
147 HttpAuthChallengeTokenizer second_challenge(second_challenge_text.begin(), | 156 HttpAuthChallengeTokenizer second_challenge(second_challenge_text.begin(), |
148 second_challenge_text.end()); | 157 second_challenge_text.end()); |
149 EXPECT_EQ(HttpAuth::AUTHORIZATION_RESULT_INVALID, | 158 EXPECT_EQ(HttpAuth::AUTHORIZATION_RESULT_INVALID, |
150 auth_sspi.ParseChallenge(&second_challenge)); | 159 auth_sspi.ParseChallenge(&second_challenge)); |
151 } | 160 } |
152 | 161 |
153 } // namespace net | 162 } // namespace net |
OLD | NEW |