Skip to content

Commit

Permalink
Avoid Fireproofing the same website multiple times (#288)
Browse files Browse the repository at this point in the history
* Prevent duplicate Fireproof domains from being added.
* Commit a BSK revision bump.
  • Loading branch information
samsymons authored Oct 29, 2021
1 parent 3e77bd6 commit 53b287d
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
4 changes: 4 additions & 0 deletions DuckDuckGo/Fireproofing/Model/FireproofDomains.swift
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ internal class FireproofDomains {
}

func addToAllowed(domain: String) {
guard !isFireproof(fireproofDomain: domain) else {
return
}

fireproofDomains += [domain]

NotificationCenter.default.post(name: Constants.newFireproofDomainNotification, object: self, userInfo: [
Expand Down
15 changes: 15 additions & 0 deletions Unit Tests/Fireproofing/FireproofDomainsTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,19 @@ final class FireproofDomainsTests: XCTestCase {
XCTAssertTrue(logins.fireproofDomains.isEmpty)
}

func testWhenAddingDuplicateDomainsThenSubsequentDomainsAreIgnored() {
let domain = "example.com"
let logins = FireproofDomains()
logins.addToAllowed(domain: domain)
XCTAssertTrue(logins.isFireproof(fireproofDomain: domain))

logins.addToAllowed(domain: domain)
XCTAssertTrue(logins.isFireproof(fireproofDomain: domain))
XCTAssertEqual(logins.fireproofDomains, [domain])

logins.remove(domain: domain)
XCTAssertFalse(logins.isFireproof(fireproofDomain: domain))
XCTAssertEqual(logins.fireproofDomains, [])
}

}

0 comments on commit 53b287d

Please sign in to comment.