2026-05-22 14:50:36 +02:00
|
|
|
import XCTest
|
2026-09-20 15:05:19 +02:00
|
|
|
@testable import KeeVaultCore
|
2026-05-22 14:50:36 +02:00
|
|
|
|
|
|
|
|
final class CredentialMatcherTests: XCTestCase {
|
|
|
|
|
func makeEntry(url: String) -> Entry {
|
|
|
|
|
Entry(title: "Test", url: url)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func test_exactURLMatch() {
|
|
|
|
|
let e = makeEntry(url: "https://github.com/login")
|
|
|
|
|
XCTAssertTrue(CredentialMatcher.matches(entry: e, serviceIdentifier: "https://github.com"))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func test_wwwStripped() {
|
|
|
|
|
let e = makeEntry(url: "https://www.github.com")
|
|
|
|
|
XCTAssertTrue(CredentialMatcher.matches(entry: e, serviceIdentifier: "https://github.com"))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func test_subdomainMatch() {
|
|
|
|
|
let e = makeEntry(url: "https://api.github.com")
|
|
|
|
|
XCTAssertTrue(CredentialMatcher.matches(entry: e, serviceIdentifier: "https://github.com"))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func test_differentDomain_noMatch() {
|
|
|
|
|
let e = makeEntry(url: "https://gitlab.com")
|
|
|
|
|
XCTAssertFalse(CredentialMatcher.matches(entry: e, serviceIdentifier: "https://github.com"))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func test_emptyURL_noMatch() {
|
|
|
|
|
let e = makeEntry(url: "")
|
|
|
|
|
XCTAssertFalse(CredentialMatcher.matches(entry: e, serviceIdentifier: "https://github.com"))
|
|
|
|
|
}
|
|
|
|
|
|
2026-09-20 12:39:45 +02:00
|
|
|
func test_bareDomainSubdomainMatch() {
|
|
|
|
|
let e = makeEntry(url: "allocine.fr")
|
|
|
|
|
XCTAssertTrue(CredentialMatcher.matches(entry: e, serviceIdentifier: "mon.allocine.fr"))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func test_bareDomainExactMatch() {
|
|
|
|
|
let e = makeEntry(url: "allocine.fr")
|
|
|
|
|
XCTAssertTrue(CredentialMatcher.matches(entry: e, serviceIdentifier: "allocine.fr"))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func test_bareDomainDifferentDomain_noMatch() {
|
|
|
|
|
let e = makeEntry(url: "allocine.fr")
|
|
|
|
|
XCTAssertFalse(CredentialMatcher.matches(entry: e, serviceIdentifier: "notallocine.fr"))
|
|
|
|
|
}
|
|
|
|
|
|
2026-05-22 14:50:36 +02:00
|
|
|
func test_filter_suggestedAndRest() {
|
|
|
|
|
let entries = [
|
|
|
|
|
makeEntry(url: "https://github.com"),
|
|
|
|
|
makeEntry(url: "https://gitlab.com"),
|
|
|
|
|
makeEntry(url: ""),
|
|
|
|
|
]
|
|
|
|
|
let result = CredentialMatcher.filter(entries: entries, for: ["https://github.com"])
|
|
|
|
|
XCTAssertEqual(result.suggested.count, 1)
|
|
|
|
|
XCTAssertEqual(result.suggested[0].url, "https://github.com")
|
|
|
|
|
XCTAssertEqual(result.all.count, 2)
|
|
|
|
|
}
|
|
|
|
|
}
|