OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "testing/gtest/include/gtest/gtest.h" | 6 #include "testing/gtest/include/gtest/gtest.h" |
7 | 7 |
8 namespace net { | 8 namespace net { |
9 | 9 |
10 TEST(HttpAuthChallengeTokenizerTest, Basic) { | 10 TEST(HttpAuthChallengeTokenizerTest, Basic) { |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
108 EXPECT_TRUE(parameters.GetNext()); | 108 EXPECT_TRUE(parameters.GetNext()); |
109 EXPECT_TRUE(parameters.valid()); | 109 EXPECT_TRUE(parameters.valid()); |
110 EXPECT_EQ(std::string("realm"), parameters.name()); | 110 EXPECT_EQ(std::string("realm"), parameters.name()); |
111 EXPECT_EQ(std::string("foo"), parameters.value()); | 111 EXPECT_EQ(std::string("foo"), parameters.value()); |
112 EXPECT_FALSE(parameters.GetNext()); | 112 EXPECT_FALSE(parameters.GetNext()); |
113 } | 113 } |
114 | 114 |
115 // Use a name= property which has no value. | 115 // Use a name= property which has no value. |
116 TEST(HttpAuthChallengeTokenizerTest, NoValue) { | 116 TEST(HttpAuthChallengeTokenizerTest, NoValue) { |
117 std::string challenge_str = "Digest qop="; | 117 std::string challenge_str = "Digest qop="; |
118 HttpAuthChallengeTokenizer challenge( | 118 HttpAuthChallengeTokenizer challenge(challenge_str.begin(), |
119 challenge_str.begin(), challenge_str.end()); | 119 challenge_str.end()); |
120 HttpUtil::NameValuePairsIterator parameters = challenge.param_pairs(); | 120 HttpUtil::NameValuePairsIterator parameters = challenge.param_pairs(); |
121 | 121 |
122 EXPECT_TRUE(parameters.valid()); | 122 EXPECT_TRUE(parameters.valid()); |
123 EXPECT_EQ(std::string("Digest"), challenge.scheme()); | 123 EXPECT_EQ(std::string("Digest"), challenge.scheme()); |
124 EXPECT_FALSE(parameters.GetNext()); | 124 EXPECT_FALSE(parameters.GetNext()); |
125 EXPECT_FALSE(parameters.valid()); | 125 EXPECT_FALSE(parameters.valid()); |
126 } | 126 } |
127 | 127 |
128 // Specify multiple properties, comma separated. | 128 // Specify multiple properties, comma separated. |
129 TEST(HttpAuthChallengeTokenizerTest, Multiple) { | 129 TEST(HttpAuthChallengeTokenizerTest, Multiple) { |
(...skipping 17 matching lines...) Expand all Loading... |
147 EXPECT_TRUE(parameters.valid()); | 147 EXPECT_TRUE(parameters.valid()); |
148 EXPECT_EQ(std::string("qop"), parameters.name()); | 148 EXPECT_EQ(std::string("qop"), parameters.name()); |
149 EXPECT_EQ(std::string("auth-int"), parameters.value()); | 149 EXPECT_EQ(std::string("auth-int"), parameters.value()); |
150 EXPECT_FALSE(parameters.GetNext()); | 150 EXPECT_FALSE(parameters.GetNext()); |
151 EXPECT_TRUE(parameters.valid()); | 151 EXPECT_TRUE(parameters.valid()); |
152 } | 152 } |
153 | 153 |
154 // Use a challenge which has no property. | 154 // Use a challenge which has no property. |
155 TEST(HttpAuthChallengeTokenizerTest, NoProperty) { | 155 TEST(HttpAuthChallengeTokenizerTest, NoProperty) { |
156 std::string challenge_str = "NTLM"; | 156 std::string challenge_str = "NTLM"; |
157 HttpAuthChallengeTokenizer challenge( | 157 HttpAuthChallengeTokenizer challenge(challenge_str.begin(), |
158 challenge_str.begin(), challenge_str.end()); | 158 challenge_str.end()); |
159 HttpUtil::NameValuePairsIterator parameters = challenge.param_pairs(); | 159 HttpUtil::NameValuePairsIterator parameters = challenge.param_pairs(); |
160 | 160 |
161 EXPECT_TRUE(parameters.valid()); | 161 EXPECT_TRUE(parameters.valid()); |
162 EXPECT_EQ(std::string("NTLM"), challenge.scheme()); | 162 EXPECT_EQ(std::string("NTLM"), challenge.scheme()); |
163 EXPECT_FALSE(parameters.GetNext()); | 163 EXPECT_FALSE(parameters.GetNext()); |
164 } | 164 } |
165 | 165 |
166 // Use a challenge with Base64 encoded token. | 166 // Use a challenge with Base64 encoded token. |
167 TEST(HttpAuthChallengeTokenizerTest, Base64) { | 167 TEST(HttpAuthChallengeTokenizerTest, Base64) { |
168 std::string challenge_str = "NTLM SGVsbG8sIFdvcmxkCg==="; | 168 std::string challenge_str = "NTLM SGVsbG8sIFdvcmxkCg==="; |
169 HttpAuthChallengeTokenizer challenge(challenge_str.begin(), | 169 HttpAuthChallengeTokenizer challenge(challenge_str.begin(), |
170 challenge_str.end()); | 170 challenge_str.end()); |
171 | 171 |
172 EXPECT_EQ(std::string("NTLM"), challenge.scheme()); | 172 EXPECT_EQ(std::string("NTLM"), challenge.scheme()); |
173 // Notice the two equal statements below due to padding removal. | 173 // Notice the two equal statements below due to padding removal. |
174 EXPECT_EQ(std::string("SGVsbG8sIFdvcmxkCg=="), challenge.base64_param()); | 174 EXPECT_EQ(std::string("SGVsbG8sIFdvcmxkCg=="), challenge.base64_param()); |
175 } | 175 } |
176 | 176 |
177 } // namespace net | 177 } // namespace net |
OLD | NEW |