Commit 93c9d23b authored by Dominique Fauteux-Chapleau's avatar Dominique Fauteux-Chapleau Committed by Chromium LUCI CQ

Add profile information for security event reporting

This adds the profile.dmToken and profile.clientId fields on non-CrOS,
and also excludes device information from reports when they are
profile-specific.

Bug: 1159533
Change-Id: I85df025aabfedbea2a295cf02225d0b44ed630a2
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2611546Reviewed-by: default avatarOwen Min <zmin@chromium.org>
Reviewed-by: default avatarDavid Roger <droger@chromium.org>
Reviewed-by: default avatarDaniel Rubery <drubery@chromium.org>
Commit-Queue: Dominique Fauteux-Chapleau <domfc@chromium.org>
Cr-Commit-Position: refs/heads/master@{#842215}
parent eea48782
...@@ -1043,6 +1043,7 @@ void SafeBrowsingPrivateEventRouter::ReportRealtimeEventCallback( ...@@ -1043,6 +1043,7 @@ void SafeBrowsingPrivateEventRouter::ReportRealtimeEventCallback(
auto* client = settings.per_profile ? profile_client_ : browser_client_; auto* client = settings.per_profile ? profile_client_ : browser_client_;
client->UploadSecurityEventReport( client->UploadSecurityEventReport(
context_, context_,
/* include_device_info */ !settings.per_profile,
policy::RealtimeReportingJobConfiguration::BuildReport( policy::RealtimeReportingJobConfiguration::BuildReport(
std::move(event_list), std::move(event_list),
reporting::GetContext(Profile::FromBrowserContext(context_))), reporting::GetContext(Profile::FromBrowserContext(context_))),
......
...@@ -62,7 +62,7 @@ namespace extensions { ...@@ -62,7 +62,7 @@ namespace extensions {
namespace { namespace {
ACTION_P(CaptureArg, wrapper) { ACTION_P(CaptureArg, wrapper) {
*wrapper = arg1.Clone(); *wrapper = arg2.Clone();
} }
constexpr char kConnectorsPrefValue[] = R"([ constexpr char kConnectorsPrefValue[] = R"([
...@@ -279,7 +279,7 @@ TEST_F(SafeBrowsingPrivateEventRouterTest, TestOnReuseDetected) { ...@@ -279,7 +279,7 @@ TEST_F(SafeBrowsingPrivateEventRouterTest, TestOnReuseDetected) {
event_router_->AddEventObserver(&event_observer); event_router_->AddEventObserver(&event_observer);
base::Value report; base::Value report;
EXPECT_CALL(*client_, UploadSecurityEventReport_(_, _, _)) EXPECT_CALL(*client_, UploadSecurityEventReport_(_, _, _, _))
.WillOnce(CaptureArg(&report)); .WillOnce(CaptureArg(&report));
TriggerOnPolicySpecifiedPasswordReuseDetectedEvent(); TriggerOnPolicySpecifiedPasswordReuseDetectedEvent();
...@@ -315,7 +315,7 @@ TEST_F(SafeBrowsingPrivateEventRouterTest, TestOnPasswordChanged) { ...@@ -315,7 +315,7 @@ TEST_F(SafeBrowsingPrivateEventRouterTest, TestOnPasswordChanged) {
event_router_->AddEventObserver(&event_observer); event_router_->AddEventObserver(&event_observer);
base::Value report; base::Value report;
EXPECT_CALL(*client_, UploadSecurityEventReport_(_, _, _)) EXPECT_CALL(*client_, UploadSecurityEventReport_(_, _, _, _))
.WillOnce(CaptureArg(&report)); .WillOnce(CaptureArg(&report));
TriggerOnPolicySpecifiedPasswordChangedEvent(); TriggerOnPolicySpecifiedPasswordChangedEvent();
...@@ -348,7 +348,7 @@ TEST_F(SafeBrowsingPrivateEventRouterTest, TestOnDangerousDownloadOpened) { ...@@ -348,7 +348,7 @@ TEST_F(SafeBrowsingPrivateEventRouterTest, TestOnDangerousDownloadOpened) {
event_router_->AddEventObserver(&event_observer); event_router_->AddEventObserver(&event_observer);
base::Value report; base::Value report;
EXPECT_CALL(*client_, UploadSecurityEventReport_(_, _, _)) EXPECT_CALL(*client_, UploadSecurityEventReport_(_, _, _, _))
.WillOnce(CaptureArg(&report)); .WillOnce(CaptureArg(&report));
TriggerOnDangerousDownloadOpenedEvent(); TriggerOnDangerousDownloadOpenedEvent();
...@@ -398,7 +398,7 @@ TEST_F(SafeBrowsingPrivateEventRouterTest, ...@@ -398,7 +398,7 @@ TEST_F(SafeBrowsingPrivateEventRouterTest,
event_router_->AddEventObserver(&event_observer); event_router_->AddEventObserver(&event_observer);
base::Value report; base::Value report;
EXPECT_CALL(*client_, UploadSecurityEventReport_(_, _, _)) EXPECT_CALL(*client_, UploadSecurityEventReport_(_, _, _, _))
.WillOnce(CaptureArg(&report)); .WillOnce(CaptureArg(&report));
TriggerOnSecurityInterstitialProceededEvent(); TriggerOnSecurityInterstitialProceededEvent();
...@@ -438,7 +438,7 @@ TEST_F(SafeBrowsingPrivateEventRouterTest, TestOnSecurityInterstitialShown) { ...@@ -438,7 +438,7 @@ TEST_F(SafeBrowsingPrivateEventRouterTest, TestOnSecurityInterstitialShown) {
event_router_->AddEventObserver(&event_observer); event_router_->AddEventObserver(&event_observer);
base::Value report; base::Value report;
EXPECT_CALL(*client_, UploadSecurityEventReport_(_, _, _)) EXPECT_CALL(*client_, UploadSecurityEventReport_(_, _, _, _))
.WillOnce(CaptureArg(&report)); .WillOnce(CaptureArg(&report));
TriggerOnSecurityInterstitialShownEvent(); TriggerOnSecurityInterstitialShownEvent();
...@@ -478,7 +478,7 @@ TEST_F(SafeBrowsingPrivateEventRouterTest, TestOnDangerousDownloadWarning) { ...@@ -478,7 +478,7 @@ TEST_F(SafeBrowsingPrivateEventRouterTest, TestOnDangerousDownloadWarning) {
event_router_->AddEventObserver(&event_observer); event_router_->AddEventObserver(&event_observer);
base::Value report; base::Value report;
EXPECT_CALL(*client_, UploadSecurityEventReport_(_, _, _)) EXPECT_CALL(*client_, UploadSecurityEventReport_(_, _, _, _))
.WillOnce(CaptureArg(&report)); .WillOnce(CaptureArg(&report));
TriggerOnDangerousDownloadEvent(); TriggerOnDangerousDownloadEvent();
...@@ -520,7 +520,7 @@ TEST_F(SafeBrowsingPrivateEventRouterTest, ...@@ -520,7 +520,7 @@ TEST_F(SafeBrowsingPrivateEventRouterTest,
event_router_->AddEventObserver(&event_observer); event_router_->AddEventObserver(&event_observer);
base::Value report; base::Value report;
EXPECT_CALL(*client_, UploadSecurityEventReport_(_, _, _)) EXPECT_CALL(*client_, UploadSecurityEventReport_(_, _, _, _))
.WillOnce(CaptureArg(&report)); .WillOnce(CaptureArg(&report));
TriggerOnDangerousDownloadEventBypass(); TriggerOnDangerousDownloadEventBypass();
...@@ -560,7 +560,7 @@ TEST_F(SafeBrowsingPrivateEventRouterTest, PolicyControlOnToOffIsDynamic) { ...@@ -560,7 +560,7 @@ TEST_F(SafeBrowsingPrivateEventRouterTest, PolicyControlOnToOffIsDynamic) {
api::safe_browsing_private::OnSecurityInterstitialShown::kEventName); api::safe_browsing_private::OnSecurityInterstitialShown::kEventName);
event_router_->AddEventObserver(&event_observer); event_router_->AddEventObserver(&event_observer);
EXPECT_CALL(*client_, UploadSecurityEventReport_(_, _, _)).Times(1); EXPECT_CALL(*client_, UploadSecurityEventReport_(_, _, _, _)).Times(1);
TriggerOnSecurityInterstitialShownEvent(); TriggerOnSecurityInterstitialShownEvent();
base::RunLoop().RunUntilIdle(); base::RunLoop().RunUntilIdle();
EXPECT_EQ(1u, event_observer.PassEventArgs().GetList().size()); EXPECT_EQ(1u, event_observer.PassEventArgs().GetList().size());
...@@ -568,7 +568,7 @@ TEST_F(SafeBrowsingPrivateEventRouterTest, PolicyControlOnToOffIsDynamic) { ...@@ -568,7 +568,7 @@ TEST_F(SafeBrowsingPrivateEventRouterTest, PolicyControlOnToOffIsDynamic) {
// Now turn off policy. This time no report should be generated. // Now turn off policy. This time no report should be generated.
SetReportingPolicy(false); SetReportingPolicy(false);
EXPECT_CALL(*client_, UploadSecurityEventReport_(_, _, _)).Times(0); EXPECT_CALL(*client_, UploadSecurityEventReport_(_, _, _, _)).Times(0);
TriggerOnSecurityInterstitialShownEvent(); TriggerOnSecurityInterstitialShownEvent();
base::RunLoop().RunUntilIdle(); base::RunLoop().RunUntilIdle();
EXPECT_EQ(1u, event_observer.PassEventArgs().GetList().size()); EXPECT_EQ(1u, event_observer.PassEventArgs().GetList().size());
...@@ -587,7 +587,7 @@ TEST_F(SafeBrowsingPrivateEventRouterTest, PolicyControlOffToOnIsDynamic) { ...@@ -587,7 +587,7 @@ TEST_F(SafeBrowsingPrivateEventRouterTest, PolicyControlOffToOnIsDynamic) {
// Now turn on policy. // Now turn on policy.
SetReportingPolicy(true); SetReportingPolicy(true);
EXPECT_CALL(*client_, UploadSecurityEventReport_(_, _, _)).Times(1); EXPECT_CALL(*client_, UploadSecurityEventReport_(_, _, _, _)).Times(1);
TriggerOnSecurityInterstitialShownEvent(); TriggerOnSecurityInterstitialShownEvent();
base::RunLoop().RunUntilIdle(); base::RunLoop().RunUntilIdle();
EXPECT_EQ(1u, event_observer.PassEventArgs().GetList().size()); EXPECT_EQ(1u, event_observer.PassEventArgs().GetList().size());
...@@ -602,7 +602,7 @@ TEST_F(SafeBrowsingPrivateEventRouterTest, TestUnauthorizedOnReuseDetected) { ...@@ -602,7 +602,7 @@ TEST_F(SafeBrowsingPrivateEventRouterTest, TestUnauthorizedOnReuseDetected) {
event_router_->AddEventObserver(&event_observer); event_router_->AddEventObserver(&event_observer);
base::Value report; base::Value report;
EXPECT_CALL(*client_, UploadSecurityEventReport_(_, _, _)).Times(0); EXPECT_CALL(*client_, UploadSecurityEventReport_(_, _, _, _)).Times(0);
TriggerOnPolicySpecifiedPasswordReuseDetectedEvent(); TriggerOnPolicySpecifiedPasswordReuseDetectedEvent();
base::RunLoop().RunUntilIdle(); base::RunLoop().RunUntilIdle();
...@@ -618,7 +618,7 @@ TEST_F(SafeBrowsingPrivateEventRouterTest, TestUnauthorizedOnPasswordChanged) { ...@@ -618,7 +618,7 @@ TEST_F(SafeBrowsingPrivateEventRouterTest, TestUnauthorizedOnPasswordChanged) {
event_router_->AddEventObserver(&event_observer); event_router_->AddEventObserver(&event_observer);
base::Value report; base::Value report;
EXPECT_CALL(*client_, UploadSecurityEventReport_(_, _, _)).Times(0); EXPECT_CALL(*client_, UploadSecurityEventReport_(_, _, _, _)).Times(0);
TriggerOnPolicySpecifiedPasswordChangedEvent(); TriggerOnPolicySpecifiedPasswordChangedEvent();
base::RunLoop().RunUntilIdle(); base::RunLoop().RunUntilIdle();
...@@ -635,7 +635,7 @@ TEST_F(SafeBrowsingPrivateEventRouterTest, ...@@ -635,7 +635,7 @@ TEST_F(SafeBrowsingPrivateEventRouterTest,
event_router_->AddEventObserver(&event_observer); event_router_->AddEventObserver(&event_observer);
base::Value report; base::Value report;
EXPECT_CALL(*client_, UploadSecurityEventReport_(_, _, _)).Times(0); EXPECT_CALL(*client_, UploadSecurityEventReport_(_, _, _, _)).Times(0);
TriggerOnDangerousDownloadOpenedEvent(); TriggerOnDangerousDownloadOpenedEvent();
base::RunLoop().RunUntilIdle(); base::RunLoop().RunUntilIdle();
...@@ -652,7 +652,7 @@ TEST_F(SafeBrowsingPrivateEventRouterTest, ...@@ -652,7 +652,7 @@ TEST_F(SafeBrowsingPrivateEventRouterTest,
event_router_->AddEventObserver(&event_observer); event_router_->AddEventObserver(&event_observer);
base::Value report; base::Value report;
EXPECT_CALL(*client_, UploadSecurityEventReport_(_, _, _)).Times(0); EXPECT_CALL(*client_, UploadSecurityEventReport_(_, _, _, _)).Times(0);
TriggerOnSecurityInterstitialProceededEvent(); TriggerOnSecurityInterstitialProceededEvent();
base::RunLoop().RunUntilIdle(); base::RunLoop().RunUntilIdle();
...@@ -669,7 +669,7 @@ TEST_F(SafeBrowsingPrivateEventRouterTest, ...@@ -669,7 +669,7 @@ TEST_F(SafeBrowsingPrivateEventRouterTest,
event_router_->AddEventObserver(&event_observer); event_router_->AddEventObserver(&event_observer);
base::Value report; base::Value report;
EXPECT_CALL(*client_, UploadSecurityEventReport_(_, _, _)).Times(0); EXPECT_CALL(*client_, UploadSecurityEventReport_(_, _, _, _)).Times(0);
TriggerOnSecurityInterstitialShownEvent(); TriggerOnSecurityInterstitialShownEvent();
base::RunLoop().RunUntilIdle(); base::RunLoop().RunUntilIdle();
...@@ -686,7 +686,7 @@ TEST_F(SafeBrowsingPrivateEventRouterTest, ...@@ -686,7 +686,7 @@ TEST_F(SafeBrowsingPrivateEventRouterTest,
event_router_->AddEventObserver(&event_observer); event_router_->AddEventObserver(&event_observer);
base::Value report; base::Value report;
EXPECT_CALL(*client_, UploadSecurityEventReport_(_, _, _)).Times(0); EXPECT_CALL(*client_, UploadSecurityEventReport_(_, _, _, _)).Times(0);
TriggerOnDangerousDownloadEvent(); TriggerOnDangerousDownloadEvent();
base::RunLoop().RunUntilIdle(); base::RunLoop().RunUntilIdle();
...@@ -703,7 +703,7 @@ TEST_F(SafeBrowsingPrivateEventRouterTest, ...@@ -703,7 +703,7 @@ TEST_F(SafeBrowsingPrivateEventRouterTest,
event_router_->AddEventObserver(&event_observer); event_router_->AddEventObserver(&event_observer);
base::Value report; base::Value report;
EXPECT_CALL(*client_, UploadSecurityEventReport_(_, _, _)).Times(0); EXPECT_CALL(*client_, UploadSecurityEventReport_(_, _, _, _)).Times(0);
TriggerOnDangerousDownloadEventBypass(); TriggerOnDangerousDownloadEventBypass();
base::RunLoop().RunUntilIdle(); base::RunLoop().RunUntilIdle();
...@@ -716,7 +716,7 @@ TEST_F(SafeBrowsingPrivateEventRouterTest, TestOnSensitiveDataEvent_Allowed) { ...@@ -716,7 +716,7 @@ TEST_F(SafeBrowsingPrivateEventRouterTest, TestOnSensitiveDataEvent_Allowed) {
SetUpRouters(/*realtime_reporting_enable=*/true, /*authorized=*/true); SetUpRouters(/*realtime_reporting_enable=*/true, /*authorized=*/true);
base::Value report; base::Value report;
EXPECT_CALL(*client_, UploadSecurityEventReport_(_, _, _)) EXPECT_CALL(*client_, UploadSecurityEventReport_(_, _, _, _))
.WillOnce(CaptureArg(&report)); .WillOnce(CaptureArg(&report));
TriggerOnSensitiveDataEvent(safe_browsing::EventResult::ALLOWED); TriggerOnSensitiveDataEvent(safe_browsing::EventResult::ALLOWED);
...@@ -766,7 +766,7 @@ TEST_F(SafeBrowsingPrivateEventRouterTest, TestOnSensitiveDataEvent_Blocked) { ...@@ -766,7 +766,7 @@ TEST_F(SafeBrowsingPrivateEventRouterTest, TestOnSensitiveDataEvent_Blocked) {
SetUpRouters(/*realtime_reporting_enable=*/true, /*authorized=*/true); SetUpRouters(/*realtime_reporting_enable=*/true, /*authorized=*/true);
base::Value report; base::Value report;
EXPECT_CALL(*client_, UploadSecurityEventReport_(_, _, _)) EXPECT_CALL(*client_, UploadSecurityEventReport_(_, _, _, _))
.WillOnce(CaptureArg(&report)); .WillOnce(CaptureArg(&report));
TriggerOnSensitiveDataEvent(safe_browsing::EventResult::BLOCKED); TriggerOnSensitiveDataEvent(safe_browsing::EventResult::BLOCKED);
...@@ -816,7 +816,7 @@ TEST_F(SafeBrowsingPrivateEventRouterTest, TestOnUnscannedFileEvent_Allowed) { ...@@ -816,7 +816,7 @@ TEST_F(SafeBrowsingPrivateEventRouterTest, TestOnUnscannedFileEvent_Allowed) {
SetUpRouters(/*realtime_reporting_enable=*/true, /*authorized=*/true); SetUpRouters(/*realtime_reporting_enable=*/true, /*authorized=*/true);
base::Value report; base::Value report;
EXPECT_CALL(*client_, UploadSecurityEventReport_(_, _, _)) EXPECT_CALL(*client_, UploadSecurityEventReport_(_, _, _, _))
.WillOnce(CaptureArg(&report)); .WillOnce(CaptureArg(&report));
TriggerOnUnscannedFileEvent(safe_browsing::EventResult::ALLOWED); TriggerOnUnscannedFileEvent(safe_browsing::EventResult::ALLOWED);
...@@ -860,7 +860,7 @@ TEST_F(SafeBrowsingPrivateEventRouterTest, TestOnUnscannedFileEvent_Blocked) { ...@@ -860,7 +860,7 @@ TEST_F(SafeBrowsingPrivateEventRouterTest, TestOnUnscannedFileEvent_Blocked) {
SetUpRouters(/*realtime_reporting_enable=*/true, /*authorized=*/true); SetUpRouters(/*realtime_reporting_enable=*/true, /*authorized=*/true);
base::Value report; base::Value report;
EXPECT_CALL(*client_, UploadSecurityEventReport_(_, _, _)) EXPECT_CALL(*client_, UploadSecurityEventReport_(_, _, _, _))
.WillOnce(CaptureArg(&report)); .WillOnce(CaptureArg(&report));
TriggerOnUnscannedFileEvent(safe_browsing::EventResult::BLOCKED); TriggerOnUnscannedFileEvent(safe_browsing::EventResult::BLOCKED);
...@@ -911,7 +911,7 @@ TEST_F(SafeBrowsingPrivateEventRouterTest, TestProfileUsername) { ...@@ -911,7 +911,7 @@ TEST_F(SafeBrowsingPrivateEventRouterTest, TestProfileUsername) {
->SetIdentityManagerForTesting( ->SetIdentityManagerForTesting(
identity_test_environment.identity_manager()); identity_test_environment.identity_manager());
EXPECT_CALL(*client_, UploadSecurityEventReport_(_, _, _)) EXPECT_CALL(*client_, UploadSecurityEventReport_(_, _, _, _))
.WillRepeatedly(Return()); .WillRepeatedly(Return());
// With no primary account, we should not set the username. // With no primary account, we should not set the username.
...@@ -1043,13 +1043,13 @@ TEST_P(SafeBrowsingIsRealtimeReportingEnabledTest, CheckRealtimeReport) { ...@@ -1043,13 +1043,13 @@ TEST_P(SafeBrowsingIsRealtimeReportingEnabledTest, CheckRealtimeReport) {
#endif #endif
if (should_report) { if (should_report) {
EXPECT_CALL(*client_, UploadSecurityEventReport_(_, _, _)).Times(1); EXPECT_CALL(*client_, UploadSecurityEventReport_(_, _, _, _)).Times(1);
} else if (client_) { } else if (client_) {
// Because the test will crate a |client_| object when the policy is // Because the test will crate a |client_| object when the policy is
// set, even if the feature flag or other conditions indicate that // set, even if the feature flag or other conditions indicate that
// reports should not be sent, it is possible that the pointer is not // reports should not be sent, it is possible that the pointer is not
// null. In this case, make sure UploadSecurityEventReport() is not called. // null. In this case, make sure UploadSecurityEventReport() is not called.
EXPECT_CALL(*client_, UploadSecurityEventReport_(_, _, _)).Times(0); EXPECT_CALL(*client_, UploadSecurityEventReport_(_, _, _, _)).Times(0);
} }
TriggerOnPolicySpecifiedPasswordChangedEvent(); TriggerOnPolicySpecifiedPasswordChangedEvent();
......
...@@ -17,31 +17,31 @@ ...@@ -17,31 +17,31 @@
#include "chrome/browser/profiles/profile_manager.h" #include "chrome/browser/profiles/profile_manager.h"
#include "components/account_id/account_id.h" #include "components/account_id/account_id.h"
#include "components/policy/core/common/cloud/cloud_policy_store.h" #include "components/policy/core/common/cloud/cloud_policy_store.h"
#include "components/policy/core/common/cloud/user_cloud_policy_manager.h"
#include "components/policy/proto/device_management_backend.pb.h" #include "components/policy/proto/device_management_backend.pb.h"
#include "components/user_manager/user.h" #include "components/user_manager/user.h"
#include "components/user_manager/user_manager.h" #include "components/user_manager/user_manager.h"
#ifdef OS_CHROMEOS #if defined(OS_CHROMEOS)
#include "chrome/browser/chromeos/login/users/affiliation.h" #include "chrome/browser/chromeos/login/users/affiliation.h"
#include "chrome/browser/chromeos/policy/user_cloud_policy_manager_chromeos.h" #include "chrome/browser/chromeos/policy/user_cloud_policy_manager_chromeos.h"
#include "chrome/browser/chromeos/profiles/profile_helper.h" #include "chrome/browser/chromeos/profiles/profile_helper.h"
#endif // OS_CHROMEOS #endif // defined(OS_CHROMEOS)
namespace { namespace {
#ifdef OS_CHROMEOS
// A callback which fetches device dm_token based on user affiliation.
using DeviceDMTokenCallback = base::RepeatingCallback<std::string(
const std::vector<std::string>& user_affiliation_ids)>;
// Returns policy for the given |profile|. If failed to get policy returns // Returns policy for the given |profile|. If failed to get policy returns
// nullptr. // nullptr.
const enterprise_management::PolicyData* GetPolicyData(Profile* profile) { const enterprise_management::PolicyData* GetPolicyData(Profile* profile) {
if (!profile) if (!profile)
return nullptr; return nullptr;
policy::UserCloudPolicyManagerChromeOS* manager = auto* manager =
#if defined(OS_CHROMEOS)
profile->GetUserCloudPolicyManagerChromeOS(); profile->GetUserCloudPolicyManagerChromeOS();
#else
profile->GetUserCloudPolicyManager();
#endif
if (!manager) if (!manager)
return nullptr; return nullptr;
...@@ -52,6 +52,28 @@ const enterprise_management::PolicyData* GetPolicyData(Profile* profile) { ...@@ -52,6 +52,28 @@ const enterprise_management::PolicyData* GetPolicyData(Profile* profile) {
return store->policy(); return store->policy();
} }
// Returns User DMToken for a given |profile| if:
// * |profile| is NOT incognito profile.
// * |profile| is NOT sign-in screen profile
// * user corresponding to a |profile| is managed.
// Otherwise returns empty string. More about DMToken:
// go/dmserver-domain-model#dmtoken.
std::string GetUserDmToken(Profile* profile) {
if (!profile)
return std::string();
const enterprise_management::PolicyData* policy = GetPolicyData(profile);
if (!policy || !policy->has_request_token())
return std::string();
return policy->request_token();
}
#if defined(OS_CHROMEOS)
// A callback which fetches device dm_token based on user affiliation.
using DeviceDMTokenCallback = base::RepeatingCallback<std::string(
const std::vector<std::string>& user_affiliation_ids)>;
// Returns the Device DMToken for the given |profile| if: // Returns the Device DMToken for the given |profile| if:
// * |profile| is NOT incognito profile // * |profile| is NOT incognito profile
// * user corresponding to a given |profile| is affiliated. // * user corresponding to a given |profile| is affiliated.
...@@ -81,23 +103,7 @@ std::string GetDeviceDmToken(Profile* profile) { ...@@ -81,23 +103,7 @@ std::string GetDeviceDmToken(Profile* profile) {
return device_dm_token_callback.Run(user_affiliation_ids); return device_dm_token_callback.Run(user_affiliation_ids);
} }
// Returns User DMToken for a given |profile| if: #endif // defined(OS_CHROMEOS)
// * |profile| is NOT incognito profile.
// * |profile| is NOT sign-in screen profile
// * user corresponding to a |profile| is managed.
// Otherwise returns empty string. More about DMToken:
// go/dmserver-domain-model#dmtoken.
std::string GetUserDmToken(Profile* profile) {
if (!profile)
return std::string();
const enterprise_management::PolicyData* policy = GetPolicyData(profile);
if (!policy || !policy->has_request_token())
return std::string();
return policy->request_token();
}
#endif // OS_CHROMEOS
} // namespace } // namespace
...@@ -120,22 +126,22 @@ base::Value GetContext(Profile* profile) { ...@@ -120,22 +126,22 @@ base::Value GetContext(Profile* profile) {
context.SetStringPath("profile.profilePath", profile->GetPath().value()); context.SetStringPath("profile.profilePath", profile->GetPath().value());
#ifdef OS_CHROMEOS
const enterprise_management::PolicyData* policy = GetPolicyData(profile); const enterprise_management::PolicyData* policy = GetPolicyData(profile);
if (policy) { if (policy) {
if (policy->has_device_id()) if (policy->has_device_id())
context.SetStringPath("profile.clientId", policy->device_id()); context.SetStringPath("profile.clientId", policy->device_id());
#if defined(OS_CHROMEOS)
std::string device_dm_token = GetDeviceDmToken(profile); std::string device_dm_token = GetDeviceDmToken(profile);
if (!device_dm_token.empty()) if (!device_dm_token.empty())
context.SetStringPath("device.dmToken", device_dm_token); context.SetStringPath("device.dmToken", device_dm_token);
#endif
std::string user_dm_token = GetUserDmToken(profile); std::string user_dm_token = GetUserDmToken(profile);
if (!user_dm_token.empty()) if (!user_dm_token.empty())
context.SetStringPath("profile.dmToken", user_dm_token); context.SetStringPath("profile.dmToken", user_dm_token);
} }
#endif // OS_CHROMEOS
return context; return context;
} }
......
...@@ -53,8 +53,9 @@ void EventReportValidator::ExpectUnscannedFileEvent( ...@@ -53,8 +53,9 @@ void EventReportValidator::ExpectUnscannedFileEvent(
content_size_ = expected_content_size; content_size_ = expected_content_size;
result_ = expected_result; result_ = expected_result;
username_ = expected_username; username_ = expected_username;
EXPECT_CALL(*client_, UploadSecurityEventReport_(_, _, _)) EXPECT_CALL(*client_, UploadSecurityEventReport_(_, _, _, _))
.WillOnce([this](content::BrowserContext* context, base::Value& report, .WillOnce([this](content::BrowserContext* context,
bool include_device_info, base::Value& report,
base::OnceCallback<void(bool)>& callback) { base::OnceCallback<void(bool)>& callback) {
ValidateReport(&report); ValidateReport(&report);
if (!done_closure_.is_null()) if (!done_closure_.is_null())
...@@ -82,8 +83,9 @@ void EventReportValidator::ExpectDangerousDeepScanningResult( ...@@ -82,8 +83,9 @@ void EventReportValidator::ExpectDangerousDeepScanningResult(
content_size_ = expected_content_size; content_size_ = expected_content_size;
result_ = expected_result; result_ = expected_result;
username_ = expected_username; username_ = expected_username;
EXPECT_CALL(*client_, UploadSecurityEventReport_(_, _, _)) EXPECT_CALL(*client_, UploadSecurityEventReport_(_, _, _, _))
.WillOnce([this](content::BrowserContext* context, base::Value& report, .WillOnce([this](content::BrowserContext* context,
bool include_device_info, base::Value& report,
base::OnceCallback<void(bool)>& callback) { base::OnceCallback<void(bool)>& callback) {
ValidateReport(&report); ValidateReport(&report);
if (!done_closure_.is_null()) if (!done_closure_.is_null())
...@@ -112,8 +114,9 @@ void EventReportValidator::ExpectSensitiveDataEvent( ...@@ -112,8 +114,9 @@ void EventReportValidator::ExpectSensitiveDataEvent(
content_size_ = expected_content_size; content_size_ = expected_content_size;
result_ = expected_result; result_ = expected_result;
username_ = expected_username; username_ = expected_username;
EXPECT_CALL(*client_, UploadSecurityEventReport_(_, _, _)) EXPECT_CALL(*client_, UploadSecurityEventReport_(_, _, _, _))
.WillOnce([this](content::BrowserContext* context, base::Value& report, .WillOnce([this](content::BrowserContext* context,
bool include_device_info, base::Value& report,
base::OnceCallback<void(bool)>& callback) { base::OnceCallback<void(bool)>& callback) {
ValidateReport(&report); ValidateReport(&report);
if (!done_closure_.is_null()) if (!done_closure_.is_null())
...@@ -144,13 +147,15 @@ void EventReportValidator:: ...@@ -144,13 +147,15 @@ void EventReportValidator::
content_size_ = expected_content_size; content_size_ = expected_content_size;
result_ = expected_result; result_ = expected_result;
username_ = expected_username; username_ = expected_username;
EXPECT_CALL(*client_, UploadSecurityEventReport_(_, _, _)) EXPECT_CALL(*client_, UploadSecurityEventReport_(_, _, _, _))
.WillOnce([this](content::BrowserContext* context, base::Value& report, .WillOnce([this](content::BrowserContext* context,
bool include_device_info, base::Value& report,
base::OnceCallback<void(bool)>& callback) { base::OnceCallback<void(bool)>& callback) {
ValidateReport(&report); ValidateReport(&report);
}) })
.WillOnce([this, expected_dlp_verdict]( .WillOnce([this, expected_dlp_verdict](
content::BrowserContext* context, base::Value& report, content::BrowserContext* context, bool include_device_info,
base::Value& report,
base::OnceCallback<void(bool)>& callback) { base::OnceCallback<void(bool)>& callback) {
event_key_ = SafeBrowsingPrivateEventRouter::kKeySensitiveDataEvent; event_key_ = SafeBrowsingPrivateEventRouter::kKeySensitiveDataEvent;
threat_type_ = base::nullopt; threat_type_ = base::nullopt;
...@@ -184,13 +189,15 @@ void EventReportValidator:: ...@@ -184,13 +189,15 @@ void EventReportValidator::
result_ = expected_result; result_ = expected_result;
dlp_verdict_ = expected_dlp_verdict; dlp_verdict_ = expected_dlp_verdict;
username_ = expected_username; username_ = expected_username;
EXPECT_CALL(*client_, UploadSecurityEventReport_(_, _, _)) EXPECT_CALL(*client_, UploadSecurityEventReport_(_, _, _, _))
.WillOnce([this](content::BrowserContext* context, base::Value& report, .WillOnce([this](content::BrowserContext* context,
bool include_device_info, base::Value& report,
base::OnceCallback<void(bool)>& callback) { base::OnceCallback<void(bool)>& callback) {
ValidateReport(&report); ValidateReport(&report);
}) })
.WillOnce([this, expected_threat_type]( .WillOnce([this, expected_threat_type](
content::BrowserContext* context, base::Value& report, content::BrowserContext* context, bool include_device_info,
base::Value& report,
base::OnceCallback<void(bool)>& callback) { base::OnceCallback<void(bool)>& callback) {
event_key_ = SafeBrowsingPrivateEventRouter::kKeyDangerousDownloadEvent; event_key_ = SafeBrowsingPrivateEventRouter::kKeyDangerousDownloadEvent;
threat_type_ = expected_threat_type; threat_type_ = expected_threat_type;
...@@ -221,8 +228,9 @@ void EventReportValidator::ExpectDangerousDownloadEvent( ...@@ -221,8 +228,9 @@ void EventReportValidator::ExpectDangerousDownloadEvent(
content_size_ = expected_content_size; content_size_ = expected_content_size;
result_ = expected_result; result_ = expected_result;
username_ = expected_username; username_ = expected_username;
EXPECT_CALL(*client_, UploadSecurityEventReport_(_, _, _)) EXPECT_CALL(*client_, UploadSecurityEventReport_(_, _, _, _))
.WillOnce([this](content::BrowserContext* context, base::Value& report, .WillOnce([this](content::BrowserContext* context,
bool include_device_info, base::Value& report,
base::OnceCallback<void(bool)>& callback) { base::OnceCallback<void(bool)>& callback) {
ValidateReport(&report); ValidateReport(&report);
if (!done_closure_.is_null()) if (!done_closure_.is_null())
...@@ -335,7 +343,7 @@ void EventReportValidator::ValidateField( ...@@ -335,7 +343,7 @@ void EventReportValidator::ValidateField(
} }
void EventReportValidator::ExpectNoReport() { void EventReportValidator::ExpectNoReport() {
EXPECT_CALL(*client_, UploadSecurityEventReport_(_, _, _)).Times(0); EXPECT_CALL(*client_, UploadSecurityEventReport_(_, _, _, _)).Times(0);
} }
void EventReportValidator::SetDoneClosure(base::RepeatingClosure closure) { void EventReportValidator::SetDoneClosure(base::RepeatingClosure closure) {
......
...@@ -596,6 +596,7 @@ void CloudPolicyClient::UploadChromeOsUserReport( ...@@ -596,6 +596,7 @@ void CloudPolicyClient::UploadChromeOsUserReport(
void CloudPolicyClient::UploadSecurityEventReport( void CloudPolicyClient::UploadSecurityEventReport(
content::BrowserContext* context, content::BrowserContext* context,
bool include_device_info,
base::Value report, base::Value report,
StatusCallback callback) { StatusCallback callback) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
...@@ -603,7 +604,7 @@ void CloudPolicyClient::UploadSecurityEventReport( ...@@ -603,7 +604,7 @@ void CloudPolicyClient::UploadSecurityEventReport(
CreateNewRealtimeReportingJob( CreateNewRealtimeReportingJob(
std::move(report), std::move(report),
service()->configuration()->GetReportingConnectorServerUrl(context), service()->configuration()->GetReportingConnectorServerUrl(context),
add_connector_url_params_, std::move(callback)); include_device_info, add_connector_url_params_, std::move(callback));
} }
void CloudPolicyClient::UploadEncryptedReport( void CloudPolicyClient::UploadEncryptedReport(
...@@ -636,7 +637,8 @@ void CloudPolicyClient::UploadAppInstallReport(base::Value report, ...@@ -636,7 +637,8 @@ void CloudPolicyClient::UploadAppInstallReport(base::Value report,
app_install_report_request_job_ = CreateNewRealtimeReportingJob( app_install_report_request_job_ = CreateNewRealtimeReportingJob(
std::move(report), std::move(report),
service()->configuration()->GetRealtimeReportingServerUrl(), service()->configuration()->GetRealtimeReportingServerUrl(),
/* add_connector_url_params=*/false, std::move(callback)); /* include_device_info */ true, /* add_connector_url_params=*/false,
std::move(callback));
DCHECK(app_install_report_request_job_); DCHECK(app_install_report_request_job_);
} }
...@@ -657,6 +659,7 @@ void CloudPolicyClient::UploadExtensionInstallReport(base::Value report, ...@@ -657,6 +659,7 @@ void CloudPolicyClient::UploadExtensionInstallReport(base::Value report,
extension_install_report_request_job_ = CreateNewRealtimeReportingJob( extension_install_report_request_job_ = CreateNewRealtimeReportingJob(
std::move(report), std::move(report),
service()->configuration()->GetRealtimeReportingServerUrl(), service()->configuration()->GetRealtimeReportingServerUrl(),
/* include_device_info */ true,
/* add_connector_url_params=*/false, std::move(callback)); /* add_connector_url_params=*/false, std::move(callback));
DCHECK(extension_install_report_request_job_); DCHECK(extension_install_report_request_job_);
} }
...@@ -702,11 +705,12 @@ void CloudPolicyClient::FetchRemoteCommands( ...@@ -702,11 +705,12 @@ void CloudPolicyClient::FetchRemoteCommands(
DeviceManagementService::Job* CloudPolicyClient::CreateNewRealtimeReportingJob( DeviceManagementService::Job* CloudPolicyClient::CreateNewRealtimeReportingJob(
base::Value report, base::Value report,
const std::string& server_url, const std::string& server_url,
bool include_device_info,
bool add_connector_url_params, bool add_connector_url_params,
StatusCallback callback) { StatusCallback callback) {
std::unique_ptr<RealtimeReportingJobConfiguration> config = std::unique_ptr<RealtimeReportingJobConfiguration> config =
std::make_unique<RealtimeReportingJobConfiguration>( std::make_unique<RealtimeReportingJobConfiguration>(
this, server_url, add_connector_url_params, this, server_url, include_device_info, add_connector_url_params,
base::BindOnce(&CloudPolicyClient::OnRealtimeReportUploadCompleted, base::BindOnce(&CloudPolicyClient::OnRealtimeReportUploadCompleted,
weak_ptr_factory_.GetWeakPtr(), std::move(callback))); weak_ptr_factory_.GetWeakPtr(), std::move(callback)));
......
...@@ -313,8 +313,11 @@ class POLICY_EXPORT CloudPolicyClient { ...@@ -313,8 +313,11 @@ class POLICY_EXPORT CloudPolicyClient {
// Uploads a report containing enterprise connectors real-time security // Uploads a report containing enterprise connectors real-time security
// events for |context|. As above, the client must be in a registered state. // events for |context|. As above, the client must be in a registered state.
// The |callback| will be called when the operation completes. // If |include_device_info| is true, information specific to the device such
// as the device name, user, id and OS will be included in the report. The
// |callback| will be called when the operation completes.
virtual void UploadSecurityEventReport(content::BrowserContext* context, virtual void UploadSecurityEventReport(content::BrowserContext* context,
bool include_device_info,
base::Value report, base::Value report,
StatusCallback callback); StatusCallback callback);
...@@ -792,12 +795,15 @@ class POLICY_EXPORT CloudPolicyClient { ...@@ -792,12 +795,15 @@ class POLICY_EXPORT CloudPolicyClient {
private: private:
// Creates a new real-time reporting job and appends it to |request_jobs_|. // Creates a new real-time reporting job and appends it to |request_jobs_|.
// The job will send its report to the |server_url| endpoint. If // The job will send its report to the |server_url| endpoint. If
// |include_device_info| is true, information specific to the device such as
// the device name, user, id and OS will be included in the report. If
// |add_connector_url_params| is true then URL paramaters specific to // |add_connector_url_params| is true then URL paramaters specific to
// enterprise connectors are added to the request uploading the report. // enterprise connectors are added to the request uploading the report.
// |callback| is invoked once the report is uploaded. // |callback| is invoked once the report is uploaded.
DeviceManagementService::Job* CreateNewRealtimeReportingJob( DeviceManagementService::Job* CreateNewRealtimeReportingJob(
base::Value report, base::Value report,
const std::string& server_url, const std::string& server_url,
bool include_device_info,
bool add_connector_url_params, bool add_connector_url_params,
StatusCallback callback); StatusCallback callback);
......
...@@ -1477,7 +1477,19 @@ TEST_F(CloudPolicyClientTest, UploadChromeOsUserReport) { ...@@ -1477,7 +1477,19 @@ TEST_F(CloudPolicyClientTest, UploadChromeOsUserReport) {
#if defined(OS_WIN) || defined(OS_APPLE) || defined(OS_LINUX) || \ #if defined(OS_WIN) || defined(OS_APPLE) || defined(OS_LINUX) || \
defined(OS_CHROMEOS) defined(OS_CHROMEOS)
TEST_F(CloudPolicyClientTest, UploadSecurityEventReport) {
class CloudPolicyClientUploadSecurityEventTest
: public CloudPolicyClientTest,
public testing::WithParamInterface<bool> {
public:
bool include_device_info() const { return GetParam(); }
};
INSTANTIATE_TEST_SUITE_P(,
CloudPolicyClientUploadSecurityEventTest,
testing::Bool());
TEST_P(CloudPolicyClientUploadSecurityEventTest, Test) {
RegisterClient(); RegisterClient();
ExpectAndCaptureJSONJob(/*response=*/"{}"); ExpectAndCaptureJSONJob(/*response=*/"{}");
...@@ -1486,7 +1498,8 @@ TEST_F(CloudPolicyClientTest, UploadSecurityEventReport) { ...@@ -1486,7 +1498,8 @@ TEST_F(CloudPolicyClientTest, UploadSecurityEventReport) {
base::BindOnce(&MockStatusCallbackObserver::OnCallbackComplete, base::BindOnce(&MockStatusCallbackObserver::OnCallbackComplete,
base::Unretained(&callback_observer_)); base::Unretained(&callback_observer_));
client_->UploadSecurityEventReport(nullptr, MakeDefaultRealtimeReport(), client_->UploadSecurityEventReport(nullptr, include_device_info(),
MakeDefaultRealtimeReport(),
std::move(callback)); std::move(callback));
base::RunLoop().RunUntilIdle(); base::RunLoop().RunUntilIdle();
EXPECT_EQ( EXPECT_EQ(
...@@ -1498,33 +1511,54 @@ TEST_F(CloudPolicyClientTest, UploadSecurityEventReport) { ...@@ -1498,33 +1511,54 @@ TEST_F(CloudPolicyClientTest, UploadSecurityEventReport) {
base::Optional<base::Value> payload = base::JSONReader::Read(job_payload_); base::Optional<base::Value> payload = base::JSONReader::Read(job_payload_);
ASSERT_TRUE(payload); ASSERT_TRUE(payload);
EXPECT_EQ(kDMToken, *payload->FindStringPath( ASSERT_FALSE(policy::GetDeviceName().empty());
ReportingJobConfigurationBase::
DeviceDictionaryBuilder::GetDMTokenPath()));
EXPECT_EQ(client_id_, *payload->FindStringPath(
ReportingJobConfigurationBase::
DeviceDictionaryBuilder::GetClientIdPath()));
EXPECT_EQ(policy::GetOSUsername(),
*payload->FindStringPath(
ReportingJobConfigurationBase::BrowserDictionaryBuilder::
GetMachineUserPath()));
EXPECT_EQ(version_info::GetVersionNumber(), EXPECT_EQ(version_info::GetVersionNumber(),
*payload->FindStringPath( *payload->FindStringPath(
ReportingJobConfigurationBase::BrowserDictionaryBuilder:: ReportingJobConfigurationBase::BrowserDictionaryBuilder::
GetChromeVersionPath())); GetChromeVersionPath()));
EXPECT_EQ(policy::GetOSPlatform(),
*payload->FindStringPath( if (include_device_info()) {
ReportingJobConfigurationBase::DeviceDictionaryBuilder:: EXPECT_EQ(kDMToken, *payload->FindStringPath(
GetOSPlatformPath())); ReportingJobConfigurationBase::
EXPECT_EQ(policy::GetOSVersion(), DeviceDictionaryBuilder::GetDMTokenPath()));
*payload->FindStringPath( EXPECT_EQ(client_id_, *payload->FindStringPath(
ReportingJobConfigurationBase::DeviceDictionaryBuilder:: ReportingJobConfigurationBase::
GetOSVersionPath())); DeviceDictionaryBuilder::GetClientIdPath()));
EXPECT_FALSE(policy::GetDeviceName().empty()); EXPECT_EQ(policy::GetOSUsername(),
EXPECT_EQ( *payload->FindStringPath(
policy::GetDeviceName(), ReportingJobConfigurationBase::BrowserDictionaryBuilder::
*payload->FindStringPath(ReportingJobConfigurationBase:: GetMachineUserPath()));
DeviceDictionaryBuilder::GetNamePath())); EXPECT_EQ(policy::GetOSPlatform(),
*payload->FindStringPath(
ReportingJobConfigurationBase::DeviceDictionaryBuilder::
GetOSPlatformPath()));
EXPECT_EQ(policy::GetOSVersion(),
*payload->FindStringPath(
ReportingJobConfigurationBase::DeviceDictionaryBuilder::
GetOSVersionPath()));
EXPECT_EQ(
policy::GetDeviceName(),
*payload->FindStringPath(ReportingJobConfigurationBase::
DeviceDictionaryBuilder::GetNamePath()));
} else {
EXPECT_FALSE(
payload->FindStringPath(ReportingJobConfigurationBase::
DeviceDictionaryBuilder::GetDMTokenPath()));
EXPECT_FALSE(payload->FindStringPath(
ReportingJobConfigurationBase::DeviceDictionaryBuilder::
GetClientIdPath()));
EXPECT_FALSE(payload->FindStringPath(
ReportingJobConfigurationBase::BrowserDictionaryBuilder::
GetMachineUserPath()));
EXPECT_FALSE(payload->FindStringPath(
ReportingJobConfigurationBase::DeviceDictionaryBuilder::
GetOSPlatformPath()));
EXPECT_FALSE(payload->FindStringPath(
ReportingJobConfigurationBase::DeviceDictionaryBuilder::
GetOSVersionPath()));
EXPECT_FALSE(payload->FindStringPath(
ReportingJobConfigurationBase::DeviceDictionaryBuilder::GetNamePath()));
}
base::Value* events = base::Value* events =
payload->FindPath(RealtimeReportingJobConfiguration::kEventListKey); payload->FindPath(RealtimeReportingJobConfiguration::kEventListKey);
...@@ -1535,7 +1569,7 @@ TEST_F(CloudPolicyClientTest, UploadSecurityEventReport) { ...@@ -1535,7 +1569,7 @@ TEST_F(CloudPolicyClientTest, UploadSecurityEventReport) {
TEST_F(CloudPolicyClientTest, RealtimeReportMerge) { TEST_F(CloudPolicyClientTest, RealtimeReportMerge) {
auto config = std::make_unique<RealtimeReportingJobConfiguration>( auto config = std::make_unique<RealtimeReportingJobConfiguration>(
client_.get(), service_.configuration()->GetRealtimeReportingServerUrl(), client_.get(), service_.configuration()->GetRealtimeReportingServerUrl(),
/*add_connector_url_params=*/false, /*include_device_info*/ true, /*add_connector_url_params=*/false,
RealtimeReportingJobConfiguration::UploadCompleteCallback()); RealtimeReportingJobConfiguration::UploadCompleteCallback());
// Add one report to the config. // Add one report to the config.
......
...@@ -31,6 +31,7 @@ EncryptedReportingJobConfiguration::EncryptedReportingJobConfiguration( ...@@ -31,6 +31,7 @@ EncryptedReportingJobConfiguration::EncryptedReportingJobConfiguration(
client->GetURLLoaderFactory(), client->GetURLLoaderFactory(),
client, client,
server_url, server_url,
/*include_device_info*/ true,
std::move(complete_cb)) { std::move(complete_cb)) {
// Merge it into the base class payload. // Merge it into the base class payload.
payload_.MergeDictionary(&merging_payload); payload_.MergeDictionary(&merging_payload);
......
...@@ -101,12 +101,14 @@ class MockCloudPolicyClient : public CloudPolicyClient { ...@@ -101,12 +101,14 @@ class MockCloudPolicyClient : public CloudPolicyClient {
StatusCallback&)); StatusCallback&));
void UploadSecurityEventReport(content::BrowserContext* context, void UploadSecurityEventReport(content::BrowserContext* context,
bool include_device_info,
base::Value value, base::Value value,
StatusCallback callback) override { StatusCallback callback) override {
UploadSecurityEventReport_(context, value, callback); UploadSecurityEventReport_(context, include_device_info, value, callback);
} }
MOCK_METHOD3(UploadSecurityEventReport_, MOCK_METHOD4(UploadSecurityEventReport_,
void(content::BrowserContext* context, void(content::BrowserContext* context,
bool include_device_info,
base::Value&, base::Value&,
StatusCallback&)); StatusCallback&));
......
...@@ -42,12 +42,14 @@ base::Value RealtimeReportingJobConfiguration::BuildReport( ...@@ -42,12 +42,14 @@ base::Value RealtimeReportingJobConfiguration::BuildReport(
RealtimeReportingJobConfiguration::RealtimeReportingJobConfiguration( RealtimeReportingJobConfiguration::RealtimeReportingJobConfiguration(
CloudPolicyClient* client, CloudPolicyClient* client,
const std::string& server_url, const std::string& server_url,
bool include_device_info,
bool add_connector_url_params, bool add_connector_url_params,
UploadCompleteCallback callback) UploadCompleteCallback callback)
: ReportingJobConfigurationBase(TYPE_UPLOAD_REAL_TIME_REPORT, : ReportingJobConfigurationBase(TYPE_UPLOAD_REAL_TIME_REPORT,
client->GetURLLoaderFactory(), client->GetURLLoaderFactory(),
client, client,
server_url, server_url,
include_device_info,
std::move(callback)) { std::move(callback)) {
InitializePayloadInternal(client, add_connector_url_params); InitializePayloadInternal(client, add_connector_url_params);
} }
......
...@@ -46,6 +46,7 @@ class POLICY_EXPORT RealtimeReportingJobConfiguration ...@@ -46,6 +46,7 @@ class POLICY_EXPORT RealtimeReportingJobConfiguration
// parameters will be used. // parameters will be used.
RealtimeReportingJobConfiguration(CloudPolicyClient* client, RealtimeReportingJobConfiguration(CloudPolicyClient* client,
const std::string& server_url, const std::string& server_url,
bool include_device_info,
bool add_connector_url_params, bool add_connector_url_params,
UploadCompleteCallback callback); UploadCompleteCallback callback);
......
...@@ -79,7 +79,7 @@ class RealtimeReportingJobConfigurationTest : public testing::Test { ...@@ -79,7 +79,7 @@ class RealtimeReportingJobConfigurationTest : public testing::Test {
client_.SetDMToken(kDummyToken); client_.SetDMToken(kDummyToken);
configuration_ = std::make_unique<RealtimeReportingJobConfiguration>( configuration_ = std::make_unique<RealtimeReportingJobConfiguration>(
&client_, service_.configuration()->GetRealtimeReportingServerUrl(), &client_, service_.configuration()->GetRealtimeReportingServerUrl(),
/*add_connector_url_params=*/false, /*include_device_info=*/true, /*add_connector_url_params=*/false,
base::BindOnce(&MockCallbackObserver::OnURLLoadComplete, base::BindOnce(&MockCallbackObserver::OnURLLoadComplete,
base::Unretained(&callback_observer_))); base::Unretained(&callback_observer_)));
base::Value context(base::Value::Type::DICTIONARY); base::Value context(base::Value::Type::DICTIONARY);
......
...@@ -112,8 +112,9 @@ const char ...@@ -112,8 +112,9 @@ const char
"chromeVersion"; "chromeVersion";
// static // static
base::Value ReportingJobConfigurationBase::BrowserDictionaryBuilder:: base::Value
BuildBrowserDictionary() { ReportingJobConfigurationBase::BrowserDictionaryBuilder::BuildBrowserDictionary(
bool include_device_info) {
base::Value browser_dictionary{base::Value::Type::DICTIONARY}; base::Value browser_dictionary{base::Value::Type::DICTIONARY};
base::FilePath browser_id; base::FilePath browser_id;
...@@ -121,7 +122,9 @@ base::Value ReportingJobConfigurationBase::BrowserDictionaryBuilder:: ...@@ -121,7 +122,9 @@ base::Value ReportingJobConfigurationBase::BrowserDictionaryBuilder::
browser_dictionary.SetStringKey(kBrowserId, browser_id.value()); browser_dictionary.SetStringKey(kBrowserId, browser_id.value());
} }
browser_dictionary.SetStringKey(kMachineUser, GetOSUsername()); if (include_device_info)
browser_dictionary.SetStringKey(kMachineUser, GetOSUsername());
browser_dictionary.SetStringKey(kChromeVersion, browser_dictionary.SetStringKey(kChromeVersion,
version_info::GetVersionNumber()); version_info::GetVersionNumber());
return browser_dictionary; return browser_dictionary;
...@@ -265,6 +268,7 @@ ReportingJobConfigurationBase::ReportingJobConfigurationBase( ...@@ -265,6 +268,7 @@ ReportingJobConfigurationBase::ReportingJobConfigurationBase(
scoped_refptr<network::SharedURLLoaderFactory> factory, scoped_refptr<network::SharedURLLoaderFactory> factory,
CloudPolicyClient* client, CloudPolicyClient* client,
const std::string& server_url, const std::string& server_url,
bool include_device_info,
UploadCompleteCallback callback) UploadCompleteCallback callback)
: JobConfigurationBase(type, : JobConfigurationBase(type,
DMAuth::FromDMToken(client->dm_token()), DMAuth::FromDMToken(client->dm_token()),
...@@ -274,20 +278,24 @@ ReportingJobConfigurationBase::ReportingJobConfigurationBase( ...@@ -274,20 +278,24 @@ ReportingJobConfigurationBase::ReportingJobConfigurationBase(
callback_(std::move(callback)), callback_(std::move(callback)),
server_url_(server_url) { server_url_(server_url) {
DCHECK(GetAuth().has_dm_token()); DCHECK(GetAuth().has_dm_token());
InitializePayload(client); InitializePayload(client, include_device_info);
} }
ReportingJobConfigurationBase::~ReportingJobConfigurationBase() = default; ReportingJobConfigurationBase::~ReportingJobConfigurationBase() = default;
void ReportingJobConfigurationBase::InitializePayload( void ReportingJobConfigurationBase::InitializePayload(
CloudPolicyClient* client) { CloudPolicyClient* client,
bool include_device_info) {
AddParameter("key", google_apis::GetAPIKey()); AddParameter("key", google_apis::GetAPIKey());
payload_.SetKey(DeviceDictionaryBuilder::kDeviceKey, if (include_device_info) {
DeviceDictionaryBuilder::BuildDeviceDictionary( payload_.SetKey(DeviceDictionaryBuilder::kDeviceKey,
client->dm_token(), client->client_id())); DeviceDictionaryBuilder::BuildDeviceDictionary(
payload_.SetKey(BrowserDictionaryBuilder::kBrowserKey, client->dm_token(), client->client_id()));
BrowserDictionaryBuilder::BuildBrowserDictionary()); }
payload_.SetKey(
BrowserDictionaryBuilder::kBrowserKey,
BrowserDictionaryBuilder::BuildBrowserDictionary(include_device_info));
} }
} // namespace policy } // namespace policy
...@@ -81,7 +81,7 @@ class POLICY_EXPORT ReportingJobConfigurationBase ...@@ -81,7 +81,7 @@ class POLICY_EXPORT ReportingJobConfigurationBase
// Dictionary Key Name // Dictionary Key Name
static const char kBrowserKey[]; static const char kBrowserKey[];
static base::Value BuildBrowserDictionary(); static base::Value BuildBrowserDictionary(bool include_device_info);
static std::string GetBrowserIdPath(); static std::string GetBrowserIdPath();
static std::string GetUserAgentPath(); static std::string GetUserAgentPath();
...@@ -120,6 +120,7 @@ class POLICY_EXPORT ReportingJobConfigurationBase ...@@ -120,6 +120,7 @@ class POLICY_EXPORT ReportingJobConfigurationBase
scoped_refptr<network::SharedURLLoaderFactory> factory, scoped_refptr<network::SharedURLLoaderFactory> factory,
CloudPolicyClient* client, CloudPolicyClient* client,
const std::string& server_url, const std::string& server_url,
bool include_device_info,
UploadCompleteCallback callback); UploadCompleteCallback callback);
~ReportingJobConfigurationBase() override; ~ReportingJobConfigurationBase() override;
...@@ -150,8 +151,10 @@ class POLICY_EXPORT ReportingJobConfigurationBase ...@@ -150,8 +151,10 @@ class POLICY_EXPORT ReportingJobConfigurationBase
UploadCompleteCallback callback_; UploadCompleteCallback callback_;
private: private:
// Initializes request payload. // Initializes request payload. If |include_device_info| is false, the
void InitializePayload(CloudPolicyClient* client); // "device" and "browser.machineUser" fields (see comment at the top of the
// file) are excluded from the payload.
void InitializePayload(CloudPolicyClient* client, bool include_device_info);
const std::string server_url_; const std::string server_url_;
......
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