| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include <string> | 5 #include <string> |
| 6 | 6 |
| 7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
| 8 #include "base/string_util.h" | 8 #include "base/string_util.h" |
| 9 #include "base/utf_string_conversions.h" | 9 #include "base/utf_string_conversions.h" |
| 10 #include "net/base/net_errors.h" | 10 #include "net/base/net_errors.h" |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 59 OK, | 59 OK, |
| 60 "", | 60 "", |
| 61 }, | 61 }, |
| 62 | 62 |
| 63 // Realm is empty string. | 63 // Realm is empty string. |
| 64 { | 64 { |
| 65 "Basic realm=\"\"", | 65 "Basic realm=\"\"", |
| 66 OK, | 66 OK, |
| 67 "", | 67 "", |
| 68 }, | 68 }, |
| 69 |
| 70 // Realm is valid. |
| 71 { |
| 72 "Basic realm=\"test_realm\"", |
| 73 OK, |
| 74 "test_realm", |
| 75 }, |
| 76 |
| 77 // The parser ignores tokens which aren't known. |
| 78 { |
| 79 "Basic realm=\"test_realm\",unknown_token=foobar", |
| 80 OK, |
| 81 "test_realm", |
| 82 }, |
| 83 |
| 84 // The parser skips over tokens which aren't known. |
| 85 { |
| 86 "Basic unknown_token=foobar,realm=\"test_realm\"", |
| 87 OK, |
| 88 "test_realm", |
| 89 }, |
| 90 |
| 91 #if 0 |
| 92 // TODO(cbentzel): It's unclear what the parser should do in these cases. |
| 93 // It seems like this should either be treated as invalid, |
| 94 // or the spaces should be used as a separator. |
| 95 { |
| 96 "Basic realm=\"test_realm\" unknown_token=foobar", |
| 97 OK, |
| 98 "test_realm", |
| 99 }, |
| 100 |
| 101 // The parser skips over tokens which aren't known. |
| 102 { |
| 103 "Basic unknown_token=foobar realm=\"test_realm\"", |
| 104 OK, |
| 105 "test_realm", |
| 106 }, |
| 107 #endif |
| 108 |
| 109 // The parser fails when the first token is not "Basic". |
| 110 { |
| 111 "Negotiate", |
| 112 ERR_INVALID_RESPONSE, |
| 113 "" |
| 114 }, |
| 69 }; | 115 }; |
| 70 HttpAuthHandlerBasic::Factory factory; | 116 HttpAuthHandlerBasic::Factory factory; |
| 71 GURL origin("http://www.example.com"); | 117 GURL origin("http://www.example.com"); |
| 72 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) { | 118 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) { |
| 73 std::string challenge = tests[i].challenge; | 119 std::string challenge = tests[i].challenge; |
| 74 scoped_ptr<HttpAuthHandler> basic; | 120 scoped_ptr<HttpAuthHandler> basic; |
| 75 int rv = factory.CreateAuthHandlerFromString( | 121 int rv = factory.CreateAuthHandlerFromString( |
| 76 challenge, HttpAuth::AUTH_SERVER, origin, BoundNetLog(), &basic); | 122 challenge, HttpAuth::AUTH_SERVER, origin, BoundNetLog(), &basic); |
| 77 EXPECT_EQ(tests[i].expected_rv, rv); | 123 EXPECT_EQ(tests[i].expected_rv, rv); |
| 78 if (rv == OK) | 124 if (rv == OK) |
| 79 EXPECT_EQ(tests[i].expected_realm, basic->realm()); | 125 EXPECT_EQ(tests[i].expected_realm, basic->realm()); |
| 80 } | 126 } |
| 81 } | 127 } |
| 82 | 128 |
| 83 } // namespace net | 129 } // namespace net |
| OLD | NEW |