OLD | NEW |
(Empty) | |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef IOS_WEB_PUBLIC_TEST_RESPONSE_PROVIDERS_HTTP_AUTH_RESPONSE_PROVIDER_H_ |
| 6 #define IOS_WEB_PUBLIC_TEST_RESPONSE_PROVIDERS_HTTP_AUTH_RESPONSE_PROVIDER_H_ |
| 7 |
| 8 #include <string> |
| 9 |
| 10 #import "ios/web/public/test/response_providers/html_response_provider.h" |
| 11 #include "url/gurl.h" |
| 12 |
| 13 namespace net { |
| 14 class HttpResponseHeaders; |
| 15 class HttpRequestHeaders; |
| 16 } // namespace net |
| 17 |
| 18 namespace web { |
| 19 |
| 20 // Serves a page which requires Basic HTTP Authentication. |
| 21 class HttpAuthResponseProvider : public HtmlResponseProvider { |
| 22 public: |
| 23 // Constructs provider which will respond to the given |url| and will use the |
| 24 // given authenticaion |realm|. |username| and |password| are credentials |
| 25 // required for sucessfull authentication. Use different realms and |
| 26 // username/password combination for different tests to prevent credentials |
| 27 // caching. |
| 28 HttpAuthResponseProvider(const GURL& url, |
| 29 const std::string& realm, |
| 30 const std::string& username, |
| 31 const std::string& password); |
| 32 ~HttpAuthResponseProvider() override; |
| 33 |
| 34 // HtmlResponseProvider overrides: |
| 35 bool CanHandleRequest(const Request& request) override; |
| 36 void GetResponseHeadersAndBody( |
| 37 const Request& request, |
| 38 scoped_refptr<net::HttpResponseHeaders>* headers, |
| 39 std::string* response_body) override; |
| 40 |
| 41 // Text returned in response if authentication was successfull. |
| 42 static std::string page_text() { return "authenticated"; } |
| 43 |
| 44 private: |
| 45 // Checks if authorization header has valid credintials: |
| 46 // https://tools.ietf.org/html/rfc1945#section-10.2 |
| 47 bool HeadersHaveValidCredentials(const net::HttpRequestHeaders& headers); |
| 48 |
| 49 // URL this provider responds to. |
| 50 GURL url_; |
| 51 // HTTP Authentication realm. |
| 52 std::string realm_; |
| 53 // Correct username to pass authentication |
| 54 std::string username_; |
| 55 // Correct password to pass authentication |
| 56 std::string password_; |
| 57 }; |
| 58 |
| 59 } // namespace web |
| 60 |
| 61 #endif // IOS_WEB_PUBLIC_TEST_RESPONSE_PROVIDERS_HTTP_AUTH_RESPONSE_PROVIDER_H_ |
OLD | NEW |