Index: net/http/http_auth_handler_digest_unittest.cc |
diff --git a/net/http/http_auth_handler_digest_unittest.cc b/net/http/http_auth_handler_digest_unittest.cc |
index 5c3941c9efe3920a2677bdcb3bf7c8847eaa0865..a4723104e45c0edda651d145012892072aed471e 100644 |
--- a/net/http/http_auth_handler_digest_unittest.cc |
+++ b/net/http/http_auth_handler_digest_unittest.cc |
@@ -19,7 +19,7 @@ namespace net { |
namespace { |
const char* const kSimpleChallenge = |
- "Digest realm=\"Oblivion\", nonce=\"nonce-value\""; |
+ "Digest realm=\"Oblivion\", nonce=\"nonce-value\""; |
// RespondToChallenge creates an HttpAuthHandlerDigest for the specified |
// |challenge|, and generates a response to the challenge which is returned in |
@@ -55,7 +55,7 @@ bool RespondToChallenge(HttpAuth::Target target, |
// Create a handler for a particular challenge. |
GURL url_origin(target == HttpAuth::AUTH_SERVER ? request_url : proxy_name); |
int rv_create = factory->CreateAuthHandlerFromString( |
- challenge, target, url_origin.GetOrigin(), BoundNetLog(), &handler); |
+ challenge, target, url_origin.GetOrigin(), BoundNetLog(), &handler); |
if (rv_create != OK || handler.get() == NULL) { |
ADD_FAILURE() << "Unable to create auth handler."; |
return false; |
@@ -82,7 +82,6 @@ bool RespondToChallenge(HttpAuth::Target target, |
} // namespace |
- |
TEST(HttpAuthHandlerDigestTest, ParseChallenge) { |
static const struct { |
// The challenge string. |
@@ -98,255 +97,114 @@ TEST(HttpAuthHandlerDigestTest, ParseChallenge) { |
int parsed_algorithm; |
int parsed_qop; |
} tests[] = { |
- { // Check that a minimal challenge works correctly. |
- "Digest nonce=\"xyz\", realm=\"Thunder Bluff\"", |
- true, |
- "Thunder Bluff", |
- "xyz", |
- "", |
- "", |
- false, |
- HttpAuthHandlerDigest::ALGORITHM_UNSPECIFIED, |
- HttpAuthHandlerDigest::QOP_UNSPECIFIED |
- }, |
- |
- { // Realm does not need to be quoted, even though RFC2617 requires it. |
- "Digest nonce=\"xyz\", realm=ThunderBluff", |
- true, |
- "ThunderBluff", |
- "xyz", |
- "", |
- "", |
- false, |
- HttpAuthHandlerDigest::ALGORITHM_UNSPECIFIED, |
- HttpAuthHandlerDigest::QOP_UNSPECIFIED |
- }, |
- |
- { // We allow the realm to be omitted, and will default it to empty string. |
- // See http://crbug.com/20984. |
- "Digest nonce=\"xyz\"", |
- true, |
- "", |
- "xyz", |
- "", |
- "", |
- false, |
- HttpAuthHandlerDigest::ALGORITHM_UNSPECIFIED, |
- HttpAuthHandlerDigest::QOP_UNSPECIFIED |
- }, |
- |
- { // Try with realm set to empty string. |
- "Digest realm=\"\", nonce=\"xyz\"", |
- true, |
- "", |
- "xyz", |
- "", |
- "", |
- false, |
- HttpAuthHandlerDigest::ALGORITHM_UNSPECIFIED, |
- HttpAuthHandlerDigest::QOP_UNSPECIFIED |
- }, |
- |
- // Handle ISO-8859-1 character as part of the realm. The realm is converted |
- // to UTF-8. However, the credentials will still use the original encoding. |
- { |
- "Digest nonce=\"xyz\", realm=\"foo-\xE5\"", |
- true, |
- "foo-\xC3\xA5", |
- "xyz", |
- "", |
- "", |
- false, |
- HttpAuthHandlerDigest::ALGORITHM_UNSPECIFIED, |
- HttpAuthHandlerDigest::QOP_UNSPECIFIED, |
- }, |
- |
- { // At a minimum, a nonce must be provided. |
- "Digest realm=\"Thunder Bluff\"", |
- false, |
- "", |
- "", |
- "", |
- "", |
- false, |
- HttpAuthHandlerDigest::ALGORITHM_UNSPECIFIED, |
- HttpAuthHandlerDigest::QOP_UNSPECIFIED |
- }, |
- |
- { // The nonce does not need to be quoted, even though RFC2617 |
- // requires it. |
- "Digest nonce=xyz, realm=\"Thunder Bluff\"", |
- true, |
- "Thunder Bluff", |
- "xyz", |
- "", |
- "", |
- false, |
- HttpAuthHandlerDigest::ALGORITHM_UNSPECIFIED, |
- HttpAuthHandlerDigest::QOP_UNSPECIFIED |
- }, |
- |
- { // Unknown authentication parameters are ignored. |
- "Digest nonce=\"xyz\", realm=\"Thunder Bluff\", foo=\"bar\"", |
- true, |
- "Thunder Bluff", |
- "xyz", |
- "", |
- "", |
- false, |
- HttpAuthHandlerDigest::ALGORITHM_UNSPECIFIED, |
- HttpAuthHandlerDigest::QOP_UNSPECIFIED |
- }, |
- |
- { // Check that when algorithm has an unsupported value, parsing fails. |
- "Digest nonce=\"xyz\", algorithm=\"awezum\", realm=\"Thunder\"", |
- false, |
- // The remaining values don't matter (but some have been set already). |
- "", |
- "xyz", |
- "", |
- "", |
- false, |
- HttpAuthHandlerDigest::ALGORITHM_UNSPECIFIED, |
- HttpAuthHandlerDigest::QOP_UNSPECIFIED |
- }, |
- |
- { // Check that algorithm's value is case insensitive, and that MD5 is |
- // a supported algorithm. |
- "Digest nonce=\"xyz\", algorithm=\"mD5\", realm=\"Oblivion\"", |
- true, |
- "Oblivion", |
- "xyz", |
- "", |
- "", |
- false, |
- HttpAuthHandlerDigest::ALGORITHM_MD5, |
- HttpAuthHandlerDigest::QOP_UNSPECIFIED |
- }, |
- |
- { // Check that md5-sess is a supported algorithm. |
- "Digest nonce=\"xyz\", algorithm=\"md5-sess\", realm=\"Oblivion\"", |
- true, |
- "Oblivion", |
- "xyz", |
- "", |
- "", |
- false, |
- HttpAuthHandlerDigest::ALGORITHM_MD5_SESS, |
- HttpAuthHandlerDigest::QOP_UNSPECIFIED, |
- }, |
- |
- { // Check that qop's value is case insensitive, and that auth is known. |
- "Digest nonce=\"xyz\", realm=\"Oblivion\", qop=\"aUth\"", |
- true, |
- "Oblivion", |
- "xyz", |
- "", |
- "", |
- false, |
- HttpAuthHandlerDigest::ALGORITHM_UNSPECIFIED, |
- HttpAuthHandlerDigest::QOP_AUTH |
- }, |
- |
- { // auth-int is not handled, but will fall back to default qop. |
- "Digest nonce=\"xyz\", realm=\"Oblivion\", qop=\"auth-int\"", |
- true, |
- "Oblivion", |
- "xyz", |
- "", |
- "", |
- false, |
- HttpAuthHandlerDigest::ALGORITHM_UNSPECIFIED, |
- HttpAuthHandlerDigest::QOP_UNSPECIFIED |
- }, |
- |
- { // Unknown qop values are ignored. |
- "Digest nonce=\"xyz\", realm=\"Oblivion\", qop=\"auth,foo\"", |
- true, |
- "Oblivion", |
- "xyz", |
- "", |
- "", |
- false, |
- HttpAuthHandlerDigest::ALGORITHM_UNSPECIFIED, |
- HttpAuthHandlerDigest::QOP_AUTH |
- }, |
- |
- { // If auth-int is included with auth, then use auth. |
- "Digest nonce=\"xyz\", realm=\"Oblivion\", qop=\"auth,auth-int\"", |
- true, |
- "Oblivion", |
- "xyz", |
- "", |
- "", |
- false, |
- HttpAuthHandlerDigest::ALGORITHM_UNSPECIFIED, |
- HttpAuthHandlerDigest::QOP_AUTH |
- }, |
- |
- { // Opaque parameter parsing should work correctly. |
- "Digest nonce=\"xyz\", realm=\"Thunder Bluff\", opaque=\"foobar\"", |
- true, |
- "Thunder Bluff", |
- "xyz", |
- "", |
- "foobar", |
- false, |
- HttpAuthHandlerDigest::ALGORITHM_UNSPECIFIED, |
- HttpAuthHandlerDigest::QOP_UNSPECIFIED |
- }, |
- |
- { // Opaque parameters do not need to be quoted, even though RFC2617 |
- // seems to require it. |
- "Digest nonce=\"xyz\", realm=\"Thunder Bluff\", opaque=foobar", |
- true, |
- "Thunder Bluff", |
- "xyz", |
- "", |
- "foobar", |
- false, |
- HttpAuthHandlerDigest::ALGORITHM_UNSPECIFIED, |
- HttpAuthHandlerDigest::QOP_UNSPECIFIED |
- }, |
- |
- { // Domain can be parsed. |
- "Digest nonce=\"xyz\", realm=\"Thunder Bluff\", " |
- "domain=\"http://intranet.example.com/protection\"", |
- true, |
- "Thunder Bluff", |
- "xyz", |
- "http://intranet.example.com/protection", |
- "", |
- false, |
- HttpAuthHandlerDigest::ALGORITHM_UNSPECIFIED, |
- HttpAuthHandlerDigest::QOP_UNSPECIFIED |
- }, |
- |
- { // Multiple domains can be parsed. |
- "Digest nonce=\"xyz\", realm=\"Thunder Bluff\", " |
- "domain=\"http://intranet.example.com/protection http://www.google.com\"", |
- true, |
- "Thunder Bluff", |
- "xyz", |
- "http://intranet.example.com/protection http://www.google.com", |
- "", |
- false, |
- HttpAuthHandlerDigest::ALGORITHM_UNSPECIFIED, |
- HttpAuthHandlerDigest::QOP_UNSPECIFIED |
- }, |
- |
- { // If a non-Digest scheme is somehow passed in, it should be rejected. |
- "Basic realm=\"foo\"", |
- false, |
- "", |
- "", |
- "", |
- "", |
- false, |
- HttpAuthHandlerDigest::ALGORITHM_UNSPECIFIED, |
- HttpAuthHandlerDigest::QOP_UNSPECIFIED |
- }, |
- }; |
+ {// Check that a minimal challenge works correctly. |
+ "Digest nonce=\"xyz\", realm=\"Thunder Bluff\"", true, "Thunder Bluff", |
+ "xyz", "", "", false, HttpAuthHandlerDigest::ALGORITHM_UNSPECIFIED, |
+ HttpAuthHandlerDigest::QOP_UNSPECIFIED}, |
+ {// Realm does not need to be quoted, even though RFC2617 requires it. |
+ "Digest nonce=\"xyz\", realm=ThunderBluff", true, "ThunderBluff", |
+ "xyz", "", "", false, HttpAuthHandlerDigest::ALGORITHM_UNSPECIFIED, |
+ HttpAuthHandlerDigest::QOP_UNSPECIFIED}, |
+ {// We allow the realm to be omitted, and will default it to empty |
+ // string. |
+ // See http://crbug.com/20984. |
+ "Digest nonce=\"xyz\"", true, "", "xyz", "", "", false, |
+ HttpAuthHandlerDigest::ALGORITHM_UNSPECIFIED, |
+ HttpAuthHandlerDigest::QOP_UNSPECIFIED}, |
+ {// Try with realm set to empty string. |
+ "Digest realm=\"\", nonce=\"xyz\"", true, "", "xyz", "", "", false, |
+ HttpAuthHandlerDigest::ALGORITHM_UNSPECIFIED, |
+ HttpAuthHandlerDigest::QOP_UNSPECIFIED}, |
+ |
+ // Handle ISO-8859-1 character as part of the realm. The realm is |
+ // converted |
+ // to UTF-8. However, the credentials will still use the original |
+ // encoding. |
+ { |
+ "Digest nonce=\"xyz\", realm=\"foo-\xE5\"", true, "foo-\xC3\xA5", |
+ "xyz", "", "", false, HttpAuthHandlerDigest::ALGORITHM_UNSPECIFIED, |
+ HttpAuthHandlerDigest::QOP_UNSPECIFIED, |
+ }, |
+ {// At a minimum, a nonce must be provided. |
+ "Digest realm=\"Thunder Bluff\"", false, "", "", "", "", false, |
+ HttpAuthHandlerDigest::ALGORITHM_UNSPECIFIED, |
+ HttpAuthHandlerDigest::QOP_UNSPECIFIED}, |
+ {// The nonce does not need to be quoted, even though RFC2617 |
+ // requires it. |
+ "Digest nonce=xyz, realm=\"Thunder Bluff\"", true, "Thunder Bluff", |
+ "xyz", "", "", false, HttpAuthHandlerDigest::ALGORITHM_UNSPECIFIED, |
+ HttpAuthHandlerDigest::QOP_UNSPECIFIED}, |
+ {// Unknown authentication parameters are ignored. |
+ "Digest nonce=\"xyz\", realm=\"Thunder Bluff\", foo=\"bar\"", true, |
+ "Thunder Bluff", "xyz", "", "", false, |
+ HttpAuthHandlerDigest::ALGORITHM_UNSPECIFIED, |
+ HttpAuthHandlerDigest::QOP_UNSPECIFIED}, |
+ {// Check that when algorithm has an unsupported value, parsing fails. |
+ "Digest nonce=\"xyz\", algorithm=\"awezum\", realm=\"Thunder\"", false, |
+ // The remaining values don't matter (but some have been set already). |
+ "", "xyz", "", "", false, HttpAuthHandlerDigest::ALGORITHM_UNSPECIFIED, |
+ HttpAuthHandlerDigest::QOP_UNSPECIFIED}, |
+ {// Check that algorithm's value is case insensitive, and that MD5 is |
+ // a supported algorithm. |
+ "Digest nonce=\"xyz\", algorithm=\"mD5\", realm=\"Oblivion\"", true, |
+ "Oblivion", "xyz", "", "", false, HttpAuthHandlerDigest::ALGORITHM_MD5, |
+ HttpAuthHandlerDigest::QOP_UNSPECIFIED}, |
+ {// Check that md5-sess is a supported algorithm. |
+ "Digest nonce=\"xyz\", algorithm=\"md5-sess\", realm=\"Oblivion\"", |
+ true, "Oblivion", "xyz", "", "", false, |
+ HttpAuthHandlerDigest::ALGORITHM_MD5_SESS, |
+ HttpAuthHandlerDigest::QOP_UNSPECIFIED, |
+ }, |
+ {// Check that qop's value is case insensitive, and that auth is known. |
+ "Digest nonce=\"xyz\", realm=\"Oblivion\", qop=\"aUth\"", true, |
+ "Oblivion", "xyz", "", "", false, |
+ HttpAuthHandlerDigest::ALGORITHM_UNSPECIFIED, |
+ HttpAuthHandlerDigest::QOP_AUTH}, |
+ {// auth-int is not handled, but will fall back to default qop. |
+ "Digest nonce=\"xyz\", realm=\"Oblivion\", qop=\"auth-int\"", true, |
+ "Oblivion", "xyz", "", "", false, |
+ HttpAuthHandlerDigest::ALGORITHM_UNSPECIFIED, |
+ HttpAuthHandlerDigest::QOP_UNSPECIFIED}, |
+ {// Unknown qop values are ignored. |
+ "Digest nonce=\"xyz\", realm=\"Oblivion\", qop=\"auth,foo\"", true, |
+ "Oblivion", "xyz", "", "", false, |
+ HttpAuthHandlerDigest::ALGORITHM_UNSPECIFIED, |
+ HttpAuthHandlerDigest::QOP_AUTH}, |
+ {// If auth-int is included with auth, then use auth. |
+ "Digest nonce=\"xyz\", realm=\"Oblivion\", qop=\"auth,auth-int\"", |
+ true, "Oblivion", "xyz", "", "", false, |
+ HttpAuthHandlerDigest::ALGORITHM_UNSPECIFIED, |
+ HttpAuthHandlerDigest::QOP_AUTH}, |
+ {// Opaque parameter parsing should work correctly. |
+ "Digest nonce=\"xyz\", realm=\"Thunder Bluff\", opaque=\"foobar\"", |
+ true, "Thunder Bluff", "xyz", "", "foobar", false, |
+ HttpAuthHandlerDigest::ALGORITHM_UNSPECIFIED, |
+ HttpAuthHandlerDigest::QOP_UNSPECIFIED}, |
+ {// Opaque parameters do not need to be quoted, even though RFC2617 |
+ // seems to require it. |
+ "Digest nonce=\"xyz\", realm=\"Thunder Bluff\", opaque=foobar", true, |
+ "Thunder Bluff", "xyz", "", "foobar", false, |
+ HttpAuthHandlerDigest::ALGORITHM_UNSPECIFIED, |
+ HttpAuthHandlerDigest::QOP_UNSPECIFIED}, |
+ {// Domain can be parsed. |
+ "Digest nonce=\"xyz\", realm=\"Thunder Bluff\", " |
+ "domain=\"http://intranet.example.com/protection\"", |
+ true, "Thunder Bluff", "xyz", "http://intranet.example.com/protection", |
+ "", false, HttpAuthHandlerDigest::ALGORITHM_UNSPECIFIED, |
+ HttpAuthHandlerDigest::QOP_UNSPECIFIED}, |
+ {// Multiple domains can be parsed. |
+ "Digest nonce=\"xyz\", realm=\"Thunder Bluff\", " |
+ "domain=\"http://intranet.example.com/protection " |
+ "http://www.google.com\"", |
+ true, "Thunder Bluff", "xyz", |
+ "http://intranet.example.com/protection http://www.google.com", "", |
+ false, HttpAuthHandlerDigest::ALGORITHM_UNSPECIFIED, |
+ HttpAuthHandlerDigest::QOP_UNSPECIFIED}, |
+ {// If a non-Digest scheme is somehow passed in, it should be rejected. |
+ "Basic realm=\"foo\"", false, "", "", "", "", false, |
+ HttpAuthHandlerDigest::ALGORITHM_UNSPECIFIED, |
+ HttpAuthHandlerDigest::QOP_UNSPECIFIED}, |
+ }; |
GURL origin("http://www.example.com"); |
scoped_ptr<HttpAuthHandlerDigest::Factory> factory( |
@@ -393,126 +251,102 @@ TEST(HttpAuthHandlerDigestTest, AssembleCredentials) { |
int nonce_count; |
const char* expected_creds; |
} tests[] = { |
- { // MD5 with username/password |
- "GET", |
- "/test/drealm1", |
- |
- // Challenge |
- "Digest realm=\"DRealm1\", " |
- "nonce=\"claGgoRXBAA=7583377687842fdb7b56ba0555d175baa0b800e3\", " |
- "algorithm=MD5, qop=\"auth\"", |
- |
- "foo", "bar", // username/password |
- "082c875dcb2ca740", // cnonce |
- 1, // nc |
- |
- // Authorization |
- "Digest username=\"foo\", realm=\"DRealm1\", " |
- "nonce=\"claGgoRXBAA=7583377687842fdb7b56ba0555d175baa0b800e3\", " |
- "uri=\"/test/drealm1\", algorithm=MD5, " |
- "response=\"bcfaa62f1186a31ff1b474a19a17cf57\", " |
- "qop=auth, nc=00000001, cnonce=\"082c875dcb2ca740\"" |
- }, |
- |
- { // MD5 with username but empty password. username has space in it. |
- "GET", |
- "/test/drealm1/", |
- |
- // Challenge |
- "Digest realm=\"DRealm1\", " |
- "nonce=\"Ure30oRXBAA=7eca98bbf521ac6642820b11b86bd2d9ed7edc70\", " |
- "algorithm=MD5, qop=\"auth\"", |
- |
- "foo bar", "", // Username/password |
- "082c875dcb2ca740", // cnonce |
- 1, // nc |
- |
- // Authorization |
- "Digest username=\"foo bar\", realm=\"DRealm1\", " |
- "nonce=\"Ure30oRXBAA=7eca98bbf521ac6642820b11b86bd2d9ed7edc70\", " |
- "uri=\"/test/drealm1/\", algorithm=MD5, " |
- "response=\"93c9c6d5930af3b0eb26c745e02b04a0\", " |
- "qop=auth, nc=00000001, cnonce=\"082c875dcb2ca740\"" |
- }, |
- |
- { // MD5 with no username. |
- "GET", |
- "/test/drealm1/", |
- |
- // Challenge |
- "Digest realm=\"DRealm1\", " |
- "nonce=\"7thGplhaBAA=41fb92453c49799cf353c8cd0aabee02d61a98a8\", " |
- "algorithm=MD5, qop=\"auth\"", |
- |
- "", "pass", // Username/password |
- "6509bc74daed8263", // cnonce |
- 1, // nc |
- |
- // Authorization |
- "Digest username=\"\", realm=\"DRealm1\", " |
- "nonce=\"7thGplhaBAA=41fb92453c49799cf353c8cd0aabee02d61a98a8\", " |
- "uri=\"/test/drealm1/\", algorithm=MD5, " |
- "response=\"bc597110f41a62d07f8b70b6977fcb61\", " |
- "qop=auth, nc=00000001, cnonce=\"6509bc74daed8263\"" |
- }, |
- |
- { // MD5 with no username and no password. |
- "GET", |
- "/test/drealm1/", |
- |
- // Challenge |
- "Digest realm=\"DRealm1\", " |
- "nonce=\"s3MzvFhaBAA=4c520af5acd9d8d7ae26947529d18c8eae1e98f4\", " |
- "algorithm=MD5, qop=\"auth\"", |
- |
- "", "", // Username/password |
- "1522e61005789929", // cnonce |
- 1, // nc |
- |
- // Authorization |
- "Digest username=\"\", realm=\"DRealm1\", " |
- "nonce=\"s3MzvFhaBAA=4c520af5acd9d8d7ae26947529d18c8eae1e98f4\", " |
- "uri=\"/test/drealm1/\", algorithm=MD5, " |
- "response=\"22cfa2b30cb500a9591c6d55ec5590a8\", " |
- "qop=auth, nc=00000001, cnonce=\"1522e61005789929\"" |
- }, |
- |
- { // No algorithm, and no qop. |
- "GET", |
- "/", |
- |
- // Challenge |
- "Digest realm=\"Oblivion\", nonce=\"nonce-value\"", |
- |
- "FooBar", "pass", // Username/password |
- "", // cnonce |
- 1, // nc |
- |
- // Authorization |
- "Digest username=\"FooBar\", realm=\"Oblivion\", " |
- "nonce=\"nonce-value\", uri=\"/\", " |
- "response=\"f72ff54ebde2f928860f806ec04acd1b\"" |
- }, |
- |
- { // MD5-sess |
- "GET", |
- "/", |
- |
- // Challenge |
- "Digest realm=\"Baztastic\", nonce=\"AAAAAAAA\", " |
- "algorithm=\"md5-sess\", qop=auth", |
- |
- "USER", "123", // Username/password |
- "15c07961ed8575c4", // cnonce |
- 1, // nc |
- |
- // Authorization |
- "Digest username=\"USER\", realm=\"Baztastic\", " |
- "nonce=\"AAAAAAAA\", uri=\"/\", algorithm=MD5-sess, " |
- "response=\"cbc1139821ee7192069580570c541a03\", " |
- "qop=auth, nc=00000001, cnonce=\"15c07961ed8575c4\"" |
- } |
- }; |
+ {// MD5 with username/password |
+ "GET", "/test/drealm1", |
+ |
+ // Challenge |
+ "Digest realm=\"DRealm1\", " |
+ "nonce=\"claGgoRXBAA=7583377687842fdb7b56ba0555d175baa0b800e3\", " |
+ "algorithm=MD5, qop=\"auth\"", |
+ "foo", "bar", // username/password |
+ "082c875dcb2ca740", // cnonce |
+ 1, // nc |
+ |
+ // Authorization |
+ "Digest username=\"foo\", realm=\"DRealm1\", " |
+ "nonce=\"claGgoRXBAA=7583377687842fdb7b56ba0555d175baa0b800e3\", " |
+ "uri=\"/test/drealm1\", algorithm=MD5, " |
+ "response=\"bcfaa62f1186a31ff1b474a19a17cf57\", " |
+ "qop=auth, nc=00000001, cnonce=\"082c875dcb2ca740\""}, |
+ {// MD5 with username but empty password. username has space in it. |
+ "GET", "/test/drealm1/", |
+ |
+ // Challenge |
+ "Digest realm=\"DRealm1\", " |
+ "nonce=\"Ure30oRXBAA=7eca98bbf521ac6642820b11b86bd2d9ed7edc70\", " |
+ "algorithm=MD5, qop=\"auth\"", |
+ "foo bar", "", // Username/password |
+ "082c875dcb2ca740", // cnonce |
+ 1, // nc |
+ |
+ // Authorization |
+ "Digest username=\"foo bar\", realm=\"DRealm1\", " |
+ "nonce=\"Ure30oRXBAA=7eca98bbf521ac6642820b11b86bd2d9ed7edc70\", " |
+ "uri=\"/test/drealm1/\", algorithm=MD5, " |
+ "response=\"93c9c6d5930af3b0eb26c745e02b04a0\", " |
+ "qop=auth, nc=00000001, cnonce=\"082c875dcb2ca740\""}, |
+ {// MD5 with no username. |
+ "GET", "/test/drealm1/", |
+ |
+ // Challenge |
+ "Digest realm=\"DRealm1\", " |
+ "nonce=\"7thGplhaBAA=41fb92453c49799cf353c8cd0aabee02d61a98a8\", " |
+ "algorithm=MD5, qop=\"auth\"", |
+ "", "pass", // Username/password |
+ "6509bc74daed8263", // cnonce |
+ 1, // nc |
+ |
+ // Authorization |
+ "Digest username=\"\", realm=\"DRealm1\", " |
+ "nonce=\"7thGplhaBAA=41fb92453c49799cf353c8cd0aabee02d61a98a8\", " |
+ "uri=\"/test/drealm1/\", algorithm=MD5, " |
+ "response=\"bc597110f41a62d07f8b70b6977fcb61\", " |
+ "qop=auth, nc=00000001, cnonce=\"6509bc74daed8263\""}, |
+ {// MD5 with no username and no password. |
+ "GET", "/test/drealm1/", |
+ |
+ // Challenge |
+ "Digest realm=\"DRealm1\", " |
+ "nonce=\"s3MzvFhaBAA=4c520af5acd9d8d7ae26947529d18c8eae1e98f4\", " |
+ "algorithm=MD5, qop=\"auth\"", |
+ "", "", // Username/password |
+ "1522e61005789929", // cnonce |
+ 1, // nc |
+ |
+ // Authorization |
+ "Digest username=\"\", realm=\"DRealm1\", " |
+ "nonce=\"s3MzvFhaBAA=4c520af5acd9d8d7ae26947529d18c8eae1e98f4\", " |
+ "uri=\"/test/drealm1/\", algorithm=MD5, " |
+ "response=\"22cfa2b30cb500a9591c6d55ec5590a8\", " |
+ "qop=auth, nc=00000001, cnonce=\"1522e61005789929\""}, |
+ {// No algorithm, and no qop. |
+ "GET", "/", |
+ |
+ // Challenge |
+ "Digest realm=\"Oblivion\", nonce=\"nonce-value\"", "FooBar", |
+ "pass", // Username/password |
+ "", // cnonce |
+ 1, // nc |
+ |
+ // Authorization |
+ "Digest username=\"FooBar\", realm=\"Oblivion\", " |
+ "nonce=\"nonce-value\", uri=\"/\", " |
+ "response=\"f72ff54ebde2f928860f806ec04acd1b\""}, |
+ {// MD5-sess |
+ "GET", "/", |
+ |
+ // Challenge |
+ "Digest realm=\"Baztastic\", nonce=\"AAAAAAAA\", " |
+ "algorithm=\"md5-sess\", qop=auth", |
+ "USER", "123", // Username/password |
+ "15c07961ed8575c4", // cnonce |
+ 1, // nc |
+ |
+ // Authorization |
+ "Digest username=\"USER\", realm=\"Baztastic\", " |
+ "nonce=\"AAAAAAAA\", uri=\"/\", algorithm=MD5-sess, " |
+ "response=\"cbc1139821ee7192069580570c541a03\", " |
+ "qop=auth, nc=00000001, cnonce=\"15c07961ed8575c4\""}}; |
GURL origin("http://www.example.com"); |
scoped_ptr<HttpAuthHandlerDigest::Factory> factory( |
new HttpAuthHandlerDigest::Factory()); |
@@ -528,14 +362,13 @@ TEST(HttpAuthHandlerDigestTest, AssembleCredentials) { |
HttpAuthHandlerDigest* digest = |
static_cast<HttpAuthHandlerDigest*>(handler.get()); |
- std::string creds = |
- digest->AssembleCredentials(tests[i].req_method, |
- tests[i].req_path, |
- AuthCredentials( |
- base::ASCIIToUTF16(tests[i].username), |
- base::ASCIIToUTF16(tests[i].password)), |
- tests[i].cnonce, |
- tests[i].nonce_count); |
+ std::string creds = digest->AssembleCredentials( |
+ tests[i].req_method, |
+ tests[i].req_path, |
+ AuthCredentials(base::ASCIIToUTF16(tests[i].username), |
+ base::ASCIIToUTF16(tests[i].password)), |
+ tests[i].cnonce, |
+ tests[i].nonce_count); |
EXPECT_STREQ(tests[i].expected_creds, creds.c_str()); |
} |
@@ -548,9 +381,11 @@ TEST(HttpAuthHandlerDigest, HandleAnotherChallenge) { |
std::string default_challenge = |
"Digest realm=\"Oblivion\", nonce=\"nonce-value\""; |
GURL origin("intranet.google.com"); |
- int rv = factory->CreateAuthHandlerFromString( |
- default_challenge, HttpAuth::AUTH_SERVER, origin, BoundNetLog(), |
- &handler); |
+ int rv = factory->CreateAuthHandlerFromString(default_challenge, |
+ HttpAuth::AUTH_SERVER, |
+ origin, |
+ BoundNetLog(), |
+ &handler); |
EXPECT_EQ(OK, rv); |
ASSERT_TRUE(handler.get() != NULL); |
HttpAuthChallengeTokenizer tok_default(default_challenge.begin(), |
@@ -580,86 +415,86 @@ TEST(HttpAuthHandlerDigest, HandleAnotherChallenge) { |
TEST(HttpAuthHandlerDigest, RespondToServerChallenge) { |
std::string auth_token; |
- EXPECT_TRUE(RespondToChallenge( |
- HttpAuth::AUTH_SERVER, |
- std::string(), |
- "http://www.example.com/path/to/resource", |
- kSimpleChallenge, |
- &auth_token)); |
- EXPECT_EQ("Digest username=\"foo\", realm=\"Oblivion\", " |
- "nonce=\"nonce-value\", uri=\"/path/to/resource\", " |
- "response=\"6779f90bd0d658f937c1af967614fe84\"", |
- auth_token); |
+ EXPECT_TRUE(RespondToChallenge(HttpAuth::AUTH_SERVER, |
+ std::string(), |
+ "http://www.example.com/path/to/resource", |
+ kSimpleChallenge, |
+ &auth_token)); |
+ EXPECT_EQ( |
+ "Digest username=\"foo\", realm=\"Oblivion\", " |
+ "nonce=\"nonce-value\", uri=\"/path/to/resource\", " |
+ "response=\"6779f90bd0d658f937c1af967614fe84\"", |
+ auth_token); |
} |
TEST(HttpAuthHandlerDigest, RespondToHttpsServerChallenge) { |
std::string auth_token; |
- EXPECT_TRUE(RespondToChallenge( |
- HttpAuth::AUTH_SERVER, |
- std::string(), |
- "https://www.example.com/path/to/resource", |
- kSimpleChallenge, |
- &auth_token)); |
- EXPECT_EQ("Digest username=\"foo\", realm=\"Oblivion\", " |
- "nonce=\"nonce-value\", uri=\"/path/to/resource\", " |
- "response=\"6779f90bd0d658f937c1af967614fe84\"", |
- auth_token); |
+ EXPECT_TRUE(RespondToChallenge(HttpAuth::AUTH_SERVER, |
+ std::string(), |
+ "https://www.example.com/path/to/resource", |
+ kSimpleChallenge, |
+ &auth_token)); |
+ EXPECT_EQ( |
+ "Digest username=\"foo\", realm=\"Oblivion\", " |
+ "nonce=\"nonce-value\", uri=\"/path/to/resource\", " |
+ "response=\"6779f90bd0d658f937c1af967614fe84\"", |
+ auth_token); |
} |
TEST(HttpAuthHandlerDigest, RespondToProxyChallenge) { |
std::string auth_token; |
- EXPECT_TRUE(RespondToChallenge( |
- HttpAuth::AUTH_PROXY, |
- "http://proxy.intranet.corp.com:3128", |
- "http://www.example.com/path/to/resource", |
- kSimpleChallenge, |
- &auth_token)); |
- EXPECT_EQ("Digest username=\"foo\", realm=\"Oblivion\", " |
- "nonce=\"nonce-value\", uri=\"/path/to/resource\", " |
- "response=\"6779f90bd0d658f937c1af967614fe84\"", |
- auth_token); |
+ EXPECT_TRUE(RespondToChallenge(HttpAuth::AUTH_PROXY, |
+ "http://proxy.intranet.corp.com:3128", |
+ "http://www.example.com/path/to/resource", |
+ kSimpleChallenge, |
+ &auth_token)); |
+ EXPECT_EQ( |
+ "Digest username=\"foo\", realm=\"Oblivion\", " |
+ "nonce=\"nonce-value\", uri=\"/path/to/resource\", " |
+ "response=\"6779f90bd0d658f937c1af967614fe84\"", |
+ auth_token); |
} |
TEST(HttpAuthHandlerDigest, RespondToProxyChallengeHttps) { |
std::string auth_token; |
- EXPECT_TRUE(RespondToChallenge( |
- HttpAuth::AUTH_PROXY, |
- "http://proxy.intranet.corp.com:3128", |
- "https://www.example.com/path/to/resource", |
- kSimpleChallenge, |
- &auth_token)); |
- EXPECT_EQ("Digest username=\"foo\", realm=\"Oblivion\", " |
- "nonce=\"nonce-value\", uri=\"www.example.com:443\", " |
- "response=\"3270da8467afbe9ddf2334a48d46e9b9\"", |
- auth_token); |
+ EXPECT_TRUE(RespondToChallenge(HttpAuth::AUTH_PROXY, |
+ "http://proxy.intranet.corp.com:3128", |
+ "https://www.example.com/path/to/resource", |
+ kSimpleChallenge, |
+ &auth_token)); |
+ EXPECT_EQ( |
+ "Digest username=\"foo\", realm=\"Oblivion\", " |
+ "nonce=\"nonce-value\", uri=\"www.example.com:443\", " |
+ "response=\"3270da8467afbe9ddf2334a48d46e9b9\"", |
+ auth_token); |
} |
TEST(HttpAuthHandlerDigest, RespondToProxyChallengeWs) { |
std::string auth_token; |
- EXPECT_TRUE(RespondToChallenge( |
- HttpAuth::AUTH_PROXY, |
- "http://proxy.intranet.corp.com:3128", |
- "ws://www.example.com/echo", |
- kSimpleChallenge, |
- &auth_token)); |
- EXPECT_EQ("Digest username=\"foo\", realm=\"Oblivion\", " |
- "nonce=\"nonce-value\", uri=\"www.example.com:80\", " |
- "response=\"aa1df184f68d5b6ab9d9aa4f88e41b4c\"", |
- auth_token); |
+ EXPECT_TRUE(RespondToChallenge(HttpAuth::AUTH_PROXY, |
+ "http://proxy.intranet.corp.com:3128", |
+ "ws://www.example.com/echo", |
+ kSimpleChallenge, |
+ &auth_token)); |
+ EXPECT_EQ( |
+ "Digest username=\"foo\", realm=\"Oblivion\", " |
+ "nonce=\"nonce-value\", uri=\"www.example.com:80\", " |
+ "response=\"aa1df184f68d5b6ab9d9aa4f88e41b4c\"", |
+ auth_token); |
} |
TEST(HttpAuthHandlerDigest, RespondToProxyChallengeWss) { |
std::string auth_token; |
- EXPECT_TRUE(RespondToChallenge( |
- HttpAuth::AUTH_PROXY, |
- "http://proxy.intranet.corp.com:3128", |
- "wss://www.example.com/echo", |
- kSimpleChallenge, |
- &auth_token)); |
- EXPECT_EQ("Digest username=\"foo\", realm=\"Oblivion\", " |
- "nonce=\"nonce-value\", uri=\"www.example.com:443\", " |
- "response=\"3270da8467afbe9ddf2334a48d46e9b9\"", |
- auth_token); |
+ EXPECT_TRUE(RespondToChallenge(HttpAuth::AUTH_PROXY, |
+ "http://proxy.intranet.corp.com:3128", |
+ "wss://www.example.com/echo", |
+ kSimpleChallenge, |
+ &auth_token)); |
+ EXPECT_EQ( |
+ "Digest username=\"foo\", realm=\"Oblivion\", " |
+ "nonce=\"nonce-value\", uri=\"www.example.com:443\", " |
+ "response=\"3270da8467afbe9ddf2334a48d46e9b9\"", |
+ auth_token); |
} |
TEST(HttpAuthHandlerDigest, RespondToChallengeAuthQop) { |
@@ -670,29 +505,30 @@ TEST(HttpAuthHandlerDigest, RespondToChallengeAuthQop) { |
"http://www.example.com/path/to/resource", |
"Digest realm=\"Oblivion\", nonce=\"nonce-value\", qop=\"auth\"", |
&auth_token)); |
- EXPECT_EQ("Digest username=\"foo\", realm=\"Oblivion\", " |
- "nonce=\"nonce-value\", uri=\"/path/to/resource\", " |
- "response=\"5b1459beda5cee30d6ff9e970a69c0ea\", " |
- "qop=auth, nc=00000001, cnonce=\"client_nonce\"", |
- auth_token); |
+ EXPECT_EQ( |
+ "Digest username=\"foo\", realm=\"Oblivion\", " |
+ "nonce=\"nonce-value\", uri=\"/path/to/resource\", " |
+ "response=\"5b1459beda5cee30d6ff9e970a69c0ea\", " |
+ "qop=auth, nc=00000001, cnonce=\"client_nonce\"", |
+ auth_token); |
} |
TEST(HttpAuthHandlerDigest, RespondToChallengeOpaque) { |
std::string auth_token; |
- EXPECT_TRUE(RespondToChallenge( |
- HttpAuth::AUTH_SERVER, |
- std::string(), |
- "http://www.example.com/path/to/resource", |
- "Digest realm=\"Oblivion\", nonce=\"nonce-value\", " |
- "qop=\"auth\", opaque=\"opaque text\"", |
- &auth_token)); |
- EXPECT_EQ("Digest username=\"foo\", realm=\"Oblivion\", " |
- "nonce=\"nonce-value\", uri=\"/path/to/resource\", " |
- "response=\"5b1459beda5cee30d6ff9e970a69c0ea\", " |
- "opaque=\"opaque text\", " |
- "qop=auth, nc=00000001, cnonce=\"client_nonce\"", |
- auth_token); |
+ EXPECT_TRUE( |
+ RespondToChallenge(HttpAuth::AUTH_SERVER, |
+ std::string(), |
+ "http://www.example.com/path/to/resource", |
+ "Digest realm=\"Oblivion\", nonce=\"nonce-value\", " |
+ "qop=\"auth\", opaque=\"opaque text\"", |
+ &auth_token)); |
+ EXPECT_EQ( |
+ "Digest username=\"foo\", realm=\"Oblivion\", " |
+ "nonce=\"nonce-value\", uri=\"/path/to/resource\", " |
+ "response=\"5b1459beda5cee30d6ff9e970a69c0ea\", " |
+ "opaque=\"opaque text\", " |
+ "qop=auth, nc=00000001, cnonce=\"client_nonce\"", |
+ auth_token); |
} |
- |
-} // namespace net |
+} // namespace net |