Skip to content

Commit

Permalink
Fix #5968: remove use of googlemapping.json and Disconnect cat., upda…
Browse files Browse the repository at this point in the history
…te shavar (#6664)

* Fix #5968: remove use of googlemapping.json and Disconnect cat., update shavar

* update tests
  • Loading branch information
garvankeeley committed May 21, 2020
1 parent cbd78d2 commit 488cf01
Show file tree
Hide file tree
Showing 5 changed files with 5 additions and 34 deletions.
2 changes: 1 addition & 1 deletion Cartfile.resolved
Expand Up @@ -14,7 +14,7 @@ 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" "1f282be9bc7bf86cf4d695e2a63dbcdf2eecfb89"
github "mozilla/application-services" "v0.59.0"
github "mozilla/glean" "v29.0.0"
github "swisspol/GCDWebServer" "3.5.3"
2 changes: 1 addition & 1 deletion ClientTests/TPStatsBlocklistsTests.swift
Expand Up @@ -62,7 +62,7 @@ class TPStatsBlocklistsTests: XCTestCase {
XCTAssertEqual(blocklist("https://subadmeld.com"), nil)
XCTAssertEqual(blocklist("https://aol.com.aolanswers.com", "https://foo.com", ["ers.com"]), nil)
XCTAssertEqual(blocklist("https://sub.xiti.com/track"), .analytics)
XCTAssertEqual(blocklist("https://atlassolutions.com"), .social)
XCTAssertEqual(blocklist("https://atlassolutions.com"), .advertising)
XCTAssertEqual(blocklist("https://atlassolutions.com", "https://foo.com", ["*solutions.com"]), nil)
}
}
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
Expand Up @@ -21,10 +21,8 @@ public enum CategoryTitle: String, CaseIterable {

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 +81,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
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 488cf01

Please sign in to comment.