chromium/chrome/browser/enterprise/connectors/analysis/files_request_handler_unittest.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.

#ifdef UNSAFE_BUFFERS_BUILD
// TODO(crbug.com/40285824): Remove this and convert code to safer constructs.
#pragma allow_unsafe_buffers
#endif

#include "chrome/browser/enterprise/connectors/analysis/files_request_handler.h"

#include <map>
#include <set>
#include <string>
#include <vector>

#include "base/files/file_path.h"
#include "base/files/file_util.h"
#include "base/files/scoped_temp_dir.h"
#include "base/functional/bind.h"
#include "base/memory/raw_ptr.h"
#include "base/memory/weak_ptr.h"
#include "base/path_service.h"
#include "base/task/single_thread_task_runner.h"
#include "base/test/bind.h"
#include "base/test/gmock_callback_support.h"
#include "base/test/scoped_feature_list.h"
#include "base/test/test_future.h"
#include "build/build_config.h"
#include "chrome/browser/enterprise/connectors/analysis/content_analysis_features.h"
#include "chrome/browser/enterprise/connectors/common.h"
#include "chrome/browser/enterprise/connectors/connectors_service.h"
#include "chrome/browser/enterprise/connectors/test/deep_scanning_test_utils.h"
#include "chrome/browser/enterprise/connectors/test/fake_content_analysis_delegate.h"
#include "chrome/browser/enterprise/connectors/test/fake_files_request_handler.h"
#include "chrome/browser/policy/dm_token_utils.h"
#include "chrome/browser/safe_browsing/cloud_content_scanning/binary_upload_service.h"
#include "chrome/browser/safe_browsing/cloud_content_scanning/deep_scanning_utils.h"
#include "chrome/common/chrome_paths.h"
#include "chrome/test/base/testing_browser_process.h"
#include "chrome/test/base/testing_profile.h"
#include "chrome/test/base/testing_profile_manager.h"
#include "components/enterprise/buildflags/buildflags.h"
#include "components/enterprise/common/proto/connectors.pb.h"
#include "components/file_access/test/mock_scoped_file_access_delegate.h"
#include "components/prefs/testing_pref_service.h"
#include "content/public/test/browser_task_environment.h"
#include "content/public/test/test_utils.h"
#include "testing/gmock/include/gmock/gmock-matchers.h"
#include "testing/gtest/include/gtest/gtest.h"

namespace enterprise_connectors {

namespace {

constexpr char kDmToken[] =;
constexpr char kUserActionId[] =;
constexpr char kTabTitle[] =;
constexpr char kContentTransferMethod[] =;
constexpr char kTestUrl[] =;
base::TimeDelta kResponseDelay =;

constexpr char kBlockingScansForDlpAndMalware[] =;

constexpr char kBlockingScansForDlp[] =;

constexpr char kBlockingScansForMalware[] =;

#if BUILDFLAG(ENTERPRISE_LOCAL_CONTENT_ANALYSIS)
constexpr char kLocalServiceProvider[] =;
#endif  // BUILDFLAG(ENTERPRISE_LOCAL_CONTENT_ANALYSIS)

constexpr char kNothingEnabled[] =;

class ScopedSetDMToken {};

class BaseTest : public testing::Test {};

MATCHER_P3(MatchesRequestHandlerResult, complies, final_result, tag, "") {}

}  // namespace

// Make a RequestHandlerResult show nicely in google tests.
// It's important that PrintTo() is defined in the SAME namespace that defines
// RequestHandlerResult.  C++'s look-up rules rely on that. Additionally, it
// cannot go into the anonymous namespace.
void PrintTo(const RequestHandlerResult& request_handler_result,
             std::ostream* os) {}

class FilesRequestHandlerTest : public BaseTest {};

TEST_F(FilesRequestHandlerTest, Empty) {}

TEST_F(FilesRequestHandlerTest, ZeroLengthFileSucceeds) {}

TEST_F(FilesRequestHandlerTest, FileDataPositiveMalwareAndDlpVerdicts) {}

TEST_F(FilesRequestHandlerTest, FileDataPositiveMalwareAndDlpVerdicts2) {}

TEST_F(FilesRequestHandlerTest, FileDataPositiveMalwareVerdict) {}

TEST_F(FilesRequestHandlerTest, FileIsEncrypted) {}

// With a local service provider, a scan should not terminate early due to
// encryption.
#if BUILDFLAG(ENTERPRISE_LOCAL_CONTENT_ANALYSIS)
TEST_F(FilesRequestHandlerTest, FileIsEncrypted_LocalAnalysis) {}
#endif  // BUILDFLAG(ENTERPRISE_LOCAL_CONTENT_ANALYSIS)

TEST_F(FilesRequestHandlerTest, FileIsEncrypted_PolicyAllows) {}

TEST_F(FilesRequestHandlerTest, FileIsLarge) {}

// With a local service provider, a scan should not terminate early due to
// size.
#if BUILDFLAG(ENTERPRISE_LOCAL_CONTENT_ANALYSIS)
TEST_F(FilesRequestHandlerTest, FileIsLarge_LocalAnalysis) {}
#endif  // BUILDFLAG(ENTERPRISE_LOCAL_CONTENT_ANALYSIS)

TEST_F(FilesRequestHandlerTest, FileIsLarge_PolicyAllows) {}

// With a local service provider, multiple file uploads should result in
// multiple analysis requests.
#if BUILDFLAG(ENTERPRISE_LOCAL_CONTENT_ANALYSIS)
TEST_F(FilesRequestHandlerTest, MultipleFilesUpload_LocalAnalysis) {}
#endif  // BUILDFLAG(ENTERPRISE_LOCAL_CONTENT_ANALYSIS)

TEST_F(FilesRequestHandlerTest, FileDataNegativeMalwareVerdict) {}

TEST_F(FilesRequestHandlerTest, FileDataPositiveDlpVerdict) {}

TEST_F(FilesRequestHandlerTest, FileDataPositiveDlpVerdictDataControls) {}

TEST_F(FilesRequestHandlerTest, FileDataNegativeDlpVerdict) {}

TEST_F(FilesRequestHandlerTest, FileDataNegativeMalwareAndDlpVerdicts) {}

TEST_F(FilesRequestHandlerTest, NoDelay) {}

}  // namespace enterprise_connectors