Commit 1c4c1400 authored by Roger Tawa's avatar Roger Tawa Committed by Commit Bot

Triggered DLP rule is not filled in for sensitive data scan.

With recent changes triggered DLP rule names are added to the reported
events.  This CL is mostly about make sure things are work as expected.
Two changes are made:

1/ Remove extra fields from the reported rules.  The server is quite
   strict and rejects reports if they contain bad or extra fields.
   This CL removes the fields 'id' and 'action' which are not handled.

2/ Rename the "result" field to "eventResult".  This was an error I
   introduced in cl/2288811.

With these changes I have verified that event reports are properly
accepted by the backend.

Bug: 1069109
Change-Id: Ia381da313488eee6f41d71b1ab3928c213003e43
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2308991Reviewed-by: default avatarDominique Fauteux-Chapleau <domfc@chromium.org>
Reviewed-by: default avatarDaniel Rubery <drubery@chromium.org>
Commit-Queue: Roger Tawa <rogerta@chromium.org>
Cr-Commit-Position: refs/heads/master@{#790538}
parent 75ce234e
......@@ -77,22 +77,9 @@ void AddAnalysisConnectorVerdictToEvent(
base::ListValue triggered_rule_info;
for (const auto& trigger : result.triggers) {
base::Value triggered_rule(base::Value::Type::DICTIONARY);
int64_t rule_id;
if (base::StringToInt64(trigger.id, &rule_id)) {
triggered_rule.SetIntKey(
extensions::SafeBrowsingPrivateEventRouter::kKeyTriggeredRuleId,
rule_id);
} else {
triggered_rule.SetIntKey(
extensions::SafeBrowsingPrivateEventRouter::kKeyTriggeredRuleId, 0);
}
triggered_rule.SetStringKey(
extensions::SafeBrowsingPrivateEventRouter::kKeyTriggeredRuleName,
trigger.name);
triggered_rule.SetIntKey(
extensions::SafeBrowsingPrivateEventRouter::kKeyTriggeredRuleAction,
trigger.action);
triggered_rule_info.Append(std::move(triggered_rule));
}
......@@ -133,16 +120,14 @@ const char SafeBrowsingPrivateEventRouter::kKeyReason[] = "reason";
const char SafeBrowsingPrivateEventRouter::kKeyNetErrorCode[] = "netErrorCode";
const char SafeBrowsingPrivateEventRouter::kKeyClickedThrough[] =
"clickedThrough";
const char SafeBrowsingPrivateEventRouter::kKeyTriggeredRuleId[] = "ruleId";
const char SafeBrowsingPrivateEventRouter::kKeyTriggeredRuleName[] = "ruleName";
const char SafeBrowsingPrivateEventRouter::kKeyTriggeredRuleAction[] = "action";
const char SafeBrowsingPrivateEventRouter::kKeyTriggeredRuleInfo[] =
"triggeredRuleInfo";
const char SafeBrowsingPrivateEventRouter::kKeyThreatType[] = "threatType";
const char SafeBrowsingPrivateEventRouter::kKeyContentType[] = "contentType";
const char SafeBrowsingPrivateEventRouter::kKeyContentSize[] = "contentSize";
const char SafeBrowsingPrivateEventRouter::kKeyTrigger[] = "trigger";
const char SafeBrowsingPrivateEventRouter::kKeyEventResult[] = "result";
const char SafeBrowsingPrivateEventRouter::kKeyEventResult[] = "eventResult";
const char SafeBrowsingPrivateEventRouter::kKeyPasswordReuseEvent[] =
"passwordReuseEvent";
......
......@@ -73,9 +73,7 @@ class SafeBrowsingPrivateEventRouter
static const char kKeyReason[];
static const char kKeyNetErrorCode[];
static const char kKeyClickedThrough[];
static const char kKeyTriggeredRuleId[];
static const char kKeyTriggeredRuleName[];
static const char kKeyTriggeredRuleAction[];
static const char kKeyTriggeredRuleInfo[];
static const char kKeyThreatType[];
static const char kKeyContentType[];
......
......@@ -742,10 +742,6 @@ TEST_F(SafeBrowsingPrivateEventRouterTest, TestOnSensitiveDataEvent_Allowed) {
ASSERT_NE(nullptr, triggered_rule_info);
ASSERT_EQ(1u, triggered_rule_info->GetList().size());
base::Value triggered_rule = std::move(triggered_rule_info->GetList()[0]);
EXPECT_EQ(12345, triggered_rule.FindIntKey(
SafeBrowsingPrivateEventRouter::kKeyTriggeredRuleId));
EXPECT_EQ(3, triggered_rule.FindIntKey(
SafeBrowsingPrivateEventRouter::kKeyTriggeredRuleAction));
EXPECT_EQ(
safe_browsing::EventResultToString(safe_browsing::EventResult::ALLOWED),
*event->FindStringKey(SafeBrowsingPrivateEventRouter::kKeyEventResult));
......@@ -796,10 +792,6 @@ TEST_F(SafeBrowsingPrivateEventRouterTest, TestOnSensitiveDataEvent_Blocked) {
ASSERT_NE(nullptr, triggered_rule_info);
ASSERT_EQ(1u, triggered_rule_info->GetList().size());
base::Value triggered_rule = std::move(triggered_rule_info->GetList()[0]);
EXPECT_EQ(12345, triggered_rule.FindIntKey(
SafeBrowsingPrivateEventRouter::kKeyTriggeredRuleId));
EXPECT_EQ(3, triggered_rule.FindIntKey(
SafeBrowsingPrivateEventRouter::kKeyTriggeredRuleAction));
EXPECT_EQ(
safe_browsing::EventResultToString(safe_browsing::EventResult::BLOCKED),
*event->FindStringKey(SafeBrowsingPrivateEventRouter::kKeyEventResult));
......
......@@ -316,14 +316,8 @@ void EventReportValidator::ValidateDlpVerdict(base::Value* value) {
void EventReportValidator::ValidateDlpRule(
base::Value* value,
const ContentAnalysisTrigger& expected_rule) {
ValidateField(value, SafeBrowsingPrivateEventRouter::kKeyTriggeredRuleAction,
base::Optional<int>(expected_rule.action));
ValidateField(value, SafeBrowsingPrivateEventRouter::kKeyTriggeredRuleName,
expected_rule.name);
int64_t rule_id;
ASSERT_TRUE(base::StringToInt64(expected_rule.id, &rule_id));
ValidateField(value, SafeBrowsingPrivateEventRouter::kKeyTriggeredRuleId,
base::Optional<int>(rule_id));
}
void EventReportValidator::ValidateField(
......
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