summaryrefslogtreecommitdiffstats
path: root/net/http/http_auth_unittest.cc
diff options
context:
space:
mode:
Diffstat (limited to 'net/http/http_auth_unittest.cc')
-rw-r--r--net/http/http_auth_unittest.cc193
1 files changed, 104 insertions, 89 deletions
diff --git a/net/http/http_auth_unittest.cc b/net/http/http_auth_unittest.cc
index cc62214..913e1cc 100644
--- a/net/http/http_auth_unittest.cc
+++ b/net/http/http_auth_unittest.cc
@@ -188,15 +188,17 @@ TEST(HttpAuthTest, ChallengeTokenizer) {
std::string challenge_str = "Basic realm=\"foobar\"";
HttpAuth::ChallengeTokenizer challenge(challenge_str.begin(),
challenge_str.end());
- EXPECT_TRUE(challenge.valid());
+ HttpUtil::NameValuePairsIterator parameters = challenge.param_pairs();
+
+ EXPECT_TRUE(parameters.valid());
EXPECT_EQ(std::string("Basic"), challenge.scheme());
- EXPECT_TRUE(challenge.GetNext());
- EXPECT_TRUE(challenge.valid());
- EXPECT_EQ(std::string("realm"), challenge.name());
- EXPECT_EQ(std::string("foobar"), challenge.unquoted_value());
- EXPECT_EQ(std::string("\"foobar\""), challenge.value());
- EXPECT_TRUE(challenge.value_is_quoted());
- EXPECT_FALSE(challenge.GetNext());
+ EXPECT_TRUE(parameters.GetNext());
+ EXPECT_TRUE(parameters.valid());
+ EXPECT_EQ(std::string("realm"), parameters.name());
+ EXPECT_EQ(std::string("foobar"), parameters.unquoted_value());
+ EXPECT_EQ(std::string("\"foobar\""), parameters.value());
+ EXPECT_TRUE(parameters.value_is_quoted());
+ EXPECT_FALSE(parameters.GetNext());
}
// Use a name=value property with no quote marks.
@@ -204,15 +206,17 @@ TEST(HttpAuthTest, ChallengeTokenizerNoQuotes) {
std::string challenge_str = "Basic realm=foobar@baz.com";
HttpAuth::ChallengeTokenizer challenge(challenge_str.begin(),
challenge_str.end());
- EXPECT_TRUE(challenge.valid());
+ HttpUtil::NameValuePairsIterator parameters = challenge.param_pairs();
+
+ EXPECT_TRUE(parameters.valid());
EXPECT_EQ(std::string("Basic"), challenge.scheme());
- EXPECT_TRUE(challenge.GetNext());
- EXPECT_TRUE(challenge.valid());
- EXPECT_EQ(std::string("realm"), challenge.name());
- EXPECT_EQ(std::string("foobar@baz.com"), challenge.value());
- EXPECT_EQ(std::string("foobar@baz.com"), challenge.unquoted_value());
- EXPECT_FALSE(challenge.value_is_quoted());
- EXPECT_FALSE(challenge.GetNext());
+ EXPECT_TRUE(parameters.GetNext());
+ EXPECT_TRUE(parameters.valid());
+ EXPECT_EQ(std::string("realm"), parameters.name());
+ EXPECT_EQ(std::string("foobar@baz.com"), parameters.value());
+ EXPECT_EQ(std::string("foobar@baz.com"), parameters.unquoted_value());
+ EXPECT_FALSE(parameters.value_is_quoted());
+ EXPECT_FALSE(parameters.GetNext());
}
// Use a name=value property with mismatching quote marks.
@@ -220,15 +224,17 @@ TEST(HttpAuthTest, ChallengeTokenizerMismatchedQuotes) {
std::string challenge_str = "Basic realm=\"foobar@baz.com";
HttpAuth::ChallengeTokenizer challenge(challenge_str.begin(),
challenge_str.end());
- EXPECT_TRUE(challenge.valid());
+ HttpUtil::NameValuePairsIterator parameters = challenge.param_pairs();
+
+ EXPECT_TRUE(parameters.valid());
EXPECT_EQ(std::string("Basic"), challenge.scheme());
- EXPECT_TRUE(challenge.GetNext());
- EXPECT_TRUE(challenge.valid());
- EXPECT_EQ(std::string("realm"), challenge.name());
- EXPECT_EQ(std::string("foobar@baz.com"), challenge.value());
- EXPECT_EQ(std::string("foobar@baz.com"), challenge.unquoted_value());
- EXPECT_FALSE(challenge.value_is_quoted());
- EXPECT_FALSE(challenge.GetNext());
+ EXPECT_TRUE(parameters.GetNext());
+ EXPECT_TRUE(parameters.valid());
+ EXPECT_EQ(std::string("realm"), parameters.name());
+ EXPECT_EQ(std::string("foobar@baz.com"), parameters.value());
+ EXPECT_EQ(std::string("foobar@baz.com"), parameters.unquoted_value());
+ EXPECT_FALSE(parameters.value_is_quoted());
+ EXPECT_FALSE(parameters.GetNext());
}
// Use a name= property without a value and with mismatching quote marks.
@@ -236,14 +242,16 @@ TEST(HttpAuthTest, ChallengeTokenizerMismatchedQuotesNoValue) {
std::string challenge_str = "Basic realm=\"";
HttpAuth::ChallengeTokenizer challenge(challenge_str.begin(),
challenge_str.end());
- EXPECT_TRUE(challenge.valid());
+ HttpUtil::NameValuePairsIterator parameters = challenge.param_pairs();
+
+ EXPECT_TRUE(parameters.valid());
EXPECT_EQ(std::string("Basic"), challenge.scheme());
- EXPECT_TRUE(challenge.GetNext());
- EXPECT_TRUE(challenge.valid());
- EXPECT_EQ(std::string("realm"), challenge.name());
- EXPECT_EQ(std::string(""), challenge.value());
- EXPECT_FALSE(challenge.value_is_quoted());
- EXPECT_FALSE(challenge.GetNext());
+ EXPECT_TRUE(parameters.GetNext());
+ EXPECT_TRUE(parameters.valid());
+ EXPECT_EQ(std::string("realm"), parameters.name());
+ EXPECT_EQ(std::string(""), parameters.value());
+ EXPECT_FALSE(parameters.value_is_quoted());
+ EXPECT_FALSE(parameters.GetNext());
}
// Use a name=value property with mismatching quote marks and spaces in the
@@ -252,15 +260,17 @@ TEST(HttpAuthTest, ChallengeTokenizerMismatchedQuotesSpaces) {
std::string challenge_str = "Basic realm=\"foo bar";
HttpAuth::ChallengeTokenizer challenge(challenge_str.begin(),
challenge_str.end());
- EXPECT_TRUE(challenge.valid());
+ HttpUtil::NameValuePairsIterator parameters = challenge.param_pairs();
+
+ EXPECT_TRUE(parameters.valid());
EXPECT_EQ(std::string("Basic"), challenge.scheme());
- EXPECT_TRUE(challenge.GetNext());
- EXPECT_TRUE(challenge.valid());
- EXPECT_EQ(std::string("realm"), challenge.name());
- EXPECT_EQ(std::string("foo bar"), challenge.value());
- EXPECT_EQ(std::string("foo bar"), challenge.unquoted_value());
- EXPECT_FALSE(challenge.value_is_quoted());
- EXPECT_FALSE(challenge.GetNext());
+ EXPECT_TRUE(parameters.GetNext());
+ EXPECT_TRUE(parameters.valid());
+ EXPECT_EQ(std::string("realm"), parameters.name());
+ EXPECT_EQ(std::string("foo bar"), parameters.value());
+ EXPECT_EQ(std::string("foo bar"), parameters.unquoted_value());
+ EXPECT_FALSE(parameters.value_is_quoted());
+ EXPECT_FALSE(parameters.GetNext());
}
// Use multiple name=value properties with mismatching quote marks in the last
@@ -269,26 +279,28 @@ TEST(HttpAuthTest, ChallengeTokenizerMismatchedQuotesMultiple) {
std::string challenge_str = "Digest qop=, algorithm=md5, realm=\"foo";
HttpAuth::ChallengeTokenizer challenge(challenge_str.begin(),
challenge_str.end());
- EXPECT_TRUE(challenge.valid());
+ HttpUtil::NameValuePairsIterator parameters = challenge.param_pairs();
+
+ EXPECT_TRUE(parameters.valid());
EXPECT_EQ(std::string("Digest"), challenge.scheme());
- EXPECT_TRUE(challenge.GetNext());
- EXPECT_TRUE(challenge.valid());
- EXPECT_EQ(std::string("qop"), challenge.name());
- EXPECT_EQ(std::string(""), challenge.value());
- EXPECT_FALSE(challenge.value_is_quoted());
- EXPECT_TRUE(challenge.GetNext());
- EXPECT_TRUE(challenge.valid());
- EXPECT_EQ(std::string("algorithm"), challenge.name());
- EXPECT_EQ(std::string("md5"), challenge.value());
- EXPECT_EQ(std::string("md5"), challenge.unquoted_value());
- EXPECT_FALSE(challenge.value_is_quoted());
- EXPECT_TRUE(challenge.GetNext());
- EXPECT_TRUE(challenge.valid());
- EXPECT_EQ(std::string("realm"), challenge.name());
- EXPECT_EQ(std::string("foo"), challenge.value());
- EXPECT_EQ(std::string("foo"), challenge.unquoted_value());
- EXPECT_FALSE(challenge.value_is_quoted());
- EXPECT_FALSE(challenge.GetNext());
+ EXPECT_TRUE(parameters.GetNext());
+ EXPECT_TRUE(parameters.valid());
+ EXPECT_EQ(std::string("qop"), parameters.name());
+ EXPECT_EQ(std::string(""), parameters.value());
+ EXPECT_FALSE(parameters.value_is_quoted());
+ EXPECT_TRUE(parameters.GetNext());
+ EXPECT_TRUE(parameters.valid());
+ EXPECT_EQ(std::string("algorithm"), parameters.name());
+ EXPECT_EQ(std::string("md5"), parameters.value());
+ EXPECT_EQ(std::string("md5"), parameters.unquoted_value());
+ EXPECT_FALSE(parameters.value_is_quoted());
+ EXPECT_TRUE(parameters.GetNext());
+ EXPECT_TRUE(parameters.valid());
+ EXPECT_EQ(std::string("realm"), parameters.name());
+ EXPECT_EQ(std::string("foo"), parameters.value());
+ EXPECT_EQ(std::string("foo"), parameters.unquoted_value());
+ EXPECT_FALSE(parameters.value_is_quoted());
+ EXPECT_FALSE(parameters.GetNext());
}
// Use a name= property which has no value.
@@ -296,14 +308,16 @@ TEST(HttpAuthTest, ChallengeTokenizerNoValue) {
std::string challenge_str = "Digest qop=";
HttpAuth::ChallengeTokenizer challenge(
challenge_str.begin(), challenge_str.end());
- EXPECT_TRUE(challenge.valid());
+ HttpUtil::NameValuePairsIterator parameters = challenge.param_pairs();
+
+ EXPECT_TRUE(parameters.valid());
EXPECT_EQ(std::string("Digest"), challenge.scheme());
- EXPECT_TRUE(challenge.GetNext());
- EXPECT_TRUE(challenge.valid());
- EXPECT_EQ(std::string("qop"), challenge.name());
- EXPECT_EQ(std::string(""), challenge.value());
- EXPECT_FALSE(challenge.value_is_quoted());
- EXPECT_FALSE(challenge.GetNext());
+ EXPECT_TRUE(parameters.GetNext());
+ EXPECT_TRUE(parameters.valid());
+ EXPECT_EQ(std::string("qop"), parameters.name());
+ EXPECT_EQ(std::string(""), parameters.value());
+ EXPECT_FALSE(parameters.value_is_quoted());
+ EXPECT_FALSE(parameters.GetNext());
}
// Specify multiple properties, comma separated.
@@ -312,24 +326,26 @@ TEST(HttpAuthTest, ChallengeTokenizerMultiple) {
"Digest algorithm=md5, realm=\"Oblivion\", qop=auth-int";
HttpAuth::ChallengeTokenizer challenge(challenge_str.begin(),
challenge_str.end());
- EXPECT_TRUE(challenge.valid());
+ HttpUtil::NameValuePairsIterator parameters = challenge.param_pairs();
+
+ EXPECT_TRUE(parameters.valid());
EXPECT_EQ(std::string("Digest"), challenge.scheme());
- EXPECT_TRUE(challenge.GetNext());
- EXPECT_TRUE(challenge.valid());
- EXPECT_EQ(std::string("algorithm"), challenge.name());
- EXPECT_EQ(std::string("md5"), challenge.value());
- EXPECT_FALSE(challenge.value_is_quoted());
- EXPECT_TRUE(challenge.GetNext());
- EXPECT_TRUE(challenge.valid());
- EXPECT_EQ(std::string("realm"), challenge.name());
- EXPECT_EQ(std::string("Oblivion"), challenge.unquoted_value());
- EXPECT_TRUE(challenge.value_is_quoted());
- EXPECT_TRUE(challenge.GetNext());
- EXPECT_TRUE(challenge.valid());
- EXPECT_EQ(std::string("qop"), challenge.name());
- EXPECT_EQ(std::string("auth-int"), challenge.value());
- EXPECT_FALSE(challenge.value_is_quoted());
- EXPECT_FALSE(challenge.GetNext());
+ EXPECT_TRUE(parameters.GetNext());
+ EXPECT_TRUE(parameters.valid());
+ EXPECT_EQ(std::string("algorithm"), parameters.name());
+ EXPECT_EQ(std::string("md5"), parameters.value());
+ EXPECT_FALSE(parameters.value_is_quoted());
+ EXPECT_TRUE(parameters.GetNext());
+ EXPECT_TRUE(parameters.valid());
+ EXPECT_EQ(std::string("realm"), parameters.name());
+ EXPECT_EQ(std::string("Oblivion"), parameters.unquoted_value());
+ EXPECT_TRUE(parameters.value_is_quoted());
+ EXPECT_TRUE(parameters.GetNext());
+ EXPECT_TRUE(parameters.valid());
+ EXPECT_EQ(std::string("qop"), parameters.name());
+ EXPECT_EQ(std::string("auth-int"), parameters.value());
+ EXPECT_FALSE(parameters.value_is_quoted());
+ EXPECT_FALSE(parameters.GetNext());
}
// Use a challenge which has no property.
@@ -337,9 +353,11 @@ TEST(HttpAuthTest, ChallengeTokenizerNoProperty) {
std::string challenge_str = "NTLM";
HttpAuth::ChallengeTokenizer challenge(
challenge_str.begin(), challenge_str.end());
- EXPECT_TRUE(challenge.valid());
+ HttpUtil::NameValuePairsIterator parameters = challenge.param_pairs();
+
+ EXPECT_TRUE(parameters.valid());
EXPECT_EQ(std::string("NTLM"), challenge.scheme());
- EXPECT_FALSE(challenge.GetNext());
+ EXPECT_FALSE(parameters.GetNext());
}
// Use a challenge with Base64 encoded token.
@@ -347,13 +365,10 @@ TEST(HttpAuthTest, ChallengeTokenizerBase64) {
std::string challenge_str = "NTLM SGVsbG8sIFdvcmxkCg===";
HttpAuth::ChallengeTokenizer challenge(challenge_str.begin(),
challenge_str.end());
- EXPECT_TRUE(challenge.valid());
+
EXPECT_EQ(std::string("NTLM"), challenge.scheme());
- challenge.set_expect_base64_token(true);
- EXPECT_TRUE(challenge.GetNext());
// Notice the two equal statements below due to padding removal.
- EXPECT_EQ(std::string("SGVsbG8sIFdvcmxkCg=="), challenge.value());
- EXPECT_FALSE(challenge.GetNext());
+ EXPECT_EQ(std::string("SGVsbG8sIFdvcmxkCg=="), challenge.base64_param());
}
TEST(HttpAuthTest, GetChallengeHeaderName) {