Skip to content

Commit

Permalink
Fix PR issues
Browse files Browse the repository at this point in the history
  • Loading branch information
alessandroboron committed Jan 31, 2025
1 parent 40910c9 commit 0e76b07
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
3 changes: 2 additions & 1 deletion Sources/MaliciousSiteProtection/MaliciousSiteDetector.swift
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,9 @@ public final class MaliciousSiteDetector: MaliciousSiteDetecting {

private func fireErrorPageShown(threatKind: ThreatKind, clientSideHit: Bool) async {
let filterSet = await dataManager.dataSet(for: .filterSet(threatKind: threatKind))
// Send Pixel clientSideHit parameter only if filterSet size is greater than 100
// https://app.asana.com/0/0/1209113403594297/1209141231997704/f
let sanitisedClientSideHit = filterSet.filters.count < 100 ? clientSideHit : nil
let sanitisedClientSideHit = filterSet.filters.count > 100 ? clientSideHit : nil
eventMapping.fire(.errorPageShown(category: threatKind, clientSideHit: sanitisedClientSideHit))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -172,13 +172,13 @@ class MaliciousSiteDetectorTests: XCTestCase {
XCTAssertEqual(mockEventMapping.events.count, 1)
switch mockEventMapping.events.last {
case let .errorPageShown(_, clientSideHit):
XCTAssertTrue(clientSideHit == true)
XCTAssertNil(clientSideHit)
default:
XCTFail("Wrong event fired")
}
}

func testWhenLocalFilterHitAndFilterSetGreaterThanHundredThenClientSideHitParameterIsNil() async throws {
func testWhenLocalFilterHitAndFilterSetGreaterThanHundredThenClientSideHitParameterIsSent() async throws {
// GIVEN
let maliciousFilter = Filter(hash: "255a8a793097aeea1f06a19c08cde28db0eb34c660c6e4e7480c9525d034b16d", regex: ".*malicious.*")
let filters = (1...100).map { i in
Expand All @@ -195,7 +195,7 @@ class MaliciousSiteDetectorTests: XCTestCase {
XCTAssertEqual(mockEventMapping.events.count, 1)
switch mockEventMapping.events.last {
case let .errorPageShown(_, clientSideHit):
XCTAssertNil(clientSideHit)
XCTAssertNotNil(clientSideHit)
default:
XCTFail("Wrong event fired")
}
Expand All @@ -207,19 +207,19 @@ class MaliciousSiteDetectorTests: XCTestCase {
let url = URL(string: "https://example.com/mal")!

// WHEN
let _ = await detector.evaluate(url)
_ = await detector.evaluate(url)

// THEN
XCTAssertEqual(mockEventMapping.events.count, 1)
switch mockEventMapping.events.last {
case let .errorPageShown(_, clientSideHit):
XCTAssertTrue(clientSideHit == false)
XCTAssertNil(clientSideHit)
default:
XCTFail("Wrong event fired")
}
}

func testWhenMatchesAPIAndFilterSetGreaterThanHundredThenClientSideHitParameterIsNil() async throws {
func testWhenMatchesAPIAndFilterSetGreaterThanHundredThenClientSideHitParameterIsSet() async throws {
// GIVEN
let maliciousFilter = Filter(hash: "255a8a793097aeea1f06a19c08cde28db0eb34c660c6e4e7480c9525d034b16d", regex: ".*malicious.*")
let filters = (1...100).map { i in
Expand All @@ -230,13 +230,13 @@ class MaliciousSiteDetectorTests: XCTestCase {
let url = URL(string: "https://example.com/mal")!

// WHEN
let _ = await detector.evaluate(url)
_ = await detector.evaluate(url)

// THEN
XCTAssertEqual(mockEventMapping.events.count, 1)
switch mockEventMapping.events.last {
case let .errorPageShown(_, clientSideHit):
XCTAssertNil(clientSideHit)
XCTAssertNotNil(clientSideHit)
default:
XCTFail("Wrong event fired")
}
Expand Down

0 comments on commit 0e76b07

Please sign in to comment.