Commit d48b58c7 authored by Dominique Fauteux-Chapleau's avatar Dominique Fauteux-Chapleau Committed by Commit Bot

Add --binary-upload-service-url switch support

This will allow to override the URL used by BinaryUploadService::Request
on Chromium builds for development purposes.

Bug: 1108856
Change-Id: I8a4645b3fdb73c6268e0dbb790c539b1a2eb5824
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2314688
Commit-Queue: Dominique Fauteux-Chapleau <domfc@chromium.org>
Reviewed-by: default avatarDaniel Rubery <drubery@chromium.org>
Reviewed-by: default avatarRoger Tawa <rogerta@chromium.org>
Cr-Commit-Position: refs/heads/master@{#791844}
parent 37c791e7
...@@ -11,12 +11,15 @@ ...@@ -11,12 +11,15 @@
#include "base/base64.h" #include "base/base64.h"
#include "base/bind.h" #include "base/bind.h"
#include "base/bind_helpers.h" #include "base/bind_helpers.h"
#include "base/command_line.h"
#include "base/metrics/histogram_functions.h" #include "base/metrics/histogram_functions.h"
#include "base/optional.h"
#include "base/rand_util.h" #include "base/rand_util.h"
#include "base/strings/string_number_conversions.h" #include "base/strings/string_number_conversions.h"
#include "base/threading/thread_task_runner_handle.h" #include "base/threading/thread_task_runner_handle.h"
#include "base/time/time.h" #include "base/time/time.h"
#include "base/timer/timer.h" #include "base/timer/timer.h"
#include "build/branding_buildflags.h"
#include "chrome/browser/browser_process.h" #include "chrome/browser/browser_process.h"
#include "chrome/browser/enterprise/connectors/connectors_manager.h" #include "chrome/browser/enterprise/connectors/connectors_manager.h"
#include "chrome/browser/profiles/profile.h" #include "chrome/browser/profiles/profile.h"
...@@ -84,6 +87,24 @@ std::string ResultToString(BinaryUploadService::Result result) { ...@@ -84,6 +87,24 @@ std::string ResultToString(BinaryUploadService::Result result) {
} }
} }
#if !BUILDFLAG(GOOGLE_CHROME_BRANDING)
constexpr char kBinaryUploadServiceUrlFlag[] = "binary-upload-service-url";
#endif
base::Optional<GURL> GetUrlOverride() {
#if !BUILDFLAG(GOOGLE_CHROME_BRANDING)
base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
if (command_line->HasSwitch(kBinaryUploadServiceUrlFlag)) {
GURL url =
GURL(command_line->GetSwitchValueASCII(kBinaryUploadServiceUrlFlag));
if (url.is_valid())
return url;
}
#endif
return base::nullopt;
}
} // namespace } // namespace
BinaryUploadService::BinaryUploadService( BinaryUploadService::BinaryUploadService(
...@@ -728,10 +749,10 @@ void BinaryUploadService::Request::SerializeToString( ...@@ -728,10 +749,10 @@ void BinaryUploadService::Request::SerializeToString(
} }
GURL BinaryUploadService::Request::GetUrlWithParams() const { GURL BinaryUploadService::Request::GetUrlWithParams() const {
if (use_legacy_proto_) GURL url = GetUrlOverride().value_or(url_);
return url_;
GURL url(url_); if (use_legacy_proto_)
return url;
url = net::AppendQueryParameter(url, enterprise::kUrlParamDeviceToken, url = net::AppendQueryParameter(url, enterprise::kUrlParamDeviceToken,
device_token()); device_token());
......
...@@ -10,7 +10,9 @@ ...@@ -10,7 +10,9 @@
#include "base/bind.h" #include "base/bind.h"
#include "base/bind_helpers.h" #include "base/bind_helpers.h"
#include "base/callback_forward.h" #include "base/callback_forward.h"
#include "base/command_line.h"
#include "base/time/time.h" #include "base/time/time.h"
#include "build/branding_buildflags.h"
#include "chrome/browser/safe_browsing/advanced_protection_status_manager.h" #include "chrome/browser/safe_browsing/advanced_protection_status_manager.h"
#include "chrome/browser/safe_browsing/advanced_protection_status_manager_factory.h" #include "chrome/browser/safe_browsing/advanced_protection_status_manager_factory.h"
#include "chrome/browser/safe_browsing/cloud_content_scanning/binary_fcm_service.h" #include "chrome/browser/safe_browsing/cloud_content_scanning/binary_fcm_service.h"
...@@ -593,4 +595,38 @@ TEST_F(BinaryUploadServiceTest, ConnectorUrlParams) { ...@@ -593,4 +595,38 @@ TEST_F(BinaryUploadServiceTest, ConnectorUrlParams) {
} }
} }
TEST_F(BinaryUploadServiceTest, UrlOverride) {
MockRequest request(
base::DoNothing(),
GURL("https://safebrowsing.google.com/safebrowsing/uploads/scan"));
request.set_device_token("fake_token");
request.set_analysis_connector(enterprise_connectors::FILE_ATTACHED);
request.add_tag("dlp");
request.add_tag("malware");
base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
command_line->AppendSwitchASCII("binary-upload-service-url",
"https://test.com/scan");
// The flag should only work on Chromium builds.
#if BUILDFLAG(GOOGLE_CHROME_BRANDING)
ASSERT_EQ(GURL("https://safebrowsing.google.com/safebrowsing/uploads/"
"scan?device_token=fake_token&connector=OnFileAttached&tag="
"dlp&tag=malware"),
request.GetUrlWithParams());
#else
ASSERT_EQ(GURL("https://test.com/scan?device_token=fake_token&connector="
"OnFileAttached&tag=dlp&tag=malware"),
request.GetUrlWithParams());
#endif
command_line->RemoveSwitch("binary-upload-service-url");
// The flag being empty should not affect the URL at all, on either builds.
ASSERT_EQ(GURL("https://safebrowsing.google.com/safebrowsing/uploads/"
"scan?device_token=fake_token&connector=OnFileAttached&tag="
"dlp&tag=malware"),
request.GetUrlWithParams());
}
} // namespace safe_browsing } // namespace safe_browsing
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment