Signal-iOS/SignalServiceKit/tests/Network/SignalProxyTest.swift
2025-12-30 11:34:05 -08:00

47 lines
1.6 KiB
Swift

//
// Copyright 2022 Signal Messenger, LLC
// SPDX-License-Identifier: AGPL-3.0-only
//
import SignalServiceKit
import XCTest
class SignalProxyTest: XCTestCase {
func testIsValidProxyLink() throws {
let validHrefs: [String] = [
"https://signal.tube/#example.com",
"sgnl://signal.tube/#example.com",
"sgnl://signal.tube/extrapath?extra=query#example.com",
"HTTPS://SIGNAL.TUBE/#EXAMPLE.COM",
]
for href in validHrefs {
let url = URL(string: href)!
XCTAssertTrue(SignalProxy.isValidProxyLink(url), href)
}
let invalidHrefs: [String] = [
// Wrong protocol
"http://signal.tube/#example.com",
// Wrong host
"https://example.net/#example.com",
"https://signal.org/#example.com",
// Extra stuff
"https://user:pass@signal.tube/#example.com",
"https://signal.tube:1234/#example.com",
// Invalid or missing hash
"https://signal.tube",
"https://signal.tube/example.com",
"https://signal.tube/#",
"https://signal.tube/#example",
"https://signal.tube/#example.com.",
"https://signal.tube/#example.com/",
"https://signal.tube/#\(String(repeating: "x", count: 9999)).example.com",
"https://signal.tube/#https://example.com",
]
for href in invalidHrefs {
let url = URL(string: href)!
XCTAssertFalse(SignalProxy.isValidProxyLink(url), href)
}
}
}