Skip to content

Commit

Permalink
Fix 10279: Set updater endpoint at build time
Browse files Browse the repository at this point in the history
  • Loading branch information
jumde committed Jun 17, 2020
1 parent 4e10666 commit 42e0db2
Show file tree
Hide file tree
Showing 9 changed files with 54 additions and 25 deletions.
5 changes: 4 additions & 1 deletion browser/net/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@ import("//build/config/features.gni")
defines = brave_service_key_defines

source_set("net") {
configs += [ "//brave/build/geolocation" ]
configs += [
"//brave/build/geolocation",
"//brave/common:network_config"
]
sources = [
"brave_ad_block_tp_network_delegate_helper.cc",
"brave_ad_block_tp_network_delegate_helper.h",
Expand Down
35 changes: 25 additions & 10 deletions browser/net/brave_common_static_redirect_network_delegate_helper.cc
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,25 @@

namespace brave {

const char kUpdaterTestingEndpoint[] = "test.updater.com";

namespace {

bool g_updater_url_host_for_testing_ = false;

std::string GetUpdateURLHost() {
if (g_updater_url_host_for_testing_)
return kUpdaterTestingEndpoint;

const base::CommandLine& command_line =
*base::CommandLine::ForCurrentProcess();
if (!command_line.HasSwitch(switches::kUseGoUpdateDev) &&
!base::FeatureList::IsEnabled(features::kUseDevUpdaterUrl)) {
return UPDATER_PROD_ENDPOINT;
}
return UPDATER_DEV_ENDPOINT;
}

// Update server checks happen from the profile context for admin policy
// installed extensions. Update server checks happen from the system context for
// normal update operations.
Expand Down Expand Up @@ -75,6 +92,10 @@ bool RewriteBugReportingURL(const GURL& request_url, GURL* new_url) {

} // namespace

void SetUpdateURLHostForTesting(bool testing) {
g_updater_url_host_for_testing_ = testing;
}

int OnBeforeURLRequest_CommonStaticRedirectWork(
const ResponseCallback& next_callback,
std::shared_ptr<BraveRequestInfo> ctx) {
Expand Down Expand Up @@ -102,16 +123,10 @@ int OnBeforeURLRequest_CommonStaticRedirectWorkForGURL(
"*://bugs.chromium.org/p/chromium/issues/entry?*");

if (IsUpdaterURL(request_url)) {
replacements.SetQueryStr(request_url.query_piece());
const base::CommandLine& command_line =
*base::CommandLine::ForCurrentProcess();
if (!command_line.HasSwitch(switches::kUseGoUpdateDev) &&
!base::FeatureList::IsEnabled(features::kUseDevUpdaterUrl)) {
*new_url = GURL(kBraveUpdatesExtensionsProdEndpoint)
.ReplaceComponents(replacements);
} else {
*new_url = GURL(kBraveUpdatesExtensionsDevEndpoint)
.ReplaceComponents(replacements);
auto update_host = GetUpdateURLHost();
if (!update_host.empty()) {
replacements.SetQueryStr(request_url.query_piece());
*new_url = GURL(update_host).ReplaceComponents(replacements);
}
return net::OK;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ class GURL;

namespace brave {

extern const char kUpdaterTestingEndpoint[];

int OnBeforeURLRequest_CommonStaticRedirectWork(
const ResponseCallback& next_callback,
std::shared_ptr<BraveRequestInfo> ctx);
Expand All @@ -22,6 +24,7 @@ int OnBeforeURLRequest_CommonStaticRedirectWorkForGURL(
const GURL& url,
GURL* new_url);

void SetUpdateURLHostForTesting(bool testing);
} // namespace brave

#endif // BRAVE_BROWSER_NET_BRAVE_COMMON_STATIC_REDIRECT_NETWORK_DELEGATE_HELPER_H_
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,12 @@ const char kComponentUpdaterProxy[] = "https://componentupdater.brave.com";

TEST(BraveCommonStaticRedirectNetworkDelegateHelperTest,
ModifyComponentUpdaterURL) {
brave::SetUpdateURLHostForTesting(true);
const std::string query_string("?foo=bar");
const GURL url(component_updater::kUpdaterJSONDefaultUrl + query_string);
auto request_info = std::make_shared<brave::BraveRequestInfo>(url);
const GURL expected_url(
std::string(kBraveUpdatesExtensionsProdEndpoint + query_string));
std::string(brave::kUpdaterTestingEndpoint + query_string));

int rc = OnBeforeURLRequest_CommonStaticRedirectWork(ResponseCallback(),
request_info);
Expand All @@ -39,13 +40,14 @@ TEST(BraveCommonStaticRedirectNetworkDelegateHelperTest,

TEST(BraveCommonStaticRedirectNetworkDelegateHelperTest,
ModifyComponentUpdaterURLDev) {
brave::SetUpdateURLHostForTesting(true);
base::CommandLine::ForCurrentProcess()->AppendSwitch(
switches::kUseGoUpdateDev);
const std::string query_string("?foo=bar");
const GURL url(component_updater::kUpdaterJSONDefaultUrl + query_string);
auto request_info = std::make_shared<brave::BraveRequestInfo>(url);
const GURL expected_url(
std::string(kBraveUpdatesExtensionsDevEndpoint + query_string));
std::string(brave::kUpdaterTestingEndpoint + query_string));

int rc = OnBeforeURLRequest_CommonStaticRedirectWork(ResponseCallback(),
request_info);
Expand Down
12 changes: 12 additions & 0 deletions common/BUILD.gn
Original file line number Diff line number Diff line change
@@ -1,6 +1,18 @@
import("//build/util/branding.gni")
import("//extensions/buildflags/buildflags.gni")

declare_args() {
updater_dev_endpoint = ""
updater_prod_endpoint = ""
}

config("network_config") {
defines = [
"UPDATER_DEV_ENDPOINT=\"$updater_dev_endpoint\"",
"UPDATER_PROD_ENDPOINT=\"$updater_prod_endpoint\"",
]
}

source_set("channel_info") {
if (is_linux) {
sources = [
Expand Down
8 changes: 0 additions & 8 deletions common/network_constants.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,6 @@

const char kBraveProxyPattern[] = "https://*.brave.com/*";
const char kBraveSoftwareProxyPattern[] = "https://*.bravesoftware.com/*";
const char kBraveUpdatesExtensionsProdEndpoint[] =
"https://go-updater.brave.com/extensions";

const char kBraveUpdatesExtensionsDevEndpoint[] =
"https://go-updater-dev.bravesoftware.com/extensions";
// For debgugging:
// const char kBraveUpdatesExtensionsEndpoint[] =
// "http://localhost:8192/extensions";

const char kBraveReferralsServer[] = "laptop-updates.brave.com";
const char kBraveReferralsHeadersPath[] = "/promo/custom-headers";
Expand Down
2 changes: 0 additions & 2 deletions common/network_constants.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@

extern const char kBraveProxyPattern[];
extern const char kBraveSoftwareProxyPattern[];
extern const char kBraveUpdatesExtensionsProdEndpoint[];
extern const char kBraveUpdatesExtensionsDevEndpoint[];

extern const char kBraveReferralsServer[];
extern const char kBraveReferralsHeadersPath[];
Expand Down
4 changes: 4 additions & 0 deletions components/greaselion/browser/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ source_set("browser") {
"switches.h",
]

configs += [
"//brave/common:network_config"
]

deps = [
"//base",
"//brave/components/brave_component_updater/browser",
Expand Down
4 changes: 2 additions & 2 deletions components/greaselion/browser/greaselion_service_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,11 @@ scoped_refptr<Extension> ConvertGreaselionRuleToExtensionOnTaskRunner(
*base::CommandLine::ForCurrentProcess();
if (!command_line.HasSwitch(switches::kUseGoUpdateDev) &&
!base::FeatureList::IsEnabled(features::kUseDevUpdaterUrl)) {
crypto::SHA256HashString(kBraveUpdatesExtensionsDevEndpoint + script_name,
crypto::SHA256HashString(UPDATER_DEV_ENDPOINT + script_name,
raw,
crypto::kSHA256Length);
} else {
crypto::SHA256HashString(kBraveUpdatesExtensionsProdEndpoint + script_name,
crypto::SHA256HashString(UPDATER_PROD_ENDPOINT + script_name,
raw,
crypto::kSHA256Length);
}
Expand Down

0 comments on commit 42e0db2

Please sign in to comment.