summaryrefslogtreecommitdiffstats
path: root/net/http/http_auth_unittest.cc
diff options
context:
space:
mode:
authorerikwright@chromium.org <erikwright@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-09-30 13:28:44 +0000
committererikwright@chromium.org <erikwright@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-09-30 13:28:44 +0000
commite3fe59bfb0912596e8975f9c50b01683c19ee5d9 (patch)
tree04b9c722b6f9db105acfc70bd286cb4f78c7d843 /net/http/http_auth_unittest.cc
parentd1cd0715ae8b15982b7ca46f4497eeddb4b73bca (diff)
downloadchromium_src-e3fe59bfb0912596e8975f9c50b01683c19ee5d9.zip
chromium_src-e3fe59bfb0912596e8975f9c50b01683c19ee5d9.tar.gz
chromium_src-e3fe59bfb0912596e8975f9c50b01683c19ee5d9.tar.bz2
Extract name-value pair parsing from http_auth.cc (ChallengeTokenizer) into http_util.cc (NameValuePairsIterator). In preparation for re-use of name-value pair parsing in ChromeFrame (for X-UA-Compatible header).
BUG=None TEST=net_unittests (HttpAuth* and HttpUtilTest.NameValuePairs*) Review URL: http://codereview.chromium.org/3525004 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@61061 0039d316-1c4b-4281-b951-d872f2087c98
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) {