summaryrefslogtreecommitdiffstats
path: root/net/http/http_auth_handler_basic_unittest.cc
diff options
context:
space:
mode:
authoreroman@chromium.org <eroman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-09-21 19:56:19 +0000
committereroman@chromium.org <eroman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-09-21 19:56:19 +0000
commit22927adeb7d392dfee17a90657f51bf12d8a5766 (patch)
treeaf02aa3e92b63d25d9f7c94143a8c5176d6105e1 /net/http/http_auth_handler_basic_unittest.cc
parentf7e69b50e1af50ff848ce896db8d4e51c037d279 (diff)
downloadchromium_src-22927adeb7d392dfee17a90657f51bf12d8a5766.zip
chromium_src-22927adeb7d392dfee17a90657f51bf12d8a5766.tar.gz
chromium_src-22927adeb7d392dfee17a90657f51bf12d8a5766.tar.bz2
Allow the realm in BASIC and DIGEST challenges to not be specified.
This goes against RFC 2617 which states they are required parameters, but apparently there are servers which do this, and other browsers are less strict. Also allow the empty string as a valid realm value (previously this was being disallowed as an implementation bug to check if it was not specified). BUG=12565,20984 Review URL: http://codereview.chromium.org/211040 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@26723 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/http/http_auth_handler_basic_unittest.cc')
-rw-r--r--net/http/http_auth_handler_basic_unittest.cc38
1 files changed, 36 insertions, 2 deletions
diff --git a/net/http/http_auth_handler_basic_unittest.cc b/net/http/http_auth_handler_basic_unittest.cc
index ca2004c..d7a1437 100644
--- a/net/http/http_auth_handler_basic_unittest.cc
+++ b/net/http/http_auth_handler_basic_unittest.cc
@@ -27,8 +27,9 @@ TEST(HttpAuthHandlerBasicTest, GenerateCredentials) {
for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) {
std::string challenge = "Basic realm=\"Atlantis\"";
scoped_refptr<HttpAuthHandlerBasic> basic = new HttpAuthHandlerBasic;
- basic->InitFromChallenge(challenge.begin(), challenge.end(),
- HttpAuth::AUTH_SERVER, origin);
+ bool ok = basic->InitFromChallenge(challenge.begin(), challenge.end(),
+ HttpAuth::AUTH_SERVER, origin);
+ EXPECT_TRUE(ok);
std::string credentials = basic->GenerateCredentials(tests[i].username,
tests[i].password,
NULL, NULL);
@@ -36,4 +37,37 @@ TEST(HttpAuthHandlerBasicTest, GenerateCredentials) {
}
}
+TEST(HttpAuthHandlerBasicTest, InitFromChallenge) {
+ static const struct {
+ const char* challenge;
+ bool expected_success;
+ const char* expected_realm;
+ } tests[] = {
+ // No realm (we allow this even though realm is supposed to be required
+ // according to RFC 2617.)
+ {
+ "Basic",
+ true,
+ "",
+ },
+
+ // Realm is empty string.
+ {
+ "Basic realm=\"\"",
+ true,
+ "",
+ },
+ };
+ GURL origin("http://www.example.com");
+ for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) {
+ std::string challenge = tests[i].challenge;
+ scoped_refptr<HttpAuthHandlerBasic> basic = new HttpAuthHandlerBasic;
+ bool ok = basic->InitFromChallenge(challenge.begin(), challenge.end(),
+ HttpAuth::AUTH_SERVER, origin);
+ EXPECT_EQ(tests[i].expected_success, ok);
+ if (ok)
+ EXPECT_EQ(tests[i].expected_realm, basic->realm());
+ }
+}
+
} // namespace net