chromium/components/device_signals/test/signals_contract.cc

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

#include "components/device_signals/test/signals_contract.h"

#include "base/functional/bind.h"
#include "base/functional/callback.h"
#include "base/test/bind.h"
#include "build/build_config.h"
#include "components/device_signals/core/browser/signals_types.h"
#include "components/device_signals/core/common/signals_constants.h"

namespace device_signals::test {

namespace {

// Only return false if the value is set to something other than a string.
bool VerifyOptionalString(const std::string& signal_name,
                          const base::Value::Dict& signals) {}

bool VerifyIsString(const std::string& signal_name,
                    const base::Value::Dict& signals) {}

bool VerifyIsBoolean(const std::string& signal_name,
                     const base::Value::Dict& signals) {}

// `min_value` and `max_value` are inclusive.
bool VerifyIsIntegerWithRange(const std::string& signal_name,
                              int32_t min_value,
                              int32_t max_value,
                              const base::Value::Dict& signals) {}

bool VerifyIsSettingInteger(const std::string& signal_name,
                            const base::Value::Dict& signals) {}

// `enforce_value` can be set to true when we definitely expect a value to be
// set in the array.
bool VerifyIsStringArray(const std::string& signal_name,
                         bool enforce_value,
                         const base::Value::Dict& signals) {}

bool VerifyUnset(const std::string& signal_name,
                 const base::Value::Dict& signals) {}

#if BUILDFLAG(IS_CHROMEOS_ASH)
void ChangeContractForUnmanagedDevices(
    base::flat_map<std::string,
                   base::RepeatingCallback<bool(const base::Value::Dict&)>>&
        contract) {
  contract[names::kDeviceAffiliationIds] =
      base::BindRepeating(VerifyIsStringArray, names::kDeviceAffiliationIds,
                          /*enforce_value=*/false);

  // Signals containing stable device identifiers should be unset.
  contract[names::kDisplayName] =
      base::BindRepeating(VerifyUnset, names::kDisplayName);
  contract[names::kSystemDnsServers] = base::BindRepeating(
      base::BindRepeating(VerifyUnset, names::kSystemDnsServers));
  contract[names::kSerialNumber] =
      base::BindRepeating(VerifyUnset, names::kSerialNumber);
  contract[names::kDeviceHostName] =
      base::BindRepeating(VerifyUnset, names::kDeviceHostName);
  contract[names::kMacAddresses] =
      base::BindRepeating(VerifyUnset, names::kMacAddresses);
  contract[names::kImei] = base::BindRepeating(VerifyUnset, names::kImei);
  contract[names::kMeid] = base::BindRepeating(VerifyUnset, names::kMeid);
}
#endif  // BUILDFLAG(IS_CHROMEOS_ASH)

}  // namespace

base::flat_map<std::string,
               base::RepeatingCallback<bool(const base::Value::Dict&)>>
GetSignalsContract() {}

#if BUILDFLAG(IS_CHROMEOS_ASH)
base::flat_map<std::string,
               base::RepeatingCallback<bool(const base::Value::Dict&)>>
GetSignalsContractForUnmanagedDevices() {
  base::flat_map<std::string,
                 base::RepeatingCallback<bool(const base::Value::Dict&)>>
      contract = GetSignalsContract();

  ChangeContractForUnmanagedDevices(contract);
  return contract;
}
#endif  // BUILDFLAG(IS_CHROMEOS_ASH)

}  // namespace device_signals::test