| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "net/http/http_auth_controller.h" | 5 #include "net/http/http_auth_controller.h" |
| 6 | 6 |
| 7 #include "base/strings/utf_string_conversions.h" | 7 #include "base/strings/utf_string_conversions.h" |
| 8 #include "net/base/net_errors.h" | 8 #include "net/base/net_errors.h" |
| 9 #include "net/base/test_completion_callback.h" | 9 #include "net/base/test_completion_callback.h" |
| 10 #include "net/http/http_auth_cache.h" | 10 #include "net/http/http_auth_cache.h" |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 107 | 107 |
| 108 // Now try an async handler that returns | 108 // Now try an async handler that returns |
| 109 // ERR_MISSING_AUTH_CREDENTIALS. Async and sync handlers invoke | 109 // ERR_MISSING_AUTH_CREDENTIALS. Async and sync handlers invoke |
| 110 // different code paths in HttpAuthController when generating | 110 // different code paths in HttpAuthController when generating |
| 111 // tokens. | 111 // tokens. |
| 112 RunSingleRoundAuthTest(RUN_HANDLER_ASYNC, ERR_MISSING_AUTH_CREDENTIALS, OK, | 112 RunSingleRoundAuthTest(RUN_HANDLER_ASYNC, ERR_MISSING_AUTH_CREDENTIALS, OK, |
| 113 SCHEME_IS_DISABLED); | 113 SCHEME_IS_DISABLED); |
| 114 | 114 |
| 115 // If a non-permanent error is returned by the handler, then the | 115 // If a non-permanent error is returned by the handler, then the |
| 116 // controller should report it unchanged. | 116 // controller should report it unchanged. |
| 117 RunSingleRoundAuthTest(RUN_HANDLER_ASYNC, ERR_INVALID_AUTH_CREDENTIALS, | 117 RunSingleRoundAuthTest(RUN_HANDLER_ASYNC, ERR_UNEXPECTED, ERR_UNEXPECTED, |
| 118 ERR_INVALID_AUTH_CREDENTIALS, SCHEME_IS_ENABLED); | 118 SCHEME_IS_ENABLED); |
| 119 |
| 120 // ERR_INVALID_AUTH_CREDENTIALS is special. It's a non-permanet error, but |
| 121 // the error isn't propagated, nor is the auth scheme disabled. This allows |
| 122 // the scheme to re-attempt the authentication attempt using a different set |
| 123 // of credentials. |
| 124 RunSingleRoundAuthTest(RUN_HANDLER_ASYNC, ERR_INVALID_AUTH_CREDENTIALS, OK, |
| 125 SCHEME_IS_ENABLED); |
| 119 } | 126 } |
| 120 | 127 |
| 121 // If an HttpAuthHandler indicates that it doesn't allow explicit | 128 // If an HttpAuthHandler indicates that it doesn't allow explicit |
| 122 // credentials, don't prompt for credentials. | 129 // credentials, don't prompt for credentials. |
| 123 TEST(HttpAuthControllerTest, NoExplicitCredentialsAllowed) { | 130 TEST(HttpAuthControllerTest, NoExplicitCredentialsAllowed) { |
| 124 // Modified mock HttpAuthHandler for this test. | 131 // Modified mock HttpAuthHandler for this test. |
| 125 class MockHandler : public HttpAuthHandlerMock { | 132 class MockHandler : public HttpAuthHandlerMock { |
| 126 public: | 133 public: |
| 127 MockHandler(int expected_rv, HttpAuth::Scheme scheme) | 134 MockHandler(int expected_rv, HttpAuth::Scheme scheme) |
| 128 : expected_scheme_(scheme) { | 135 : expected_scheme_(scheme) { |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 234 EXPECT_TRUE(controller->HaveAuth()); | 241 EXPECT_TRUE(controller->HaveAuth()); |
| 235 EXPECT_TRUE(controller->IsAuthSchemeDisabled(HttpAuth::AUTH_SCHEME_MOCK)); | 242 EXPECT_TRUE(controller->IsAuthSchemeDisabled(HttpAuth::AUTH_SCHEME_MOCK)); |
| 236 EXPECT_FALSE(controller->IsAuthSchemeDisabled(HttpAuth::AUTH_SCHEME_BASIC)); | 243 EXPECT_FALSE(controller->IsAuthSchemeDisabled(HttpAuth::AUTH_SCHEME_BASIC)); |
| 237 | 244 |
| 238 // Should only succeed if we are using the AUTH_SCHEME_BASIC MockHandler. | 245 // Should only succeed if we are using the AUTH_SCHEME_BASIC MockHandler. |
| 239 EXPECT_EQ(OK, controller->MaybeGenerateAuthToken( | 246 EXPECT_EQ(OK, controller->MaybeGenerateAuthToken( |
| 240 &request, CompletionCallback(), dummy_log)); | 247 &request, CompletionCallback(), dummy_log)); |
| 241 } | 248 } |
| 242 | 249 |
| 243 } // namespace net | 250 } // namespace net |
| OLD | NEW |