#ifdef UNSAFE_BUFFERS_BUILD
#pragma allow_unsafe_buffers
#endif
#include "remoting/host/it2me/it2me_native_messaging_host.h"
#include <cstdint>
#include <memory>
#include <string>
#include <utility>
#include "base/compiler_specific.h"
#include "base/containers/span.h"
#include "base/functional/bind.h"
#include "base/json/json_reader.h"
#include "base/json/json_writer.h"
#include "base/location.h"
#include "base/logging.h"
#include "base/memory/ptr_util.h"
#include "base/memory/raw_ptr.h"
#include "base/numerics/safe_conversions.h"
#include "base/run_loop.h"
#include "base/test/task_environment.h"
#include "base/test/values_test_util.h"
#include "base/time/time.h"
#include "base/values.h"
#include "components/policy/core/common/fake_async_policy_loader.h"
#include "components/policy/policy_constants.h"
#include "remoting/base/auto_thread_task_runner.h"
#include "remoting/host/chromoting_host_context.h"
#include "remoting/host/it2me/it2me_constants.h"
#include "remoting/host/it2me/it2me_helpers.h"
#include "remoting/host/native_messaging/log_message_handler.h"
#include "remoting/host/native_messaging/native_messaging_pipe.h"
#include "remoting/host/native_messaging/pipe_messaging_channel.h"
#include "remoting/host/policy_watcher.h"
#include "remoting/host/setup/test_util.h"
#include "remoting/protocol/errors.h"
#include "remoting/protocol/ice_config.h"
#include "remoting/signaling/log_to_server.h"
#include "services/network/test/test_shared_url_loader_factory.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace remoting {
ErrorCode;
namespace {
const char kTestAccessCode[] = …;
constexpr base::TimeDelta kTestAccessCodeLifetime = …;
const char kTestClientUsername[] = …;
const char kTestStunServer[] = …;
void VerifyId(const base::Value::Dict& response, int expected_value) { … }
void VerifyStringProperty(const base::Value::Dict& response,
const std::string& name,
const std::string& expected_value) { … }
void VerifyCommonProperties(const base::Value::Dict& response,
const std::string& type,
int id) { … }
base::Value::Dict CreateConnectMessage(int id) { … }
base::Value::Dict CreateDisconnectMessage(int id) { … }
}
class MockIt2MeHost : public It2MeHost { … };
void MockIt2MeHost::Connect(
std::unique_ptr<ChromotingHostContext> context,
base::Value::Dict policies,
std::unique_ptr<It2MeConfirmationDialogFactory> dialog_factory,
base::WeakPtr<It2MeHost::Observer> observer,
CreateDeferredConnectContext create_connection_context,
const std::string& username,
const protocol::IceConfig& ice_config) { … }
void MockIt2MeHost::Disconnect() { … }
void MockIt2MeHost::CreateConnectionContextOnNetworkThread(
CreateDeferredConnectContext create_connection_context) { … }
void MockIt2MeHost::RunSetState(It2MeHostState state) { … }
class MockIt2MeHostFactory : public It2MeHostFactory { … };
class It2MeNativeMessagingHostTest : public testing::Test { … };
void It2MeNativeMessagingHostTest::SetUp() { … }
void It2MeNativeMessagingHostTest::TearDown() { … }
void It2MeNativeMessagingHostTest::SetPolicies(base::Value::Dict dict) { … }
std::optional<base::Value::Dict>
It2MeNativeMessagingHostTest::ReadMessageFromOutputPipe() { … }
void It2MeNativeMessagingHostTest::WriteMessageToInputPipe(
const base::Value::Dict& message) { … }
void It2MeNativeMessagingHostTest::VerifyHelloResponse(int request_id) { … }
void It2MeNativeMessagingHostTest::VerifyErrorResponse() { … }
void It2MeNativeMessagingHostTest::VerifyConnectResponses(int request_id) { … }
void It2MeNativeMessagingHostTest::VerifyDisconnectResponses(int request_id) { … }
void It2MeNativeMessagingHostTest::VerifyPolicyErrorResponse() { … }
void It2MeNativeMessagingHostTest::TestBadRequest(
const base::Value::Dict& message,
bool expect_error_response) { … }
void It2MeNativeMessagingHostTest::StartHost() { … }
void It2MeNativeMessagingHostTest::ExitTest() { … }
void It2MeNativeMessagingHostTest::ExitPolicyRunLoop() { … }
void It2MeNativeMessagingHostTest::TestConnect() { … }
TEST_F(It2MeNativeMessagingHostTest, Hello) { … }
TEST_F(It2MeNativeMessagingHostTest, Id) { … }
TEST_F(It2MeNativeMessagingHostTest, ConnectMultiple) { … }
TEST_F(It2MeNativeMessagingHostTest,
ConnectRespectsSuppressUserDialogsParameterOnChromeOsOnly) { … }
TEST_F(It2MeNativeMessagingHostTest,
ConnectRespectsSuppressNotificationsParameterOnChromeOsOnly) { … }
TEST_F(It2MeNativeMessagingHostTest,
ConnectRespectsTerminateUponInputParameterOnChromeOsOnly) { … }
TEST_F(It2MeNativeMessagingHostTest,
ConnectRespectsIsEnterpriseAdminUserParameterOnChromeOsOnly) { … }
TEST_F(It2MeNativeMessagingHostTest,
ConnectRespectsCurtainLocalUserSessionParameterOnChromeOsOnly) { … }
TEST_F(It2MeNativeMessagingHostTest, MissingType) { … }
TEST_F(It2MeNativeMessagingHostTest, InvalidType) { … }
TEST_F(It2MeNativeMessagingHostTest, BadPoliciesBeforeConnect) { … }
TEST_F(It2MeNativeMessagingHostTest, BadPoliciesAfterConnect) { … }
}