2026-06-13 08:43:32 -07:00
|
|
|
import XCTest
|
|
|
|
|
@testable import NetworkCityCore
|
|
|
|
|
|
|
|
|
|
final class IPRangesTests: XCTestCase {
|
|
|
|
|
|
|
|
|
|
func testAppleEightSlashEight() {
|
|
|
|
|
XCTAssertEqual(IPRanges.match("17.248.242.19")?.key, "apple")
|
|
|
|
|
XCTAssertEqual(IPRanges.match("17.42.251.69")?.name, "Apple")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func testTelegram() {
|
|
|
|
|
XCTAssertEqual(IPRanges.match("149.154.175.54")?.key, "telegram")
|
|
|
|
|
}
|
|
|
|
|
|
2026-06-14 10:46:53 -07:00
|
|
|
func testOneDriveNoPTRRangesCollapseToMicrosoft() {
|
|
|
|
|
// Real OneDrive front-end IPs (no PTR) that used to fragment per-IP.
|
|
|
|
|
XCTAssertEqual(IPRanges.match("13.107.137.11")?.key, "microsoft")
|
|
|
|
|
XCTAssertEqual(IPRanges.match("150.171.22.11")?.name, "Microsoft")
|
|
|
|
|
XCTAssertEqual(IPRanges.match("52.108.1.1")?.key, "microsoft")
|
|
|
|
|
XCTAssertEqual(IPRanges.match("40.96.0.1")?.key, "microsoft")
|
|
|
|
|
}
|
|
|
|
|
|
2026-06-13 08:43:32 -07:00
|
|
|
func testPrivateRangesAreLocalNetwork() {
|
|
|
|
|
XCTAssertEqual(IPRanges.match("192.168.0.1")?.name, "Local Network")
|
|
|
|
|
XCTAssertEqual(IPRanges.match("10.1.2.3")?.key, "lan")
|
|
|
|
|
XCTAssertEqual(IPRanges.match("172.20.0.5")?.key, "lan")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func testUnknownIPReturnsNil() {
|
|
|
|
|
XCTAssertNil(IPRanges.match("8.8.8.8"))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func testInvalidIPReturnsNil() {
|
|
|
|
|
XCTAssertNil(IPRanges.match("not.an.ip"))
|
|
|
|
|
XCTAssertNil(IPRanges.match("999.1.1.1"))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func testClassifyUsesRangeFallbackWhenNoPTR() {
|
|
|
|
|
// Apple publishes no PTR for 17/8, so the range table must catch it.
|
|
|
|
|
let org = OrgClassifier.classify(ip: "17.248.242.19", ptr: nil)
|
|
|
|
|
XCTAssertEqual(org.key, "apple")
|
|
|
|
|
XCTAssertEqual(org.name, "Apple")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func testPTRStillWinsOverRange() {
|
|
|
|
|
// A real registrable domain in the PTR should take precedence.
|
|
|
|
|
let org = OrgClassifier.classify(ip: "17.248.242.19", ptr: "host.example.com")
|
|
|
|
|
XCTAssertEqual(org.key, "example.com")
|
|
|
|
|
}
|
|
|
|
|
}
|