| 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" |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 65 | 65 |
| 66 TEST(HttpAuthSSPITest, ParseChallenge_FirstRound) { | 66 TEST(HttpAuthSSPITest, ParseChallenge_FirstRound) { |
| 67 // The first round should just consist of an unadorned "Negotiate" header. | 67 // The first round should just consist of an unadorned "Negotiate" header. |
| 68 MockSSPILibrary mock_library; | 68 MockSSPILibrary mock_library; |
| 69 HttpAuthSSPI auth_sspi(&mock_library, "Negotiate", | 69 HttpAuthSSPI auth_sspi(&mock_library, "Negotiate", |
| 70 NEGOSSP_NAME, kMaxTokenLength); | 70 NEGOSSP_NAME, kMaxTokenLength); |
| 71 std::string challenge_text = "Negotiate"; | 71 std::string challenge_text = "Negotiate"; |
| 72 HttpAuthChallengeTokenizer challenge(challenge_text.begin(), | 72 HttpAuthChallengeTokenizer challenge(challenge_text.begin(), |
| 73 challenge_text.end()); | 73 challenge_text.end()); |
| 74 EXPECT_EQ(HttpAuth::AUTHORIZATION_RESULT_ACCEPT, | 74 EXPECT_EQ(HttpAuth::AUTHORIZATION_RESULT_ACCEPT, |
| 75 auth_sspi.ParseChallenge(&challenge)); | 75 auth_sspi.ParseChallenge(challenge)); |
| 76 } | 76 } |
| 77 | 77 |
| 78 TEST(HttpAuthSSPITest, ParseChallenge_TwoRounds) { | 78 TEST(HttpAuthSSPITest, ParseChallenge_TwoRounds) { |
| 79 // The first round should just have "Negotiate", and the second round should | 79 // The first round should just have "Negotiate", and the second round should |
| 80 // have a valid base64 token associated with it. | 80 // have a valid base64 token associated with it. |
| 81 MockSSPILibrary mock_library; | 81 MockSSPILibrary mock_library; |
| 82 HttpAuthSSPI auth_sspi(&mock_library, "Negotiate", | 82 HttpAuthSSPI auth_sspi(&mock_library, "Negotiate", |
| 83 NEGOSSP_NAME, kMaxTokenLength); | 83 NEGOSSP_NAME, kMaxTokenLength); |
| 84 std::string first_challenge_text = "Negotiate"; | 84 std::string first_challenge_text = "Negotiate"; |
| 85 HttpAuthChallengeTokenizer first_challenge(first_challenge_text.begin(), | 85 HttpAuthChallengeTokenizer first_challenge(first_challenge_text.begin(), |
| 86 first_challenge_text.end()); | 86 first_challenge_text.end()); |
| 87 EXPECT_EQ(HttpAuth::AUTHORIZATION_RESULT_ACCEPT, | 87 EXPECT_EQ(HttpAuth::AUTHORIZATION_RESULT_ACCEPT, |
| 88 auth_sspi.ParseChallenge(&first_challenge)); | 88 auth_sspi.ParseChallenge(first_challenge)); |
| 89 | 89 |
| 90 // Generate an auth token and create another thing. | 90 // Generate an auth token and create another thing. |
| 91 std::string auth_token; | 91 std::string auth_token; |
| 92 EXPECT_EQ(OK, auth_sspi.GenerateAuthToken(NULL, "HTTP/intranet.google.com", | 92 EXPECT_EQ(OK, auth_sspi.GenerateAuthToken(NULL, "HTTP/intranet.google.com", |
| 93 &auth_token, | 93 &auth_token, |
| 94 base::Bind(&UnexpectedCallback))); | 94 base::Bind(&UnexpectedCallback))); |
| 95 | 95 |
| 96 std::string second_challenge_text = "Negotiate Zm9vYmFy"; | 96 std::string second_challenge_text = "Negotiate Zm9vYmFy"; |
| 97 HttpAuthChallengeTokenizer second_challenge(second_challenge_text.begin(), | 97 HttpAuthChallengeTokenizer second_challenge(second_challenge_text.begin(), |
| 98 second_challenge_text.end()); | 98 second_challenge_text.end()); |
| 99 EXPECT_EQ(HttpAuth::AUTHORIZATION_RESULT_ACCEPT, | 99 EXPECT_EQ(HttpAuth::AUTHORIZATION_RESULT_ACCEPT, |
| 100 auth_sspi.ParseChallenge(&second_challenge)); | 100 auth_sspi.ParseChallenge(second_challenge)); |
| 101 } | 101 } |
| 102 | 102 |
| 103 TEST(HttpAuthSSPITest, ParseChallenge_UnexpectedTokenFirstRound) { | 103 TEST(HttpAuthSSPITest, ParseChallenge_UnexpectedTokenFirstRound) { |
| 104 // If the first round challenge has an additional authentication token, it | 104 // If the first round challenge has an additional authentication token, it |
| 105 // should be treated as an invalid challenge from the server. | 105 // should be treated as an invalid challenge from the server. |
| 106 MockSSPILibrary mock_library; | 106 MockSSPILibrary mock_library; |
| 107 HttpAuthSSPI auth_sspi(&mock_library, "Negotiate", | 107 HttpAuthSSPI auth_sspi(&mock_library, "Negotiate", |
| 108 NEGOSSP_NAME, kMaxTokenLength); | 108 NEGOSSP_NAME, kMaxTokenLength); |
| 109 std::string challenge_text = "Negotiate Zm9vYmFy"; | 109 std::string challenge_text = "Negotiate Zm9vYmFy"; |
| 110 HttpAuthChallengeTokenizer challenge(challenge_text.begin(), | 110 HttpAuthChallengeTokenizer challenge(challenge_text.begin(), |
| 111 challenge_text.end()); | 111 challenge_text.end()); |
| 112 EXPECT_EQ(HttpAuth::AUTHORIZATION_RESULT_INVALID, | 112 EXPECT_EQ(HttpAuth::AUTHORIZATION_RESULT_INVALID, |
| 113 auth_sspi.ParseChallenge(&challenge)); | 113 auth_sspi.ParseChallenge(challenge)); |
| 114 } | 114 } |
| 115 | 115 |
| 116 TEST(HttpAuthSSPITest, ParseChallenge_MissingTokenSecondRound) { | 116 TEST(HttpAuthSSPITest, ParseChallenge_MissingTokenSecondRound) { |
| 117 // If a later-round challenge is simply "Negotiate", it should be treated as | 117 // If a later-round challenge is simply "Negotiate", it should be treated as |
| 118 // an authentication challenge rejection from the server or proxy. | 118 // an authentication challenge rejection from the server or proxy. |
| 119 MockSSPILibrary mock_library; | 119 MockSSPILibrary mock_library; |
| 120 HttpAuthSSPI auth_sspi(&mock_library, "Negotiate", | 120 HttpAuthSSPI auth_sspi(&mock_library, "Negotiate", |
| 121 NEGOSSP_NAME, kMaxTokenLength); | 121 NEGOSSP_NAME, kMaxTokenLength); |
| 122 std::string first_challenge_text = "Negotiate"; | 122 std::string first_challenge_text = "Negotiate"; |
| 123 HttpAuthChallengeTokenizer first_challenge(first_challenge_text.begin(), | 123 HttpAuthChallengeTokenizer first_challenge(first_challenge_text.begin(), |
| 124 first_challenge_text.end()); | 124 first_challenge_text.end()); |
| 125 EXPECT_EQ(HttpAuth::AUTHORIZATION_RESULT_ACCEPT, | 125 EXPECT_EQ(HttpAuth::AUTHORIZATION_RESULT_ACCEPT, |
| 126 auth_sspi.ParseChallenge(&first_challenge)); | 126 auth_sspi.ParseChallenge(first_challenge)); |
| 127 | 127 |
| 128 std::string auth_token; | 128 std::string auth_token; |
| 129 EXPECT_EQ(OK, auth_sspi.GenerateAuthToken(NULL, "HTTP/intranet.google.com", | 129 EXPECT_EQ(OK, auth_sspi.GenerateAuthToken(NULL, "HTTP/intranet.google.com", |
| 130 &auth_token, | 130 &auth_token, |
| 131 base::Bind(&UnexpectedCallback))); | 131 base::Bind(&UnexpectedCallback))); |
| 132 std::string second_challenge_text = "Negotiate"; | 132 std::string second_challenge_text = "Negotiate"; |
| 133 HttpAuthChallengeTokenizer second_challenge(second_challenge_text.begin(), | 133 HttpAuthChallengeTokenizer second_challenge(second_challenge_text.begin(), |
| 134 second_challenge_text.end()); | 134 second_challenge_text.end()); |
| 135 EXPECT_EQ(HttpAuth::AUTHORIZATION_RESULT_REJECT, | 135 EXPECT_EQ(HttpAuth::AUTHORIZATION_RESULT_REJECT, |
| 136 auth_sspi.ParseChallenge(&second_challenge)); | 136 auth_sspi.ParseChallenge(second_challenge)); |
| 137 } | 137 } |
| 138 | 138 |
| 139 TEST(HttpAuthSSPITest, ParseChallenge_NonBase64EncodedToken) { | 139 TEST(HttpAuthSSPITest, ParseChallenge_NonBase64EncodedToken) { |
| 140 // 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 |
| 141 // be treated as an invalid challenge. | 141 // be treated as an invalid challenge. |
| 142 MockSSPILibrary mock_library; | 142 MockSSPILibrary mock_library; |
| 143 HttpAuthSSPI auth_sspi(&mock_library, "Negotiate", | 143 HttpAuthSSPI auth_sspi(&mock_library, "Negotiate", |
| 144 NEGOSSP_NAME, kMaxTokenLength); | 144 NEGOSSP_NAME, kMaxTokenLength); |
| 145 std::string first_challenge_text = "Negotiate"; | 145 std::string first_challenge_text = "Negotiate"; |
| 146 HttpAuthChallengeTokenizer first_challenge(first_challenge_text.begin(), | 146 HttpAuthChallengeTokenizer first_challenge(first_challenge_text.begin(), |
| 147 first_challenge_text.end()); | 147 first_challenge_text.end()); |
| 148 EXPECT_EQ(HttpAuth::AUTHORIZATION_RESULT_ACCEPT, | 148 EXPECT_EQ(HttpAuth::AUTHORIZATION_RESULT_ACCEPT, |
| 149 auth_sspi.ParseChallenge(&first_challenge)); | 149 auth_sspi.ParseChallenge(first_challenge)); |
| 150 | 150 |
| 151 std::string auth_token; | 151 std::string auth_token; |
| 152 EXPECT_EQ(OK, auth_sspi.GenerateAuthToken(NULL, "HTTP/intranet.google.com", | 152 EXPECT_EQ(OK, auth_sspi.GenerateAuthToken(NULL, "HTTP/intranet.google.com", |
| 153 &auth_token, | 153 &auth_token, |
| 154 base::Bind(&UnexpectedCallback))); | 154 base::Bind(&UnexpectedCallback))); |
| 155 std::string second_challenge_text = "Negotiate =happyjoy="; | 155 std::string second_challenge_text = "Negotiate =happyjoy="; |
| 156 HttpAuthChallengeTokenizer second_challenge(second_challenge_text.begin(), | 156 HttpAuthChallengeTokenizer second_challenge(second_challenge_text.begin(), |
| 157 second_challenge_text.end()); | 157 second_challenge_text.end()); |
| 158 EXPECT_EQ(HttpAuth::AUTHORIZATION_RESULT_INVALID, | 158 EXPECT_EQ(HttpAuth::AUTHORIZATION_RESULT_INVALID, |
| 159 auth_sspi.ParseChallenge(&second_challenge)); | 159 auth_sspi.ParseChallenge(second_challenge)); |
| 160 } | 160 } |
| 161 | 161 |
| 162 } // namespace net | 162 } // namespace net |
| OLD | NEW |