OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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_sspi_win.h" | 7 #include "net/http/http_auth_sspi_win.h" |
8 #include "net/http/mock_sspi_library_win.h" | 8 #include "net/http/mock_sspi_library_win.h" |
9 #include "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
10 | 10 |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
75 HttpAuthSSPI auth_sspi(&mock_library, "Negotiate", | 75 HttpAuthSSPI auth_sspi(&mock_library, "Negotiate", |
76 NEGOSSP_NAME, kMaxTokenLength); | 76 NEGOSSP_NAME, kMaxTokenLength); |
77 std::string first_challenge_text = "Negotiate"; | 77 std::string first_challenge_text = "Negotiate"; |
78 HttpAuth::ChallengeTokenizer first_challenge(first_challenge_text.begin(), | 78 HttpAuth::ChallengeTokenizer first_challenge(first_challenge_text.begin(), |
79 first_challenge_text.end()); | 79 first_challenge_text.end()); |
80 EXPECT_EQ(HttpAuth::AUTHORIZATION_RESULT_ACCEPT, | 80 EXPECT_EQ(HttpAuth::AUTHORIZATION_RESULT_ACCEPT, |
81 auth_sspi.ParseChallenge(&first_challenge)); | 81 auth_sspi.ParseChallenge(&first_challenge)); |
82 | 82 |
83 // Generate an auth token and create another thing. | 83 // Generate an auth token and create another thing. |
84 std::string auth_token; | 84 std::string auth_token; |
85 EXPECT_EQ(OK, auth_sspi.GenerateAuthToken(NULL, NULL, | 85 EXPECT_EQ(OK, auth_sspi.GenerateAuthToken(NULL, L"HTTP/intranet.google.com", |
86 L"HTTP/intranet.google.com", | |
87 &auth_token)); | 86 &auth_token)); |
88 | 87 |
89 std::string second_challenge_text = "Negotiate Zm9vYmFy"; | 88 std::string second_challenge_text = "Negotiate Zm9vYmFy"; |
90 HttpAuth::ChallengeTokenizer second_challenge(second_challenge_text.begin(), | 89 HttpAuth::ChallengeTokenizer second_challenge(second_challenge_text.begin(), |
91 second_challenge_text.end()); | 90 second_challenge_text.end()); |
92 EXPECT_EQ(HttpAuth::AUTHORIZATION_RESULT_ACCEPT, | 91 EXPECT_EQ(HttpAuth::AUTHORIZATION_RESULT_ACCEPT, |
93 auth_sspi.ParseChallenge(&second_challenge)); | 92 auth_sspi.ParseChallenge(&second_challenge)); |
94 } | 93 } |
95 | 94 |
96 TEST(HttpAuthSSPITest, ParseChallenge_UnexpectedTokenFirstRound) { | 95 TEST(HttpAuthSSPITest, ParseChallenge_UnexpectedTokenFirstRound) { |
(...skipping 15 matching lines...) Expand all Loading... |
112 MockSSPILibrary mock_library; | 111 MockSSPILibrary mock_library; |
113 HttpAuthSSPI auth_sspi(&mock_library, "Negotiate", | 112 HttpAuthSSPI auth_sspi(&mock_library, "Negotiate", |
114 NEGOSSP_NAME, kMaxTokenLength); | 113 NEGOSSP_NAME, kMaxTokenLength); |
115 std::string first_challenge_text = "Negotiate"; | 114 std::string first_challenge_text = "Negotiate"; |
116 HttpAuth::ChallengeTokenizer first_challenge(first_challenge_text.begin(), | 115 HttpAuth::ChallengeTokenizer first_challenge(first_challenge_text.begin(), |
117 first_challenge_text.end()); | 116 first_challenge_text.end()); |
118 EXPECT_EQ(HttpAuth::AUTHORIZATION_RESULT_ACCEPT, | 117 EXPECT_EQ(HttpAuth::AUTHORIZATION_RESULT_ACCEPT, |
119 auth_sspi.ParseChallenge(&first_challenge)); | 118 auth_sspi.ParseChallenge(&first_challenge)); |
120 | 119 |
121 std::string auth_token; | 120 std::string auth_token; |
122 EXPECT_EQ(OK, auth_sspi.GenerateAuthToken(NULL, NULL, | 121 EXPECT_EQ(OK, auth_sspi.GenerateAuthToken(NULL, L"HTTP/intranet.google.com", |
123 L"HTTP/intranet.google.com", | |
124 &auth_token)); | 122 &auth_token)); |
125 std::string second_challenge_text = "Negotiate"; | 123 std::string second_challenge_text = "Negotiate"; |
126 HttpAuth::ChallengeTokenizer second_challenge(second_challenge_text.begin(), | 124 HttpAuth::ChallengeTokenizer second_challenge(second_challenge_text.begin(), |
127 second_challenge_text.end()); | 125 second_challenge_text.end()); |
128 EXPECT_EQ(HttpAuth::AUTHORIZATION_RESULT_REJECT, | 126 EXPECT_EQ(HttpAuth::AUTHORIZATION_RESULT_REJECT, |
129 auth_sspi.ParseChallenge(&second_challenge)); | 127 auth_sspi.ParseChallenge(&second_challenge)); |
130 } | 128 } |
131 | 129 |
132 TEST(HttpAuthSSPITest, ParseChallenge_NonBase64EncodedToken) { | 130 TEST(HttpAuthSSPITest, ParseChallenge_NonBase64EncodedToken) { |
133 // If a later-round challenge has an invalid base64 encoded token, it should | 131 // If a later-round challenge has an invalid base64 encoded token, it should |
134 // be treated as an invalid challenge. | 132 // be treated as an invalid challenge. |
135 MockSSPILibrary mock_library; | 133 MockSSPILibrary mock_library; |
136 HttpAuthSSPI auth_sspi(&mock_library, "Negotiate", | 134 HttpAuthSSPI auth_sspi(&mock_library, "Negotiate", |
137 NEGOSSP_NAME, kMaxTokenLength); | 135 NEGOSSP_NAME, kMaxTokenLength); |
138 std::string first_challenge_text = "Negotiate"; | 136 std::string first_challenge_text = "Negotiate"; |
139 HttpAuth::ChallengeTokenizer first_challenge(first_challenge_text.begin(), | 137 HttpAuth::ChallengeTokenizer first_challenge(first_challenge_text.begin(), |
140 first_challenge_text.end()); | 138 first_challenge_text.end()); |
141 EXPECT_EQ(HttpAuth::AUTHORIZATION_RESULT_ACCEPT, | 139 EXPECT_EQ(HttpAuth::AUTHORIZATION_RESULT_ACCEPT, |
142 auth_sspi.ParseChallenge(&first_challenge)); | 140 auth_sspi.ParseChallenge(&first_challenge)); |
143 | 141 |
144 std::string auth_token; | 142 std::string auth_token; |
145 EXPECT_EQ(OK, auth_sspi.GenerateAuthToken(NULL, NULL, | 143 EXPECT_EQ(OK, auth_sspi.GenerateAuthToken(NULL, L"HTTP/intranet.google.com", |
146 L"HTTP/intranet.google.com", | |
147 &auth_token)); | 144 &auth_token)); |
148 std::string second_challenge_text = "Negotiate =happyjoy="; | 145 std::string second_challenge_text = "Negotiate =happyjoy="; |
149 HttpAuth::ChallengeTokenizer second_challenge(second_challenge_text.begin(), | 146 HttpAuth::ChallengeTokenizer second_challenge(second_challenge_text.begin(), |
150 second_challenge_text.end()); | 147 second_challenge_text.end()); |
151 EXPECT_EQ(HttpAuth::AUTHORIZATION_RESULT_INVALID, | 148 EXPECT_EQ(HttpAuth::AUTHORIZATION_RESULT_INVALID, |
152 auth_sspi.ParseChallenge(&second_challenge)); | 149 auth_sspi.ParseChallenge(&second_challenge)); |
153 } | 150 } |
154 | 151 |
155 } // namespace net | 152 } // namespace net |
OLD | NEW |