| 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 "net/base/net_errors.h" | 5 #include "net/base/net_errors.h" |
| 6 #include "net/http/http_auth_challenge_tokenizer.h" | 6 #include "net/http/http_auth_challenge_tokenizer.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 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 82 NEGOSSP_NAME, kMaxTokenLength); | 82 NEGOSSP_NAME, kMaxTokenLength); |
| 83 std::string first_challenge_text = "Negotiate"; | 83 std::string first_challenge_text = "Negotiate"; |
| 84 HttpAuthChallengeTokenizer first_challenge(first_challenge_text.begin(), | 84 HttpAuthChallengeTokenizer first_challenge(first_challenge_text.begin(), |
| 85 first_challenge_text.end()); | 85 first_challenge_text.end()); |
| 86 EXPECT_EQ(HttpAuth::AUTHORIZATION_RESULT_ACCEPT, | 86 EXPECT_EQ(HttpAuth::AUTHORIZATION_RESULT_ACCEPT, |
| 87 auth_sspi.ParseChallenge(&first_challenge)); | 87 auth_sspi.ParseChallenge(&first_challenge)); |
| 88 | 88 |
| 89 // Generate an auth token and create another thing. | 89 // Generate an auth token and create another thing. |
| 90 std::string auth_token; | 90 std::string auth_token; |
| 91 EXPECT_EQ(OK, auth_sspi.GenerateAuthToken(NULL, "HTTP/intranet.google.com", | 91 EXPECT_EQ(OK, auth_sspi.GenerateAuthToken(NULL, "HTTP/intranet.google.com", |
| 92 &auth_token, | 92 std::string(), &auth_token, |
| 93 base::Bind(&UnexpectedCallback))); | 93 base::Bind(&UnexpectedCallback))); |
| 94 | 94 |
| 95 std::string second_challenge_text = "Negotiate Zm9vYmFy"; | 95 std::string second_challenge_text = "Negotiate Zm9vYmFy"; |
| 96 HttpAuthChallengeTokenizer second_challenge(second_challenge_text.begin(), | 96 HttpAuthChallengeTokenizer second_challenge(second_challenge_text.begin(), |
| 97 second_challenge_text.end()); | 97 second_challenge_text.end()); |
| 98 EXPECT_EQ(HttpAuth::AUTHORIZATION_RESULT_ACCEPT, | 98 EXPECT_EQ(HttpAuth::AUTHORIZATION_RESULT_ACCEPT, |
| 99 auth_sspi.ParseChallenge(&second_challenge)); | 99 auth_sspi.ParseChallenge(&second_challenge)); |
| 100 } | 100 } |
| 101 | 101 |
| 102 TEST(HttpAuthSSPITest, ParseChallenge_UnexpectedTokenFirstRound) { | 102 TEST(HttpAuthSSPITest, ParseChallenge_UnexpectedTokenFirstRound) { |
| (...skipping 16 matching lines...) Expand all Loading... |
| 119 HttpAuthSSPI auth_sspi(&mock_library, "Negotiate", | 119 HttpAuthSSPI auth_sspi(&mock_library, "Negotiate", |
| 120 NEGOSSP_NAME, kMaxTokenLength); | 120 NEGOSSP_NAME, kMaxTokenLength); |
| 121 std::string first_challenge_text = "Negotiate"; | 121 std::string first_challenge_text = "Negotiate"; |
| 122 HttpAuthChallengeTokenizer first_challenge(first_challenge_text.begin(), | 122 HttpAuthChallengeTokenizer first_challenge(first_challenge_text.begin(), |
| 123 first_challenge_text.end()); | 123 first_challenge_text.end()); |
| 124 EXPECT_EQ(HttpAuth::AUTHORIZATION_RESULT_ACCEPT, | 124 EXPECT_EQ(HttpAuth::AUTHORIZATION_RESULT_ACCEPT, |
| 125 auth_sspi.ParseChallenge(&first_challenge)); | 125 auth_sspi.ParseChallenge(&first_challenge)); |
| 126 | 126 |
| 127 std::string auth_token; | 127 std::string auth_token; |
| 128 EXPECT_EQ(OK, auth_sspi.GenerateAuthToken(NULL, "HTTP/intranet.google.com", | 128 EXPECT_EQ(OK, auth_sspi.GenerateAuthToken(NULL, "HTTP/intranet.google.com", |
| 129 &auth_token, | 129 std::string(), &auth_token, |
| 130 base::Bind(&UnexpectedCallback))); | 130 base::Bind(&UnexpectedCallback))); |
| 131 std::string second_challenge_text = "Negotiate"; | 131 std::string second_challenge_text = "Negotiate"; |
| 132 HttpAuthChallengeTokenizer second_challenge(second_challenge_text.begin(), | 132 HttpAuthChallengeTokenizer second_challenge(second_challenge_text.begin(), |
| 133 second_challenge_text.end()); | 133 second_challenge_text.end()); |
| 134 EXPECT_EQ(HttpAuth::AUTHORIZATION_RESULT_REJECT, | 134 EXPECT_EQ(HttpAuth::AUTHORIZATION_RESULT_REJECT, |
| 135 auth_sspi.ParseChallenge(&second_challenge)); | 135 auth_sspi.ParseChallenge(&second_challenge)); |
| 136 } | 136 } |
| 137 | 137 |
| 138 TEST(HttpAuthSSPITest, ParseChallenge_NonBase64EncodedToken) { | 138 TEST(HttpAuthSSPITest, ParseChallenge_NonBase64EncodedToken) { |
| 139 // If a later-round challenge has an invalid base64 encoded token, it should | 139 // If a later-round challenge has an invalid base64 encoded token, it should |
| 140 // be treated as an invalid challenge. | 140 // be treated as an invalid challenge. |
| 141 MockSSPILibrary mock_library; | 141 MockSSPILibrary mock_library; |
| 142 HttpAuthSSPI auth_sspi(&mock_library, "Negotiate", | 142 HttpAuthSSPI auth_sspi(&mock_library, "Negotiate", |
| 143 NEGOSSP_NAME, kMaxTokenLength); | 143 NEGOSSP_NAME, kMaxTokenLength); |
| 144 std::string first_challenge_text = "Negotiate"; | 144 std::string first_challenge_text = "Negotiate"; |
| 145 HttpAuthChallengeTokenizer first_challenge(first_challenge_text.begin(), | 145 HttpAuthChallengeTokenizer first_challenge(first_challenge_text.begin(), |
| 146 first_challenge_text.end()); | 146 first_challenge_text.end()); |
| 147 EXPECT_EQ(HttpAuth::AUTHORIZATION_RESULT_ACCEPT, | 147 EXPECT_EQ(HttpAuth::AUTHORIZATION_RESULT_ACCEPT, |
| 148 auth_sspi.ParseChallenge(&first_challenge)); | 148 auth_sspi.ParseChallenge(&first_challenge)); |
| 149 | 149 |
| 150 std::string auth_token; | 150 std::string auth_token; |
| 151 EXPECT_EQ(OK, auth_sspi.GenerateAuthToken(NULL, "HTTP/intranet.google.com", | 151 EXPECT_EQ(OK, auth_sspi.GenerateAuthToken(NULL, "HTTP/intranet.google.com", |
| 152 &auth_token, | 152 std::string(), &auth_token, |
| 153 base::Bind(&UnexpectedCallback))); | 153 base::Bind(&UnexpectedCallback))); |
| 154 std::string second_challenge_text = "Negotiate =happyjoy="; | 154 std::string second_challenge_text = "Negotiate =happyjoy="; |
| 155 HttpAuthChallengeTokenizer second_challenge(second_challenge_text.begin(), | 155 HttpAuthChallengeTokenizer second_challenge(second_challenge_text.begin(), |
| 156 second_challenge_text.end()); | 156 second_challenge_text.end()); |
| 157 EXPECT_EQ(HttpAuth::AUTHORIZATION_RESULT_INVALID, | 157 EXPECT_EQ(HttpAuth::AUTHORIZATION_RESULT_INVALID, |
| 158 auth_sspi.ParseChallenge(&second_challenge)); | 158 auth_sspi.ParseChallenge(&second_challenge)); |
| 159 } | 159 } |
| 160 | 160 |
| 161 } // namespace net | 161 } // namespace net |
| OLD | NEW |