chromium/content/browser/interest_group/trusted_signals_fetcher_unittest.cc

// Copyright 2024 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "content/browser/interest_group/trusted_signals_fetcher.h"

#include <stdint.h>

#include <limits>
#include <list>
#include <map>
#include <memory>
#include <set>
#include <string>
#include <vector>

#include "base/containers/span.h"
#include "base/containers/span_writer.h"
#include "base/format_macros.h"
#include "base/functional/bind.h"
#include "base/functional/callback.h"
#include "base/memory/raw_ptr.h"
#include "base/memory/scoped_refptr.h"
#include "base/strings/stringprintf.h"
#include "base/synchronization/lock.h"
#include "base/test/bind.h"
#include "base/test/task_environment.h"
#include "base/thread_annotations.h"
#include "base/time/time.h"
#include "base/types/expected.h"
#include "base/values.h"
#include "content/browser/interest_group/bidding_and_auction_server_key_fetcher.h"
#include "content/services/auction_worklet/public/mojom/trusted_signals_cache.mojom.h"
#include "mojo/public/cpp/bindings/remote.h"
#include "net/cookies/canonical_cookie.h"
#include "net/http/http_request_headers.h"
#include "net/http/http_status_code.h"
#include "net/test/embedded_test_server/embedded_test_server.h"
#include "net/test/embedded_test_server/http_request.h"
#include "net/test/embedded_test_server/http_response.h"
#include "net/third_party/quiche/src/quiche/oblivious_http/common/oblivious_http_header_key_config.h"
#include "net/third_party/quiche/src/quiche/oblivious_http/oblivious_http_gateway.h"
#include "services/data_decoder/public/cpp/test_support/in_process_data_decoder.h"
#include "services/network/public/mojom/cookie_manager.mojom.h"
#include "services/network/public/mojom/network_context.mojom.h"
#include "services/network/test/test_shared_url_loader_factory.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/boringssl/src/include/openssl/hpke.h"
#include "url/gurl.h"
#include "url/origin.h"

namespace content {
namespace {

// These keys were randomly generated as follows:
// EVP_HPKE_KEY keys;
// EVP_HPKE_KEY_generate(&keys, EVP_hpke_x25519_hkdf_sha256());
// and then EVP_HPKE_KEY_public_key and EVP_HPKE_KEY_private_key were used to
// extract the keys.
const uint8_t kTestPrivateKey[] =;

const uint8_t kTestPublicKey[] =;

const uint8_t kKeyId =;

// Helper to create a CompressionGroupResult given all field values. Copies the
// entire `compression_group_data`.
TrustedSignalsFetcher::CompressionGroupResult CreateCompressionGroupResult(
    auction_worklet::mojom::TrustedSignalsCompressionScheme compression_scheme,
    std::string_view compression_group_data,
    base::TimeDelta ttl) {}

class TrustedSignalsFetcherTest : public testing::Test {};

TEST_F(TrustedSignalsFetcherTest, BiddingSignals404) {}

TEST_F(TrustedSignalsFetcherTest, BiddingSignalsRedirect) {}

TEST_F(TrustedSignalsFetcherTest, BiddingSignalsMimeType) {}

TEST_F(TrustedSignalsFetcherTest, BiddingSignalsCanSetNoCookies) {}

TEST_F(TrustedSignalsFetcherTest, BiddingSignalsHasNoCookies) {}

TEST_F(TrustedSignalsFetcherTest, BiddingSignalsNoKeys) {}

TEST_F(TrustedSignalsFetcherTest, BiddingSignalsOneKey) {}

TEST_F(TrustedSignalsFetcherTest, BiddingSignalsMultipleKeys) {}

TEST_F(TrustedSignalsFetcherTest, BiddingSignalsMultipleInterestGroups) {}

TEST_F(TrustedSignalsFetcherTest, BiddingSignalsOneAdditionalParam) {}

TEST_F(TrustedSignalsFetcherTest, BiddingSignalsMultipleAdditionalParams) {}

// Test a single compression group with a single partition, where neither has
// the index 0.
TEST_F(TrustedSignalsFetcherTest, BiddingSignalsNoZeroIndices) {}

// Test that the expected amount of padding is added to requests.
TEST_F(TrustedSignalsFetcherTest, BiddingSignalsRequestPadding) {}

TEST_F(TrustedSignalsFetcherTest, BiddingSignalsResponseBodyShorterThanHeader) {}

TEST_F(TrustedSignalsFetcherTest, BiddingSignalsResponseBodyUnencrypted) {}

// Receiving CBOR without a header in the response body should result in
// failure.
TEST_F(TrustedSignalsFetcherTest, NoResponseBodyHeader) {}

TEST_F(TrustedSignalsFetcherTest, BiddingSignalsCompressionSchemeNone) {}

TEST_F(TrustedSignalsFetcherTest, BiddingSignalsCompressionSchemeUnsupported) {}

TEST_F(TrustedSignalsFetcherTest,
       BiddingSignalsCompressionSchemeHighOrderBitsIgnored) {}

// If the advertised length is longer than the response, the request should
// fail, even if it's otherwise a valid CBOR response. This test also checks the
// case where the maximum possible length is received, to make sure there are no
// overflow/underflow issues.
TEST_F(TrustedSignalsFetcherTest, BiddingSignalsAdvertisedLengthTooLong) {}

// If the advertised shorter is longer than the response, the remaining bytes
// should be ignored, even if they make an otherwise valid CBOR response.
TEST_F(TrustedSignalsFetcherTest, BiddingSignalsAdvertisedLengthTooShort) {}

TEST_F(TrustedSignalsFetcherTest, BiddingSignalsResponsePadding) {}

// Test the case where there are valid framing headers, but the response body is
// not CBOR.
TEST_F(TrustedSignalsFetcherTest, NotCbor) {}

// Test cases where there's a valid framing header, and the response is CBOR,
// but it's not a map.
TEST_F(TrustedSignalsFetcherTest, NotCborMap) {}

TEST_F(TrustedSignalsFetcherTest, NoCompressionGroupMap) {}

TEST_F(TrustedSignalsFetcherTest, CompressionGroupsNotArray) {}

TEST_F(TrustedSignalsFetcherTest, NoCompressionGroups) {}

TEST_F(TrustedSignalsFetcherTest, CompressionGroupNotMap) {}

TEST_F(TrustedSignalsFetcherTest,
       CompressionGroupWithBadOrNoCompressionGroupId) {}

TEST_F(TrustedSignalsFetcherTest, CompressionGroupWithBadOrNoContent) {}

TEST_F(TrustedSignalsFetcherTest, CompressionGroupWithBadTtl) {}

// `ttlMs` is an optional field. When not present, we currently default to a
// value of 0.
TEST_F(TrustedSignalsFetcherTest, CompressionGroupWithNoTtl) {}

TEST_F(TrustedSignalsFetcherTest, CompressionGroupWithZeroTtl) {}

// Negative TTLs are allows, and are treated as if they were zero.
TEST_F(TrustedSignalsFetcherTest, CompressionGroupWithNegativeTtl) {}

TEST_F(TrustedSignalsFetcherTest, BiddingSignalsMultiplePartitions) {}

// Test that a fetch fails when there are two compression groups with the same
// ID in the response.
TEST_F(TrustedSignalsFetcherTest, BiddingSignalsDuplicateCompressionGroups) {}

TEST_F(TrustedSignalsFetcherTest, BiddingSignalsMultipleCompressionGroups) {}

// Test that the entire fetch fails when one of the requested partitions has an
// error.
TEST_F(TrustedSignalsFetcherTest,
       BiddingSignalsMultipleCompressionGroupsFailsWhenOneBad) {}

}  // namespace
}  // namespace content