#include "content/services/auction_worklet/trusted_signals_kvv2_helper.h"
#if BUILDFLAG(IS_WIN)
#include <winsock2.h>
#else
#include <netinet/in.h>
#endif
#include <algorithm>
#include <cstddef>
#include <cstdint>
#include <functional>
#include <optional>
#include <string>
#include <vector>
#include "base/containers/span.h"
#include "base/containers/span_writer.h"
#include "base/strings/string_number_conversions.h"
#include "base/test/scoped_feature_list.h"
#include "base/test/task_environment.h"
#include "base/time/time.h"
#include "components/cbor/values.h"
#include "components/cbor/writer.h"
#include "content/services/auction_worklet/public/mojom/auction_worklet_service.mojom.h"
#include "content/services/auction_worklet/trusted_signals.h"
#include "content/services/auction_worklet/trusted_signals_request_manager.h"
#include "net/third_party/quiche/src/quiche/oblivious_http/oblivious_http_gateway.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/blink/public/common/features.h"
#include "third_party/zlib/google/compression_utils.h"
#include "url/gurl.h"
#include "url/origin.h"
#include "v8-context.h"
namespace auction_worklet {
namespace {
const char kHostName[] = …;
const int kExperimentGroupId = …;
const char kTrustedBiddingSignalsSlotSizeParam[] = …;
const size_t kFramingHeaderSize = …;
const size_t kOhttpHeaderSize = …;
const char kTrustedSignalsUrl[] = …;
const char kOriginFooUrl[] = …;
const char kOriginFoosubUrl[] = …;
const char kOriginBarUrl[] = …;
const char kOriginBarsubUrl[] = …;
const char kOwnerOriginA[] = …;
const char kOwnerOriginB[] = …;
const char kJoiningOriginA[] = …;
const char kJoiningOriginB[] = …;
const uint8_t kTestPrivateKey[] = …;
const uint8_t kTestPublicKey[] = …;
std::vector<uint8_t> DecryptRequestBody(const std::string& request_body,
int public_key_id) { … }
std::vector<std::uint8_t> GzipCompressHelper(
const std::vector<std::uint8_t>& in) { … }
void ExpectCompressionGroupMapEquals(
const TrustedSignalsKVv2ResponseParser::CompressionGroupResultMap& map1,
const TrustedSignalsKVv2ResponseParser::CompressionGroupResultMap& map2) { … }
void CheckBiddingResult(
AuctionV8Helper* v8_helper,
TrustedSignalsKVv2ResponseParser::TrustedSignalsResultMap& result_map,
TrustedSignalsKVv2RequestHelperBuilder::IsolationIndex& index,
const std::vector<std::string>& interest_group_names,
const std::vector<std::string>& keys,
const std::map<std::string, TrustedSignals::Result::PriorityVector>&
priority_vector_map,
const std::string& bidding_signals,
std::optional<uint32_t> data_version) { … }
void CheckScoringResult(
AuctionV8Helper* v8_helper,
TrustedSignalsKVv2ResponseParser::TrustedSignalsResultMap& result_map,
TrustedSignalsKVv2RequestHelperBuilder::IsolationIndex& index,
const GURL& render_url,
const std::vector<std::string>& ad_component_render_urls,
const std::string& expected_signals,
std::optional<uint32_t> data_version) { … }
std::string BuildResponseBody(const std::string& hex_string,
uint8_t compress_scheme = 0x00) { … }
std::pair<std::string, quiche::ObliviousHttpRequest::Context>
EncryptResponseBodyHelper(const std::string& response_body) { … }
std::string GetErrorMessageFromParseResponseToSignalsFetchResult(
std::string& hex,
uint8_t compress_scheme = 0x00) { … }
std::string GetErrorMessageFromParseBiddingSignalsFetchResultToResultMap(
scoped_refptr<AuctionV8Helper> v8_helper,
const std::set<std::string>& interest_group_names,
const std::set<std::string>& keys,
const TrustedSignalsKVv2ResponseParser::CompressionGroupResultMap&
compression_group_result_map) { … }
std::string GetErrorMessageFromParseScoringSignalsFetchResultToResultMap(
scoped_refptr<AuctionV8Helper> v8_helper,
const std::set<std::string>& render_urls,
const std::set<std::string>& ad_component_render_urls,
const TrustedSignalsKVv2ResponseParser::CompressionGroupResultMap&
compression_group_result_map) { … }
}
class TrustedSignalsKVv2ResponseParserTest : public testing::Test { … };
TEST(TrustedSignalsKVv2RequestHelperTest,
TrustedBiddingSignalsRequestEncoding) { … }
TEST(TrustedSignalsKVv2RequestHelperTest, TrustedBiddingSignalsIsolationIndex) { … }
TEST(TrustedSignalsKVv2RequestHelperTest,
TrustedScoringSignalsRequestEncoding) { … }
TEST(TrustedSignalsKVv2RequestHelperTest, TrustedScoringSignalsIsolationIndex) { … }
TEST_F(TrustedSignalsKVv2ResponseParserTest,
TrustedBiddingSignalsResponseParsing) { … }
TEST_F(TrustedSignalsKVv2ResponseParserTest,
TrustedScoringSignalsResponseParsing) { … }
TEST_F(TrustedSignalsKVv2ResponseParserTest, ResponseDecryptionFailure) { … }
TEST_F(TrustedSignalsKVv2ResponseParserTest, SignalsFetchResultParseFailure) { … }
TEST_F(TrustedSignalsKVv2ResponseParserTest,
SignalsFetchResultMapParseFailure) { … }
}