Files
brave-core/app/brave_main_delegate_unittest.cc
T
b901ba9684 sync: Add experimental flag to configure the self-hosted sync service URL (#28463)
* sync: Add experimental flag to configure the self-hosted sync service URL.

* sync: Set the |BRAVE_SYNC_ENDPOINT| directly in kSyncServerUrl/kSyncDevServerUrl using chromium_src overrides instead of passing it via command_line

* sync: Remove the test case for checking if the BRAVE_SYNC_ENDPOINT is set via the command line.

* sync: Improve self-hosted sync URL validation and rename flag

- Enhanced validation to accept only valid HTTPS URLs or trustworthy HTTP origins (e.g., localhost)
- Renamed sync URL flag to brave-override-sync-server-url and updated its description.

* sync: fix build issue due to GN deps

* Update text desc in browser/about_flags.cc

Co-authored-by: Francois Marier <francois@fmarier.org>

* sync: Add tests for Self-host sync server URL validation

Add parameterized browser tests to verify the logic in `BraveMainDelegate` for handling the `--sync-url` command-line switch / feature flag.

The tests cover the following scenarios:
- Secure HTTPS URLs are accepted.
- Insecure HTTP URLs are rejected by default.
- HTTP URLs for localhost are accepted (as a trustworthy origin).
- Insecure HTTP URLs are accepted if the origin is explicitly marked as secure via `--unsafely-treat-insecure-origin-as-secure`.
- The absence of the `--sync-url` switch.

* sync: add a warning when the user provided sync url is invalid

* sync: address test failures likely caused by merge conflicts

* test: Filter HistoryNoticeUtilsTest.WebHistoryStates due to sync endpoint change

The test fails because it expects Google's sync server endpoint while Brave
uses a different sync server endpoint.

---------

Co-authored-by: Brian Clifton <brian@clifton.me>
Co-authored-by: Francois Marier <francois@fmarier.org>
2025-07-01 17:37:39 -07:00

60 lines
2.4 KiB
C++

/* Copyright (c) 2024 The Brave Authors. All rights reserved.
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at https://mozilla.org/MPL/2.0/. */
#include "brave/app/brave_main_delegate.h"
#include <string>
#include "base/command_line.h"
#include "brave/components/brave_sync/buildflags.h"
#include "brave/components/variations/buildflags.h"
#include "components/embedder_support/switches.h"
#include "components/sync/base/command_line_switches.h"
#include "components/variations/variations_switches.h"
#include "testing/gtest/include/gtest/gtest.h"
constexpr char kBraveOriginTrialsPublicKey[] =
"bYUKPJoPnCxeNvu72j4EmPuK7tr1PAC7SHh8ld9Mw3E=,"
"fMS4mpO6buLQ/QMd+zJmxzty/VQ6B1EUZqoCU04zoRU=";
TEST(BraveMainDelegateUnitTest, DefaultCommandLineOverrides) {
base::CommandLine& command_line = *base::CommandLine::ForCurrentProcess();
BraveMainDelegate::AppendCommandLineOptions();
ASSERT_STREQ(
kBraveOriginTrialsPublicKey,
command_line.GetSwitchValueASCII(embedder_support::kOriginTrialPublicKey)
.c_str());
ASSERT_STREQ(
BUILDFLAG(BRAVE_VARIATIONS_SERVER_URL),
command_line
.GetSwitchValueASCII(variations::switches::kVariationsServerURL)
.c_str());
ASSERT_STREQ(BUILDFLAG(BRAVE_VARIATIONS_SERVER_URL),
command_line
.GetSwitchValueASCII(
variations::switches::kVariationsInsecureServerURL)
.c_str());
}
TEST(BraveMainDelegateUnitTest, OverrideSwitchFromCommandLine) {
base::CommandLine& command_line = *base::CommandLine::ForCurrentProcess();
const std::string override_sync_url = "https://sync.com";
const std::string override_origin_trials_public_key = "public_key";
command_line.AppendSwitchASCII(syncer::kSyncServiceURL, override_sync_url);
command_line.AppendSwitchASCII(embedder_support::kOriginTrialPublicKey,
override_origin_trials_public_key);
BraveMainDelegate::AppendCommandLineOptions();
ASSERT_STREQ(
override_sync_url.c_str(),
command_line.GetSwitchValueASCII(syncer::kSyncServiceURL).c_str());
ASSERT_STREQ(
override_origin_trials_public_key.c_str(),
command_line.GetSwitchValueASCII(embedder_support::kOriginTrialPublicKey)
.c_str());
}