diff options
author | cbentzel@chromium.org <cbentzel@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-02-15 14:25:50 +0000 |
---|---|---|
committer | cbentzel@chromium.org <cbentzel@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-02-15 14:25:50 +0000 |
commit | fa55e1931013409ddbce59ed39f8b12a351fd0c4 (patch) | |
tree | 1ff77c48d22f36173c1fa63ae8acb1faf896aa0d /net/http/http_auth_handler_basic_unittest.cc | |
parent | e8da0a0066695284dbf698c9900617b3b159f33b (diff) | |
download | chromium_src-fa55e1931013409ddbce59ed39f8b12a351fd0c4.zip chromium_src-fa55e1931013409ddbce59ed39f8b12a351fd0c4.tar.gz chromium_src-fa55e1931013409ddbce59ed39f8b12a351fd0c4.tar.bz2 |
Added factories for HttpAuthHandler.
The driving rationale for this change was to prevent choosing an AuthHandler when it
is not supported on the system due to a missing runtime component (such as not being
able to locate a gssapi shared library when seeing a Negotiate scheme).
It also has the advantage (currently unused) of determining some per-auth-scheme properties
only the first time that a challenge for that scheme is seen (such as maximum token length for
the SSPI implementation of NTLM).
Finally, it may make unit tests easier to generate since the factory can be easily mocked.
BUG=34795
TEST=New unit test for HttpAuthHandlerDispatchFactory.
Review URL: http://codereview.chromium.org/582007
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@39065 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.cc | 25 |
1 files changed, 13 insertions, 12 deletions
diff --git a/net/http/http_auth_handler_basic_unittest.cc b/net/http/http_auth_handler_basic_unittest.cc index 59d9a56..3536c2c 100644 --- a/net/http/http_auth_handler_basic_unittest.cc +++ b/net/http/http_auth_handler_basic_unittest.cc @@ -25,12 +25,12 @@ TEST(HttpAuthHandlerBasicTest, GenerateAuthToken) { { L"", L"", "Basic Og==" }, }; GURL origin("http://www.example.com"); + HttpAuthHandlerBasic::Factory factory; for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) { std::string challenge = "Basic realm=\"Atlantis\""; - scoped_refptr<HttpAuthHandlerBasic> basic = new HttpAuthHandlerBasic; - bool ok = basic->InitFromChallenge(challenge.begin(), challenge.end(), - HttpAuth::AUTH_SERVER, origin); - EXPECT_TRUE(ok); + scoped_refptr<HttpAuthHandler> basic = new HttpAuthHandlerBasic; + EXPECT_EQ(OK, factory.CreateAuthHandlerFromString( + challenge, HttpAuth::AUTH_SERVER, origin, &basic)); std::string credentials; int rv = basic->GenerateAuthToken(tests[i].username, tests[i].password, @@ -45,32 +45,33 @@ TEST(HttpAuthHandlerBasicTest, GenerateAuthToken) { TEST(HttpAuthHandlerBasicTest, InitFromChallenge) { static const struct { const char* challenge; - bool expected_success; + int expected_rv; const char* expected_realm; } tests[] = { // No realm (we allow this even though realm is supposed to be required // according to RFC 2617.) { "Basic", - true, + OK, "", }, // Realm is empty string. { "Basic realm=\"\"", - true, + OK, "", }, }; + HttpAuthHandlerBasic::Factory factory; 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) + scoped_refptr<HttpAuthHandler> basic = new HttpAuthHandlerBasic; + int rv = factory.CreateAuthHandlerFromString( + challenge, HttpAuth::AUTH_SERVER, origin, &basic); + EXPECT_EQ(tests[i].expected_rv, rv); + if (rv == OK) EXPECT_EQ(tests[i].expected_realm, basic->realm()); } } |