Skip to content

Commit

Permalink
Fix mozilla-mobile#5968: content blocker: remove use of google-mappin…
Browse files Browse the repository at this point in the history
…g and Disconnect category
  • Loading branch information
garvankeeley committed Apr 15, 2020
1 parent fcac764 commit dda41ed
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 34 deletions.
2 changes: 1 addition & 1 deletion Cartfile.resolved
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ github "jrendel/SwiftKeychainWrapper" "3.4.0"
github "kif-framework/KIF" "v3.7.8"
github "mozilla-mobile/MappaMundi" "1d17845e4bd6077d790aca5a2b4a468f19567934"
github "mozilla-mobile/telemetry-ios" "v1.1.2"
github "mozilla-services/shavar-prod-lists" "c938da47c4880a48ac40d535caff74dac1d4d77b"
github "mozilla-services/shavar-prod-lists" "fb605541ae6122aeeb7fc234b18cab69027a5015"
github "mozilla/application-services" "v0.57.0"
github "swisspol/GCDWebServer" "3.5.3"
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ let execIsFromCorrectDir = fm.fileExists(atPath: fm.currentDirectoryPath + "/Pac
let rootdir = execIsFromCorrectDir ? fm.currentDirectoryPath : fallbackPath
let blacklist = "\(rootdir)/../../Carthage/Checkouts/shavar-prod-lists/disconnect-blacklist.json"
let entityList = "\(rootdir)/../../Carthage/Checkouts/shavar-prod-lists/disconnect-entitylist.json"
let googleMappingList = "\(rootdir)/../../Carthage/Checkouts/shavar-prod-lists/google_mapping.json"
let fingerprintingList = "\(rootdir)/../../Carthage/Checkouts/shavar-prod-lists/normalized-lists/base-fingerprinting-track.json"

func jsonFrom(filename: String) -> [String: Any] {
Expand All @@ -21,7 +20,7 @@ func jsonFrom(filename: String) -> [String: Any] {
return try! JSONSerialization.jsonObject(with: data, options: []) as! [String: Any]
}

let gen = ContentBlockerGenLib(entityListJson: jsonFrom(filename: entityList), googleMappingJson: jsonFrom(filename: googleMappingList))
let gen = ContentBlockerGenLib(entityListJson: jsonFrom(filename: entityList))

// Remove and create the output dir
let outputDir = URL(fileURLWithPath: "\(rootdir)/../Lists")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,14 @@ public enum CategoryTitle: String, CaseIterable {
case Analytics
case Social
// case Fingerprinting // not used, we have special fingerprinting list instead
case Disconnect
case Cryptomining
case Content
}

public class ContentBlockerGenLib {
var companyToRelatedDomains = [String: [String]]()
let googleMappingJson: [String: Any]

public init(entityListJson: [String: Any], googleMappingJson: [String: Any]) {
self.googleMappingJson = googleMappingJson["categories"]! as! [String: Any]
public init(entityListJson: [String: Any]) {
parseEntityList(json: entityListJson)
}

Expand Down Expand Up @@ -83,25 +80,6 @@ public class ContentBlockerGenLib {
result += handleCategoryItem($0, action: action)
}

// Special handling for Social, pull in lists from Disconnect category
if categoryTitle == .Social {
let category = categories[CategoryTitle.Disconnect.rawValue] as! [Any]
category.forEach {
let item = $0 as! [String: Any]
let companyName = item.first!.key
if ["Facebook", "Twitter"].contains(companyName) {
result += handleCategoryItem($0, action: action)
}
}
}

// Google properties exist in a special list that gets appended per-category
if let cat = googleMappingJson[categoryTitle.rawValue] as? [Any] {
cat.forEach {
result += handleCategoryItem($0, action: action)
}
}

return result
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,11 @@ let entitylist = """
}
"""

let googlemapping = """
{ "categories": {
"Analytics": [{"Google": {"http://www.google.com/": ["google-analytics.com", "postrank.com"]}}]
}}
"""

final class ContentBlockerGenTests: XCTestCase {
func testParsing() throws {
let entityJson = try! JSONSerialization.jsonObject(with: entitylist.data(using: .utf8)!, options: []) as! [String: Any]
let googleJson = try! JSONSerialization.jsonObject(with: googlemapping.data(using: .utf8)!, options: []) as! [String: Any]

let contentBlocker = ContentBlockerGenLib(entityListJson: entityJson, googleMappingJson: googleJson)
let contentBlocker = ContentBlockerGenLib(entityListJson: entityJson)

let json = try! JSONSerialization.jsonObject(with: blacklist.data(using: .utf8)!, options: []) as! [String: Any]
let categories = json["categories"]! as! [String: Any]
Expand Down

0 comments on commit dda41ed

Please sign in to comment.