Commit 3803ad75 authored by Simon Zünd's avatar Simon Zünd Committed by Commit Bot

Make TrustTokenBrowsertest available in a header

Moving the TrustTokenBrowsertest class into a header will allow
DevTools to re-use the functionality in its own browser tests for
upcoming Trust Token debugging features.

The CL https://crrev.com/c/2516225 is an example where DevTools
and TrustToken browsertests are combined.

R=davidvc@chromium.org

Bug: chromium:1141652
Change-Id: Ibd9d9a75738d17d9eb1cc33359063ad4bd99b860
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2517947
Commit-Queue: Simon Zünd <szuend@chromium.org>
Reviewed-by: default avatarSigurd Schneider <sigurds@chromium.org>
Reviewed-by: default avatarDavid Van Cleve <davidvc@chromium.org>
Cr-Commit-Position: refs/heads/master@{#824353}
parent 5f9e3f9f
...@@ -1210,6 +1210,7 @@ test("content_browsertests") { ...@@ -1210,6 +1210,7 @@ test("content_browsertests") {
"../test/content_browser_test_test.cc", "../test/content_browser_test_test.cc",
"../test/top_frame_population_browsertest.cc", "../test/top_frame_population_browsertest.cc",
"../test/trust_token_browsertest.cc", "../test/trust_token_browsertest.cc",
"../test/trust_token_browsertest.h",
"../test/trust_token_origin_trial_browsertest.cc", "../test/trust_token_origin_trial_browsertest.cc",
"../test/trust_token_parameters_browsertest.cc", "../test/trust_token_parameters_browsertest.cc",
"../test/url_loader_interceptor_test.cc", "../test/url_loader_interceptor_test.cc",
......
...@@ -2,6 +2,8 @@ ...@@ -2,6 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#include "content/test/trust_token_browsertest.h"
#include <memory> #include <memory>
#include <string> #include <string>
...@@ -43,38 +45,24 @@ namespace content { ...@@ -43,38 +45,24 @@ namespace content {
namespace { namespace {
using network::test::TrustTokenRequestHandler;
using ::testing::Field; using ::testing::Field;
using ::testing::HasSubstr; using ::testing::HasSubstr;
using ::testing::IsFalse; using ::testing::IsFalse;
using ::testing::Optional; using ::testing::Optional;
// TrustTokenBrowsertest is a fixture containing boilerplate for initializing an } // namespace
// HTTPS test server and passing requests through to an embedded instance of
// network::test::TrustTokenRequestHandler, which contains the guts of the TrustTokenBrowsertest::TrustTokenBrowsertest() {
// "server-side" token issuance and redemption logic as well as some consistency
// checks for subsequent signed requests.
class TrustTokenBrowsertest : public ContentBrowserTest {
public:
TrustTokenBrowsertest() {
auto& field_trial_param = auto& field_trial_param =
network::features::kTrustTokenOperationsRequiringOriginTrial; network::features::kTrustTokenOperationsRequiringOriginTrial;
features_.InitAndEnableFeatureWithParameters( features_.InitAndEnableFeatureWithParameters(
network::features::kTrustTokens, network::features::kTrustTokens,
{{field_trial_param.name, {{field_trial_param.name,
field_trial_param.GetName( field_trial_param.GetName(network::features::TrustTokenOriginTrialSpec::
network::features::TrustTokenOriginTrialSpec::
kOriginTrialNotRequired)}}); kOriginTrialNotRequired)}});
} }
// Registers the following handlers: void TrustTokenBrowsertest::SetUpOnMainThread() {
// - default //content/test/data files;
// - a special "/issue" endpoint executing Trust Tokens issuance;
// - a special "/redeem" endpoint executing redemption; and
// - a special "/sign" endpoint that verifies that the received signed request
// data is correctly structured and that the provided Sec-Signature header's
// verification key was previously bound to a successful token redemption.
void SetUpOnMainThread() override {
host_resolver()->AddRule("*", "127.0.0.1"); host_resolver()->AddRule("*", "127.0.0.1");
server_.SetSSLConfig(net::EmbeddedTestServer::CERT_TEST_NAMES); server_.SetSSLConfig(net::EmbeddedTestServer::CERT_TEST_NAMES);
...@@ -87,14 +75,10 @@ class TrustTokenBrowsertest : public ContentBrowserTest { ...@@ -87,14 +75,10 @@ class TrustTokenBrowsertest : public ContentBrowserTest {
network::test::RegisterTrustTokenTestHandlers(&server_, &request_handler_); network::test::RegisterTrustTokenTestHandlers(&server_, &request_handler_);
ASSERT_TRUE(server_.Start()); ASSERT_TRUE(server_.Start());
} }
protected: void TrustTokenBrowsertest::ProvideRequestHandlerKeyCommitmentsToNetworkService(
// Provides the network service key commitments from the internal std::vector<base::StringPiece> hosts) {
// TrustTokenRequestHandler. All hosts in |hosts| will be provided identical
// commitments.
void ProvideRequestHandlerKeyCommitmentsToNetworkService(
std::vector<base::StringPiece> hosts = {}) {
base::flat_map<url::Origin, base::StringPiece> origins_and_commitments; base::flat_map<url::Origin, base::StringPiece> origins_and_commitments;
std::string key_commitments = request_handler_.GetKeyCommitmentRecord(); std::string key_commitments = request_handler_.GetKeyCommitmentRecord();
...@@ -105,8 +89,7 @@ class TrustTokenBrowsertest : public ContentBrowserTest { ...@@ -105,8 +89,7 @@ class TrustTokenBrowsertest : public ContentBrowserTest {
GURL::Replacements replacements; GURL::Replacements replacements;
replacements.SetHostStr(host); replacements.SetHostStr(host);
origins_and_commitments.insert_or_assign( origins_and_commitments.insert_or_assign(
url::Origin::Create( url::Origin::Create(server_.base_url().ReplaceComponents(replacements)),
server_.base_url().ReplaceComponents(replacements)),
key_commitments); key_commitments);
} }
...@@ -117,31 +100,16 @@ class TrustTokenBrowsertest : public ContentBrowserTest { ...@@ -117,31 +100,16 @@ class TrustTokenBrowsertest : public ContentBrowserTest {
base::RunLoop run_loop; base::RunLoop run_loop;
GetNetworkService()->SetTrustTokenKeyCommitments( GetNetworkService()->SetTrustTokenKeyCommitments(
network::WrapKeyCommitmentsForIssuers( network::WrapKeyCommitmentsForIssuers(std::move(origins_and_commitments)),
std::move(origins_and_commitments)),
run_loop.QuitClosure()); run_loop.QuitClosure());
run_loop.Run(); run_loop.Run();
} }
// Given a host (e.g. "a.test"), returns the corresponding storage origin std::string TrustTokenBrowsertest::IssuanceOriginFromHost(
// for Trust Tokens state. (This adds the correct scheme---probably https---as const std::string& host) const {
// well as |server_|'s port, which can vary from test to test. There's no
// ambiguity in the result because the scheme and port are both fixed across
// all domains.)
std::string IssuanceOriginFromHost(const std::string& host) const {
auto ret = url::Origin::Create(server_.GetURL(host, "/")).Serialize(); auto ret = url::Origin::Create(server_.GetURL(host, "/")).Serialize();
return ret; return ret;
} }
base::test::ScopedFeatureList features_;
// TODO(davidvc): Extend this to support more than one key set.
TrustTokenRequestHandler request_handler_;
net::EmbeddedTestServer server_{net::EmbeddedTestServer::TYPE_HTTPS};
};
} // namespace
IN_PROC_BROWSER_TEST_F(TrustTokenBrowsertest, FetchEndToEnd) { IN_PROC_BROWSER_TEST_F(TrustTokenBrowsertest, FetchEndToEnd) {
ProvideRequestHandlerKeyCommitmentsToNetworkService({"a.test"}); ProvideRequestHandlerKeyCommitmentsToNetworkService({"a.test"});
......
// Copyright 2020 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 CONTENT_TEST_TRUST_TOKEN_BROWSERTEST_H_
#define CONTENT_TEST_TRUST_TOKEN_BROWSERTEST_H_
#include "base/test/scoped_feature_list.h"
#include "content/public/test/content_browser_test.h"
#include "services/network/trust_tokens/test/trust_token_request_handler.h"
namespace content {
using network::test::TrustTokenRequestHandler;
// TrustTokenBrowsertest is a fixture containing boilerplate for initializing an
// HTTPS test server and passing requests through to an embedded instance of
// network::test::TrustTokenRequestHandler, which contains the guts of the
// "server-side" token issuance and redemption logic as well as some consistency
// checks for subsequent signed requests.
//
// The virtual inheritance is necessary as DevtoolsTrustTokenBrowsertest builds
// an inheritance diamond with ContentBrowserTest at the root. Any class in the
// diamond inheriting from ContentBrowserTest directly, needs to do so
// virtually. Otherwise DevtoolsTrustTokenBrowsertest would contain multiple
// copies of ContentBrowserTest's members.
class TrustTokenBrowsertest : virtual public ContentBrowserTest {
public:
TrustTokenBrowsertest();
// Registers the following handlers:
// - default //content/test/data files;
// - a special "/issue" endpoint executing Trust Tokens issuance;
// - a special "/redeem" endpoint executing redemption; and
// - a special "/sign" endpoint that verifies that the received signed request
// data is correctly structured and that the provided Sec-Signature header's
// verification key was previously bound to a successful token redemption.
void SetUpOnMainThread() override;
protected:
// Provides the network service key commitments from the internal
// TrustTokenRequestHandler. All hosts in |hosts| will be provided identical
// commitments.
void ProvideRequestHandlerKeyCommitmentsToNetworkService(
std::vector<base::StringPiece> hosts = {});
// Given a host (e.g. "a.test"), returns the corresponding storage origin
// for Trust Tokens state. (This adds the correct scheme---probably https---as
// well as |server_|'s port, which can vary from test to test. There's no
// ambiguity in the result because the scheme and port are both fixed across
// all domains.)
std::string IssuanceOriginFromHost(const std::string& host) const;
base::test::ScopedFeatureList features_;
// TODO(davidvc): Extend this to support more than one key set.
TrustTokenRequestHandler request_handler_;
net::EmbeddedTestServer server_{net::EmbeddedTestServer::TYPE_HTTPS};
};
} // namespace content
#endif // CONTENT_TEST_TRUST_TOKEN_BROWSERTEST_H_
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment