chromium/content/browser/interest_group/additional_bids_util_unittest.cc

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

#ifdef UNSAFE_BUFFERS_BUILD
// TODO(crbug.com/342213636): Remove this and spanify to fix the errors.
#pragma allow_unsafe_buffers
#endif

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

#include <stdint.h>

#include <array>
#include <limits>
#include <optional>
#include <string>

#include "base/base64.h"
#include "base/containers/flat_set.h"
#include "base/strings/strcat.h"
#include "base/strings/stringprintf.h"
#include "base/test/task_environment.h"
#include "base/types/expected.h"
#include "base/types/optional_ref.h"
#include "base/uuid.h"
#include "base/values.h"
#include "components/ukm/test_ukm_recorder.h"
#include "content/browser/interest_group/auction_metrics_recorder.h"
#include "content/services/auction_worklet/public/mojom/bidder_worklet.mojom-forward.h"
#include "services/metrics/public/cpp/ukm_builders.h"
#include "services/metrics/public/cpp/ukm_source_id.h"
#include "testing/gmock/include/gmock/gmock-matchers.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/blink/public/common/interest_group/ad_auction_constants.h"
#include "third_party/blink/public/common/interest_group/ad_display_size.h"
#include "third_party/boringssl/src/include/openssl/curve25519.h"
#include "url/gurl.h"
#include "url/origin.h"

UnorderedElementsAre;

namespace content {
namespace {

// In case one wants to generate some keys for test use, the following may be
// useful:
// template <int N>
// std::string SerializeKey(uint8_t key[N]) {
//   std::string out;
//   for (int row = 0; row < (N / 8); ++row) {
//     for (int col = 0; col < 8; ++col) {
//       base::StrAppend(
//           &out, {base::StringPrintf("0x%02x",
//                                     static_cast<unsigned>(
//                                         key[row * 8 + col])),
//                  ", "});
//     }
//     base::StrAppend(&out, {"\n"});
//   }
//   return out;
// }
//
// TEST_F(AdditionalBidsUtilTest, GenerateKeyPair) {
//   uint8_t public_key[32];
//   uint8_t private_key[64];
//   ED25519_keypair(public_key, private_key);
//   std::cout << "public_key:\n";
//   std::cout << SerializeKey<32>(public_key) << "\n";
//   std::cout << base::Base64Encode(
//       base::make_span(public_key, sizeof(public_key)));
//   std::cout << "\n\n";
//
//   std::cout << "private_key:\n";
//   std::cout << SerializeKey<64>(private_key) << "\n";
//   std::cout << base::Base64Encode(
//       base::make_span(private_key, sizeof(private_key)));
//   std::cout << "\n\n";
// }

// Some test data for key/signature fields. These are just random sequences
// of bytes of the right length, not proper cryptographic ones.
const uint8_t kKey1[] =;
const char kKey1Base64[] =;

const uint8_t kKey2[] =;
const char kKey2Base64[] =;

const uint8_t kSig1[] =;
const char kSig1Base64[] =;

const uint8_t kSig2[] =;
const char kSig2Base64[] =;

// Version that requires forgiving decoder to accept.
const char kSig2Base64Sloppy[] =;

const char kPretendBid[] =;

class AdditionalBidsUtilTest : public testing::Test {};

TEST_F(AdditionalBidsUtilTest, FailNotDict) {}

TEST_F(AdditionalBidsUtilTest, FailNoNonce) {}

TEST_F(AdditionalBidsUtilTest, FailInvalidNonce) {}

TEST_F(AdditionalBidsUtilTest, FailMissingSeller) {}

TEST_F(AdditionalBidsUtilTest, FailInvalidSeller) {}

// Specifying topLevelSeller in a bid in a non-component auction is a problem.
TEST_F(AdditionalBidsUtilTest, FailInvalidTopLevelSeller) {}

// Not specifying topLevelSeller in component auction bid is also a problem.
TEST_F(AdditionalBidsUtilTest, FailInvalidTopLevelSeller2) {}

// An incorrect topLevelSeller in a bid in a component auction is also a
// problem.
TEST_F(AdditionalBidsUtilTest, FailInvalidTopLevelSeller3) {}

// Missing IG dictionary.
TEST_F(AdditionalBidsUtilTest, FailNoIGDictionary) {}

TEST_F(AdditionalBidsUtilTest, FailMissingInterestGroupName) {}

TEST_F(AdditionalBidsUtilTest, FailMissingInterestGroupBiddingScript) {}

TEST_F(AdditionalBidsUtilTest, FailMissingInterestGroupOwner) {}

TEST_F(AdditionalBidsUtilTest, FailNonHttpsInterestGroupOwner) {}

TEST_F(AdditionalBidsUtilTest, FailDomainMismatchBetweenOwnerAndBiddingScript) {}

// The additional bid owner is missing from interestGroupBuyers.
TEST_F(AdditionalBidsUtilTest, AdditionalBidOwnerNotInInterestGroupBuyers) {}

TEST_F(AdditionalBidsUtilTest, FailMissingBid) {}

TEST_F(AdditionalBidsUtilTest, FailMissingBidCreative) {}

TEST_F(AdditionalBidsUtilTest, FailMissingBidValue) {}

TEST_F(AdditionalBidsUtilTest, FailInvalidBidValue) {}

TEST_F(AdditionalBidsUtilTest, MinimalValid) {}

TEST_F(AdditionalBidsUtilTest, InvalidBidCurrencyType) {}

TEST_F(AdditionalBidsUtilTest, InvalidBidCurrencySyntax) {}

TEST_F(AdditionalBidsUtilTest, ValidBidCurrency) {}

TEST_F(AdditionalBidsUtilTest, InvalidAdCost) {}

TEST_F(AdditionalBidsUtilTest, ValidAdCost) {}

// We have a tradition of ignoring modeling signals if they're out of range,
// so this follows.
TEST_F(AdditionalBidsUtilTest, InvalidModelingSignals) {}

TEST_F(AdditionalBidsUtilTest, InvalidModelingSignals2) {}

// Bad-type modeling signals still an error, however.
TEST_F(AdditionalBidsUtilTest, BadTypeModelingSignals) {}

TEST_F(AdditionalBidsUtilTest, ValidModelingSignals) {}

TEST_F(AdditionalBidsUtilTest, ValidModelingSignals2) {}

TEST_F(AdditionalBidsUtilTest, ValidModelingSignals3) {}

TEST_F(AdditionalBidsUtilTest, InvalidAdComponents) {}

TEST_F(AdditionalBidsUtilTest, InvalidAdComponentsEntry) {}

TEST_F(AdditionalBidsUtilTest, TooManyAdComponents) {}

TEST_F(AdditionalBidsUtilTest, ValidAdComponents) {}

TEST_F(AdditionalBidsUtilTest, ValidAdComponentsEmpty) {}

TEST_F(AdditionalBidsUtilTest, ValidAdMetadata) {}

TEST_F(AdditionalBidsUtilTest, ValidSingleNegativeIG) {}

TEST_F(AdditionalBidsUtilTest, InvalidSingleNegativeIG) {}

TEST_F(AdditionalBidsUtilTest, InvalidBothKindsOfNegativeIG) {}

TEST_F(AdditionalBidsUtilTest, ValidMultipleNegativeIG) {}

// Non-string joining origin.
TEST_F(AdditionalBidsUtilTest, InvalidMultipleNegativeIG) {}

// Non-HTTPS joining origin.
TEST_F(AdditionalBidsUtilTest, InvalidMultipleNegativeIG2) {}

// Missing joining origin.
TEST_F(AdditionalBidsUtilTest, InvalidMultipleNegativeIG3) {}

// Missing interestGroupNames.
TEST_F(AdditionalBidsUtilTest, InvalidMultipleNegativeIG4) {}

// interestGroupNames not a list.
TEST_F(AdditionalBidsUtilTest, InvalidMultipleNegativeIG5) {}

// Non-string entry in interestGroupNames
TEST_F(AdditionalBidsUtilTest, InvalidMultipleNegativeIG6) {}

// Wrong type for negativeInterestGroups
TEST_F(AdditionalBidsUtilTest, InvalidMultipleNegativeIG7) {}

TEST_F(AdditionalBidsUtilTest, DecodeBasicSignedBid) {}

TEST_F(AdditionalBidsUtilTest, SignedNotDict) {}

TEST_F(AdditionalBidsUtilTest, DecodeSignedMissingBid) {}

TEST_F(AdditionalBidsUtilTest, DecodeSignedMissingSignatures) {}

TEST_F(AdditionalBidsUtilTest, DecodeSignedInvalidSignatures) {}

TEST_F(AdditionalBidsUtilTest, DecodeSignedMissingSignatureKey) {}

TEST_F(AdditionalBidsUtilTest, DecodeSignedInvalidSignatureKey) {}

TEST_F(AdditionalBidsUtilTest, DecodeSignedInvalidSignatureKeyLength) {}

TEST_F(AdditionalBidsUtilTest, DecodeSignedMissingSignatureSig) {}

TEST_F(AdditionalBidsUtilTest, DecodeSignedInvalidSignatureSig) {}

TEST_F(AdditionalBidsUtilTest, DecodeSignedInvalidSignatureSigLength) {}

TEST_F(AdditionalBidsUtilTest, VerifySignature) {}

class AdditionalBidsUtilNegativeTargetingTest : public AdditionalBidsUtilTest {};

TEST_F(AdditionalBidsUtilNegativeTargetingTest, GetNumNegativeInterestGroups) {}

TEST_F(AdditionalBidsUtilNegativeTargetingTest, SuccessfullyNegativeTargets) {}

TEST_F(AdditionalBidsUtilNegativeTargetingTest, WrongBuyer) {}

TEST_F(AdditionalBidsUtilNegativeTargetingTest,
       SuccessfulDespiteUnusedBadSignature) {}

TEST_F(AdditionalBidsUtilNegativeTargetingTest, NoMatchingKey) {}

TEST_F(AdditionalBidsUtilNegativeTargetingTest, SuccessfulDespiteMissingKey) {}

TEST_F(AdditionalBidsUtilNegativeTargetingTest,
       SuccessfulSoDoesNotEvenSeeMissingKey) {}

TEST_F(AdditionalBidsUtilNegativeTargetingTest, JoiningOriginMismatch) {}

TEST_F(AdditionalBidsUtilNegativeTargetingTest,
       SuccessfulWithMultipleNegativeInterestGroups) {}

TEST_F(AdditionalBidsUtilNegativeTargetingTest,
       SuccessfulDespiteTwoJoiningOriginMismatches) {}

}  // namespace
}  // namespace content