chromium/chrome/browser/enterprise/connectors/test/deep_scanning_test_utils.cc

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

#include "chrome/browser/enterprise/connectors/test/deep_scanning_test_utils.h"

#include "base/containers/contains.h"
#include "base/containers/flat_map.h"
#include "base/json/json_reader.h"
#include "base/numerics/safe_conversions.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/utf_string_conversions.h"
#include "base/values.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/enterprise/connectors/common.h"
#include "chrome/browser/enterprise/connectors/reporting/realtime_reporting_client.h"
#include "chrome/browser/enterprise/connectors/reporting/realtime_reporting_client_factory.h"
#include "chrome/browser/extensions/api/safe_browsing_private/safe_browsing_private_event_router.h"
#include "chrome/browser/extensions/api/safe_browsing_private/safe_browsing_private_event_router_factory.h"
#include "chrome/browser/policy/dm_token_utils.h"
#include "chrome/browser/profiles/profile.h"
#include "components/enterprise/connectors/core/connectors_prefs.h"
#include "components/enterprise/connectors/core/reporting_constants.h"
#include "components/policy/core/common/cloud/cloud_policy_client_registration_helper.h"
#include "components/policy/core/common/cloud/mock_cloud_policy_client.h"
#include "components/policy/core/common/cloud/mock_cloud_policy_store.h"
#include "components/policy/core/common/cloud/realtime_reporting_job_configuration.h"
#include "components/policy/core/common/cloud/user_cloud_policy_manager.h"
#include "components/policy/core/common/policy_types.h"
#include "components/prefs/scoped_user_pref_update.h"
#include "components/safe_browsing/core/common/safe_browsing_prefs.h"
#include "components/signin/public/identity_manager/identity_test_environment.h"
#include "content/public/browser/browser_context.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"

SafeBrowsingPrivateEventRouter;
_;

namespace enterprise_connectors::test {

EventReportValidator::EventReportValidator(
    policy::MockCloudPolicyClient* client)
    :{}

EventReportValidator::~EventReportValidator() {}

void EventReportValidator::ExpectUnscannedFileEvent(
    const std::string& expected_url,
    const std::string& expected_tab_url,
    const std::string& expected_source,
    const std::string& expected_destination,
    const std::string& expected_filename,
    const std::string& expected_sha256,
    const std::string& expected_trigger,
    const std::string& expected_reason,
    const std::set<std::string>* expected_mimetypes,
    std::optional<int64_t> expected_content_size,
    const std::string& expected_result,
    const std::string& expected_profile_username,
    const std::string& expected_profile_identifier,
    const std::optional<std::string>& expected_content_transfer_method) {}

void EventReportValidator::ExpectUnscannedFileEvents(
    const std::string& expected_url,
    const std::string& expected_tab_url,
    const std::string& expected_source,
    const std::string& expected_destination,
    const std::vector<std::string>& expected_filenames,
    const std::vector<std::string>& expected_sha256s,
    const std::string& expected_trigger,
    const std::string& expected_reason,
    const std::set<std::string>* expected_mimetypes,
    int64_t expected_content_size,
    const std::string& expected_result,
    const std::string& expected_profile_username,
    const std::string& expected_profile_identifier,
    const std::optional<std::string>& expected_content_transfer_method) {}

void EventReportValidator::ExpectDangerousDeepScanningResult(
    const std::string& expected_url,
    const std::string& expected_tab_url,
    const std::string& expected_source,
    const std::string& expected_destination,
    const std::string& expected_filename,
    const std::string& expected_sha256,
    const std::string& expected_threat_type,
    const std::string& expected_trigger,
    const std::set<std::string>* expected_mimetypes,
    int64_t expected_content_size,
    const std::string& expected_result,
    const std::string& expected_profile_username,
    const std::string& expected_profile_identifier,
    const std::optional<std::string>& expected_scan_id) {}

void EventReportValidator::ExpectSensitiveDataEvent(
    const std::string& expected_url,
    const std::string& expected_tab_url,
    const std::string& expected_source,
    const std::string& expected_destination,
    const std::string& expected_filename,
    const std::string& expected_sha256,
    const std::string& expected_trigger,
    const ContentAnalysisResponse::Result& expected_dlp_verdict,
    const std::set<std::string>* expected_mimetypes,
    std::optional<int64_t> expected_content_size,
    const std::string& expected_result,
    const std::string& expected_profile_username,
    const std::string& expected_profile_identifier,
    const std::string& expected_scan_id,
    const std::optional<std::string>& expected_content_transfer_method,
    const std::optional<std::u16string>& expected_user_justification) {}

void EventReportValidator::ExpectDataControlsSensitiveDataEvent(
    const std::string& expected_url,
    const std::string& expected_tab_url,
    const std::string& expected_source,
    const std::string& expected_destination,
    const std::set<std::string>* expected_mimetypes,
    const std::string& expected_trigger,
    const data_controls::Verdict::TriggeredRules& triggered_rules,
    const std::string& expected_result,
    const std::string& expected_profile_username,
    const std::string& expected_profile_identifier,
    int64_t expected_content_size) {}

void EventReportValidator::ExpectSensitiveDataEvents(
    const std::string& expected_url,
    const std::string& expected_tab_url,
    const std::string& expected_source,
    const std::string& expected_destination,
    const std::vector<std::string>& expected_filenames,
    const std::vector<std::string>& expected_sha256s,
    const std::string& expected_trigger,
    const std::vector<ContentAnalysisResponse::Result>& expected_dlp_verdicts,
    const std::set<std::string>* expected_mimetypes,
    int64_t expected_content_size,
    const std::vector<std::string>& expected_results,
    const std::string& expected_profile_username,
    const std::string& expected_profile_identifier,
    const std::vector<std::string>& expected_scan_ids,
    const std::optional<std::string>& expected_content_transfer_method,
    const std::optional<std::u16string>& expected_user_justification) {}

void EventReportValidator::
    ExpectDangerousDeepScanningResultAndSensitiveDataEvent(
        const std::string& expected_url,
        const std::string& expected_tab_url,
        const std::string& expected_source,
        const std::string& expected_destination,
        const std::string& expected_filename,
        const std::string& expected_sha256,
        const std::string& expected_threat_type,
        const std::string& expected_trigger,
        const ContentAnalysisResponse::Result& expected_dlp_verdict,
        const std::set<std::string>* expected_mimetypes,
        int64_t expected_content_size,
        const std::string& expected_result,
        const std::string& expected_profile_username,
        const std::string& expected_profile_identifier,
        const std::string& expected_scan_id,
        const std::optional<std::string>& expected_content_transfer_method) {}

void EventReportValidator::
    ExpectSensitiveDataEventAndDangerousDeepScanningResult(
        const std::string& expected_url,
        const std::string& expected_tab_url,
        const std::string& expected_source,
        const std::string& expected_destination,
        const std::string& expected_filename,
        const std::string& expected_sha256,
        const std::string& expected_threat_type,
        const std::string& expected_trigger,
        const ContentAnalysisResponse::Result& expected_dlp_verdict,
        const std::set<std::string>* expected_mimetypes,
        int64_t expected_content_size,
        const std::string& expected_result,
        const std::string& expected_profile_username,
        const std::string& expected_profile_identifier,
        const std::string& expected_scan_id) {}

void EventReportValidator::ExpectDangerousDownloadEvent(
    const std::string& expected_url,
    const std::string& expected_tab_url,
    const std::string& expected_filename,
    const std::string& expected_sha256,
    const std::string& expected_threat_type,
    const std::string& expected_trigger,
    const std::set<std::string>* expected_mimetypes,
    int64_t expected_content_size,
    const std::string& expected_result,
    const std::string& expected_profile_username,
    const std::string& expected_profile_identifier) {}

void EventReportValidator::ExpectLoginEvent(
    const std::string& expected_url,
    const bool expected_is_federated,
    const std::string& expected_federated_origin,
    const std::string& expected_profile_username,
    const std::string& expected_profile_identifier,
    const std::u16string& expected_login_username) {}

void EventReportValidator::ExpectPasswordBreachEvent(
    const std::string& expected_trigger,
    const std::vector<std::pair<std::string, std::u16string>>&
        expected_identities,
    const std::string& expected_profile_username,
    const std::string& expected_profile_identifier) {}

void EventReportValidator::ExpectURLFilteringInterstitialEvent(
    const std::string& expected_url,
    const std::string& expected_event_result,
    const std::string& expected_profile_username,
    const std::string& expected_profile_identifier,
    safe_browsing::RTLookupResponse expected_rt_lookup_response) {}

void EventReportValidator::ValidateReport(const base::Value::Dict* report) {}

void EventReportValidator::ValidateFederatedOrigin(
    const base::Value::Dict* value) {}

void EventReportValidator::ValidateIdentities(const base::Value::Dict* value) {}

void EventReportValidator::ValidateMimeType(const base::Value::Dict* value) {}

void EventReportValidator::ValidateDlpVerdict(
    const base::Value::Dict* value,
    const ContentAnalysisResponse::Result& result) {}

void EventReportValidator::ValidateDlpRule(
    const base::Value::Dict* value,
    const ContentAnalysisResponse::Result::TriggeredRule& expected_rule) {}

void EventReportValidator::ValidateRTLookupResponse(
    const base::Value::Dict* value) {}

void EventReportValidator::ValidateThreatInfo(
    const base::Value::Dict* value,
    const safe_browsing::RTLookupResponse::ThreatInfo& expected_threat_info) {}

void EventReportValidator::ValidateFilenameMappedAttributes(
    const base::Value::Dict* value) {}

void EventReportValidator::ValidateField(
    const base::Value::Dict* value,
    const std::string& field_key,
    const std::optional<std::string>& expected_value) {}

void EventReportValidator::ValidateField(
    const base::Value::Dict* value,
    const std::string& field_key,
    const std::optional<std::u16string>& expected_value) {}

void EventReportValidator::ValidateField(
    const base::Value::Dict* value,
    const std::string& field_key,
    const std::optional<int>& expected_value) {}

void EventReportValidator::ValidateField(
    const base::Value::Dict* value,
    const std::string& field_key,
    const std::optional<bool>& expected_value) {}

void EventReportValidator::ValidateDataControlsAttributes(
    const base::Value::Dict* event) {}

void EventReportValidator::ExpectNoReport() {}

void EventReportValidator::SetDoneClosure(base::RepeatingClosure closure) {}

EventReportValidatorHelper::EventReportValidatorHelper(Profile* profile,
                                                       bool browser_test)
    :{}

EventReportValidatorHelper::~EventReportValidatorHelper() {}

EventReportValidator EventReportValidatorHelper::CreateValidator() {}

base::Value::List CreateOptInEventsList(
    const std::map<std::string, std::vector<std::string>>&
        enabled_opt_in_events) {}

#if BUILDFLAG(ENTERPRISE_CONTENT_ANALYSIS)
void SetAnalysisConnector(PrefService* prefs,
                          AnalysisConnector connector,
                          const std::string& pref_value,
                          bool machine_scope) {}

void SetOnSecurityEventReporting(
    PrefService* prefs,
    bool enabled,
    const std::set<std::string>& enabled_event_names,
    const std::map<std::string, std::vector<std::string>>&
        enabled_opt_in_events,
    bool machine_scope) {}

void ClearAnalysisConnector(PrefService* prefs, AnalysisConnector connector) {}
#endif  // BUILDFLAG(ENTERPRISE_CONTENT_ANALYSIS)

#if !BUILDFLAG(IS_CHROMEOS_ASH)
void SetProfileDMToken(Profile* profile, const std::string& dm_token) {}
#endif

}  // namespace enterprise_connectors::test