Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement and Enable Redacted Events Manager
Summary: There are certain events that are "sensitive" that violate our terms that are transmitted from 3P clients to Meta. We want to redact these event names from ever being sent from the client-side. In order to do this, we need to retrieve a list of these "redacted" events from the server-side and build the ```RedactedEventsManager``` to process and redact these events. More information can be seen [here](https://docs.google.com/document/d/1EYy0vZ-v6q1QDGEDj_N2is6QbX4eDPodI1lYz6W8GEU/), [here](https://docs.google.com/document/d/1OcrMzjYloBgFmNRgiJ3C_beMtuKxbEr8KII0YWya8Pw/), and [here](https://docs.google.com/document/d/1OhJ-LSX0fl8WJJlbs17ka3wleUQmUDchmdbmfLUXD0w/). This diff implements and enables the ```RedactedEventsManager```. Reviewed By: Nathaaaalie Differential Revision: D51214260 fbshipit-source-id: 7c4111be7aa26acf046b1227d0204f49ccc0fb9f
- Loading branch information
1 parent
75e965e
commit 066eb63
Showing
7 changed files
with
299 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
194 changes: 194 additions & 0 deletions
194
FBSDKCoreKit/FBSDKCoreKitTests/Internal/AppEvents/Integrity/RedactedEventsManagerTests.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,194 @@ | ||
/* | ||
* Copyright (c) Meta Platforms, Inc. and affiliates. | ||
* All rights reserved. | ||
* | ||
* This source code is licensed under the license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
@testable import FBSDKCoreKit | ||
|
||
final class RedactedEventsManagerTests: XCTestCase { | ||
|
||
let serverConfigDict = [ | ||
"protectedModeRules": [ | ||
"redacted_events": [ | ||
[ | ||
"key": "FilteredEvent", | ||
"value": ["test_filtered_event_1", "test_filtered_event_2"], | ||
], | ||
[ | ||
"key": "RedactedEvent", | ||
"value": ["test_redacted_event_1", "test_redacted_event_2"], | ||
], | ||
], | ||
], | ||
] | ||
|
||
lazy var serverConfiguration = ServerConfigurationFixtures.configuration(withDictionary: serverConfigDict) | ||
|
||
// swiftlint:disable implicitly_unwrapped_optional | ||
var provider: TestServerConfigurationProvider! | ||
var redactedEventsManager: RedactedEventsManager! | ||
// swiftlint:enable implicitly_unwrapped_optional | ||
|
||
override func setUp() { | ||
super.setUp() | ||
provider = TestServerConfigurationProvider(configuration: serverConfiguration) | ||
redactedEventsManager = RedactedEventsManager() | ||
redactedEventsManager.configuredDependencies = .init( | ||
serverConfigurationProvider: provider | ||
) | ||
} | ||
|
||
override func tearDown() { | ||
super.tearDown() | ||
redactedEventsManager = nil | ||
provider = nil | ||
} | ||
|
||
private func getTestEvents() -> NSMutableArray { | ||
let event1 = [ | ||
AppEvents.ParameterName.eventName: "test_filtered_event_1", | ||
AppEvents.ParameterName.currency: "USD", | ||
AppEvents.ParameterName.description: "This is a filtered event", | ||
] | ||
let event2 = [ | ||
AppEvents.ParameterName.eventName: "test_filtered_event_2", | ||
AppEvents.ParameterName.currency: "EUR", | ||
AppEvents.ParameterName.description: "This is a filtered event", | ||
] | ||
let event3 = [ | ||
AppEvents.ParameterName.eventName: "test_redacted_event_1", | ||
AppEvents.ParameterName.currency: "FEN", | ||
AppEvents.ParameterName.description: "This is a redacted event", | ||
] | ||
let event4 = [ | ||
AppEvents.ParameterName.eventName: "test_redacted_event_2", | ||
AppEvents.ParameterName.currency: "GBP", | ||
AppEvents.ParameterName.description: "This is a redacted event", | ||
] | ||
let event5 = [ | ||
AppEvents.ParameterName.eventName: "test_non_sensitive_event", | ||
AppEvents.ParameterName.currency: "CAD", | ||
AppEvents.ParameterName.description: "This is a non-sensitive event", | ||
] | ||
let events = NSMutableArray() | ||
events.add(["event": event1, "isImplicit": false]) | ||
events.add(["event": event2, "isImplicit": false]) | ||
events.add(["event": event3, "isImplicit": false]) | ||
events.add(["event": event4, "isImplicit": false]) | ||
events.add(["event": event5, "isImplicit": false]) | ||
return events | ||
} | ||
|
||
func testDefaultDependencies() throws { | ||
redactedEventsManager.resetDependencies() | ||
XCTAssertTrue( | ||
redactedEventsManager.serverConfigurationProvider === _ServerConfigurationManager.shared, | ||
"Should use the shared server configuration manger by default" | ||
) | ||
} | ||
|
||
func testConfiguringDependencies() { | ||
XCTAssertTrue( | ||
redactedEventsManager.serverConfigurationProvider === provider, | ||
"Should be able to create with a server configuration provider" | ||
) | ||
} | ||
|
||
func testProcessEventsNotEnabled() { | ||
let events = getTestEvents() | ||
redactedEventsManager.processEvents(events) | ||
XCTAssertTrue( | ||
events.count == 5, | ||
"redactedEventsManager should not drop any events" | ||
) | ||
guard let eventDict0 = events[0] as? [String: Any], | ||
let event0 = eventDict0["event"] as? [AppEvents.ParameterName: String], | ||
let eventDict1 = events[1] as? [String: Any], | ||
let event1 = eventDict1["event"] as? [AppEvents.ParameterName: String], | ||
let eventDict2 = events[2] as? [String: Any], | ||
let event2 = eventDict2["event"] as? [AppEvents.ParameterName: String], | ||
let eventDict3 = events[3] as? [String: Any], | ||
let event3 = eventDict3["event"] as? [AppEvents.ParameterName: String], | ||
let eventDict4 = events[4] as? [String: Any], | ||
let event4 = eventDict4["event"] as? [AppEvents.ParameterName: String] else { | ||
XCTFail("events has incorrect structure") | ||
return | ||
} | ||
XCTAssertEqual( | ||
event0[AppEvents.ParameterName.eventName], | ||
"test_filtered_event_1", | ||
"Event at index 0 has an incorrect event name" | ||
) | ||
XCTAssertEqual( | ||
event1[AppEvents.ParameterName.eventName], | ||
"test_filtered_event_2", | ||
"Event at index 1 has an incorrect event name" | ||
) | ||
XCTAssertEqual( | ||
event2[AppEvents.ParameterName.eventName], | ||
"test_redacted_event_1", | ||
"Event at index 2 has an incorrect event name" | ||
) | ||
XCTAssertEqual( | ||
event3[AppEvents.ParameterName.eventName], | ||
"test_redacted_event_2", | ||
"Event at index 3 has an incorrect event name" | ||
) | ||
XCTAssertEqual( | ||
event4[AppEvents.ParameterName.eventName], | ||
"test_non_sensitive_event", | ||
"Event at index 4 has an incorrect event name" | ||
) | ||
} | ||
|
||
func testProcessEventsEnabled() { | ||
redactedEventsManager.enable() | ||
let events = getTestEvents() | ||
redactedEventsManager.processEvents(events) | ||
XCTAssertTrue( | ||
events.count == 5, | ||
"redactedEventsManager should not drop any events" | ||
) | ||
guard let eventDict0 = events[0] as? [String: Any], | ||
let event0 = eventDict0["event"] as? [AppEvents.ParameterName: String], | ||
let eventDict1 = events[1] as? [String: Any], | ||
let event1 = eventDict1["event"] as? [AppEvents.ParameterName: String], | ||
let eventDict2 = events[2] as? [String: Any], | ||
let event2 = eventDict2["event"] as? [AppEvents.ParameterName: String], | ||
let eventDict3 = events[3] as? [String: Any], | ||
let event3 = eventDict3["event"] as? [AppEvents.ParameterName: String], | ||
let eventDict4 = events[4] as? [String: Any], | ||
let event4 = eventDict4["event"] as? [AppEvents.ParameterName: String] else { | ||
XCTFail("events has incorrect structure") | ||
return | ||
} | ||
XCTAssertEqual( | ||
event0[AppEvents.ParameterName.eventName], | ||
"FilteredEvent", | ||
"Event at index 0 has an incorrect event name" | ||
) | ||
XCTAssertEqual( | ||
event1[AppEvents.ParameterName.eventName], | ||
"FilteredEvent", | ||
"Event at index 1 has an incorrect event name" | ||
) | ||
XCTAssertEqual( | ||
event2[AppEvents.ParameterName.eventName], | ||
"RedactedEvent", | ||
"Event at index 2 has an incorrect event name" | ||
) | ||
XCTAssertEqual( | ||
event3[AppEvents.ParameterName.eventName], | ||
"RedactedEvent", | ||
"Event at index 3 has an incorrect event name" | ||
) | ||
XCTAssertEqual( | ||
event4[AppEvents.ParameterName.eventName], | ||
"test_non_sensitive_event", | ||
"Event at index 4 has an incorrect event name" | ||
) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters