| Index: ios/web/public/test/response_providers/http_auth_response_provider.h
|
| diff --git a/ios/web/public/test/response_providers/http_auth_response_provider.h b/ios/web/public/test/response_providers/http_auth_response_provider.h
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..1787b38dd8a13947f63d319ce5e9c4edb971b224
|
| --- /dev/null
|
| +++ b/ios/web/public/test/response_providers/http_auth_response_provider.h
|
| @@ -0,0 +1,61 @@
|
| +// Copyright 2017 The Chromium Authors. All rights reserved.
|
| +// Use of this source code is governed by a BSD-style license that can be
|
| +// found in the LICENSE file.
|
| +
|
| +#ifndef IOS_WEB_PUBLIC_TEST_RESPONSE_PROVIDERS_HTTP_AUTH_RESPONSE_PROVIDER_H_
|
| +#define IOS_WEB_PUBLIC_TEST_RESPONSE_PROVIDERS_HTTP_AUTH_RESPONSE_PROVIDER_H_
|
| +
|
| +#include <string>
|
| +
|
| +#import "ios/web/public/test/response_providers/html_response_provider.h"
|
| +#include "url/gurl.h"
|
| +
|
| +namespace net {
|
| +class HttpResponseHeaders;
|
| +class HttpRequestHeaders;
|
| +} // namespace net
|
| +
|
| +namespace web {
|
| +
|
| +// Serves a page which requires Basic HTTP Authentication.
|
| +class HttpAuthResponseProvider : public HtmlResponseProvider {
|
| + public:
|
| + // Constructs provider which will respond to the given |url| and will use the
|
| + // given authenticaion |realm|. |username| and |password| are credentials
|
| + // required for sucessfull authentication. Use different realms and
|
| + // username/password combination for different tests to prevent credentials
|
| + // caching.
|
| + HttpAuthResponseProvider(const GURL& url,
|
| + const std::string& realm,
|
| + const std::string& username,
|
| + const std::string& password);
|
| + ~HttpAuthResponseProvider() override;
|
| +
|
| + // HtmlResponseProvider overrides:
|
| + bool CanHandleRequest(const Request& request) override;
|
| + void GetResponseHeadersAndBody(
|
| + const Request& request,
|
| + scoped_refptr<net::HttpResponseHeaders>* headers,
|
| + std::string* response_body) override;
|
| +
|
| + // Text returned in response if authentication was successfull.
|
| + static std::string page_text() { return "authenticated"; }
|
| +
|
| + private:
|
| + // Checks if authorization header has valid credintials:
|
| + // https://tools.ietf.org/html/rfc1945#section-10.2
|
| + bool HeadersHaveValidCredentials(const net::HttpRequestHeaders& headers);
|
| +
|
| + // URL this provider responds to.
|
| + GURL url_;
|
| + // HTTP Authentication realm.
|
| + std::string realm_;
|
| + // Correct username to pass authentication
|
| + std::string username_;
|
| + // Correct password to pass authentication
|
| + std::string password_;
|
| +};
|
| +
|
| +} // namespace web
|
| +
|
| +#endif // IOS_WEB_PUBLIC_TEST_RESPONSE_PROVIDERS_HTTP_AUTH_RESPONSE_PROVIDER_H_
|
|
|