This source file includes following definitions.
- TEST
- TEST
- TEST
- TEST
- TEST
- TEST
- TEST
- TEST
- TEST
- TEST
#include "net/http/http_auth_challenge_tokenizer.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace net {
TEST(HttpAuthChallengeTokenizerTest, Basic) {
std::string challenge_str = "Basic realm=\"foobar\"";
HttpAuthChallengeTokenizer challenge(challenge_str.begin(),
challenge_str.end());
HttpUtil::NameValuePairsIterator parameters = challenge.param_pairs();
EXPECT_TRUE(parameters.valid());
EXPECT_EQ(std::string("Basic"), challenge.scheme());
EXPECT_TRUE(parameters.GetNext());
EXPECT_TRUE(parameters.valid());
EXPECT_EQ(std::string("realm"), parameters.name());
EXPECT_EQ(std::string("foobar"), parameters.value());
EXPECT_FALSE(parameters.GetNext());
}
TEST(HttpAuthChallengeTokenizerTest, NoQuotes) {
std::string challenge_str = "Basic realm=foobar@baz.com";
HttpAuthChallengeTokenizer challenge(challenge_str.begin(),
challenge_str.end());
HttpUtil::NameValuePairsIterator parameters = challenge.param_pairs();
EXPECT_TRUE(parameters.valid());
EXPECT_EQ(std::string("Basic"), challenge.scheme());
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_FALSE(parameters.GetNext());
}
TEST(HttpAuthChallengeTokenizerTest, MismatchedQuotes) {
std::string challenge_str = "Basic realm=\"foobar@baz.com";
HttpAuthChallengeTokenizer challenge(challenge_str.begin(),
challenge_str.end());
HttpUtil::NameValuePairsIterator parameters = challenge.param_pairs();
EXPECT_TRUE(parameters.valid());
EXPECT_EQ(std::string("Basic"), challenge.scheme());
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_FALSE(parameters.GetNext());
}
TEST(HttpAuthChallengeTokenizerTest, MismatchedQuotesNoValue) {
std::string challenge_str = "Basic realm=\"";
HttpAuthChallengeTokenizer challenge(challenge_str.begin(),
challenge_str.end());
HttpUtil::NameValuePairsIterator parameters = challenge.param_pairs();
EXPECT_TRUE(parameters.valid());
EXPECT_EQ(std::string("Basic"), challenge.scheme());
EXPECT_TRUE(parameters.GetNext());
EXPECT_TRUE(parameters.valid());
EXPECT_EQ(std::string("realm"), parameters.name());
EXPECT_EQ(std::string(), parameters.value());
EXPECT_FALSE(parameters.GetNext());
}
TEST(HttpAuthChallengeTokenizerTest, MismatchedQuotesSpaces) {
std::string challenge_str = "Basic realm=\"foo bar";
HttpAuthChallengeTokenizer challenge(challenge_str.begin(),
challenge_str.end());
HttpUtil::NameValuePairsIterator parameters = challenge.param_pairs();
EXPECT_TRUE(parameters.valid());
EXPECT_EQ(std::string("Basic"), challenge.scheme());
EXPECT_TRUE(parameters.GetNext());
EXPECT_TRUE(parameters.valid());
EXPECT_EQ(std::string("realm"), parameters.name());
EXPECT_EQ(std::string("foo bar"), parameters.value());
EXPECT_FALSE(parameters.GetNext());
}
TEST(HttpAuthChallengeTokenizerTest, MismatchedQuotesMultiple) {
std::string challenge_str = "Digest qop=auth-int, algorithm=md5, realm=\"foo";
HttpAuthChallengeTokenizer challenge(challenge_str.begin(),
challenge_str.end());
HttpUtil::NameValuePairsIterator parameters = challenge.param_pairs();
EXPECT_TRUE(parameters.valid());
EXPECT_EQ(std::string("Digest"), challenge.scheme());
EXPECT_TRUE(parameters.GetNext());
EXPECT_TRUE(parameters.valid());
EXPECT_EQ(std::string("qop"), parameters.name());
EXPECT_EQ(std::string("auth-int"), parameters.value());
EXPECT_TRUE(parameters.GetNext());
EXPECT_TRUE(parameters.valid());
EXPECT_EQ(std::string("algorithm"), parameters.name());
EXPECT_EQ(std::string("md5"), parameters.value());
EXPECT_TRUE(parameters.GetNext());
EXPECT_TRUE(parameters.valid());
EXPECT_EQ(std::string("realm"), parameters.name());
EXPECT_EQ(std::string("foo"), parameters.value());
EXPECT_FALSE(parameters.GetNext());
}
TEST(HttpAuthChallengeTokenizerTest, NoValue) {
std::string challenge_str = "Digest qop=";
HttpAuthChallengeTokenizer challenge(
challenge_str.begin(), challenge_str.end());
HttpUtil::NameValuePairsIterator parameters = challenge.param_pairs();
EXPECT_TRUE(parameters.valid());
EXPECT_EQ(std::string("Digest"), challenge.scheme());
EXPECT_FALSE(parameters.GetNext());
EXPECT_FALSE(parameters.valid());
}
TEST(HttpAuthChallengeTokenizerTest, Multiple) {
std::string challenge_str =
"Digest algorithm=md5, realm=\"Oblivion\", qop=auth-int";
HttpAuthChallengeTokenizer challenge(challenge_str.begin(),
challenge_str.end());
HttpUtil::NameValuePairsIterator parameters = challenge.param_pairs();
EXPECT_TRUE(parameters.valid());
EXPECT_EQ(std::string("Digest"), challenge.scheme());
EXPECT_TRUE(parameters.GetNext());
EXPECT_TRUE(parameters.valid());
EXPECT_EQ(std::string("algorithm"), parameters.name());
EXPECT_EQ(std::string("md5"), parameters.value());
EXPECT_TRUE(parameters.GetNext());
EXPECT_TRUE(parameters.valid());
EXPECT_EQ(std::string("realm"), parameters.name());
EXPECT_EQ(std::string("Oblivion"), parameters.value());
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.GetNext());
EXPECT_TRUE(parameters.valid());
}
TEST(HttpAuthChallengeTokenizerTest, NoProperty) {
std::string challenge_str = "NTLM";
HttpAuthChallengeTokenizer challenge(
challenge_str.begin(), challenge_str.end());
HttpUtil::NameValuePairsIterator parameters = challenge.param_pairs();
EXPECT_TRUE(parameters.valid());
EXPECT_EQ(std::string("NTLM"), challenge.scheme());
EXPECT_FALSE(parameters.GetNext());
}
TEST(HttpAuthChallengeTokenizerTest, Base64) {
std::string challenge_str = "NTLM SGVsbG8sIFdvcmxkCg===";
HttpAuthChallengeTokenizer challenge(challenge_str.begin(),
challenge_str.end());
EXPECT_EQ(std::string("NTLM"), challenge.scheme());
EXPECT_EQ(std::string("SGVsbG8sIFdvcmxkCg=="), challenge.base64_param());
}
}