mirror of
https://github.com/signalapp/libsignal.git
synced 2024-09-20 03:52:17 +02:00
swift: Add an integration test for connecting via proxy
...along with a baseline test for connecting directly. This is only enabled when LIBSIGNAL_TESTING_SIGNAL_PROXY is set in the environment.
This commit is contained in:
parent
01a8c350e8
commit
4854611b30
@ -11,7 +11,7 @@ import Foundation
|
||||
import SignalFfi
|
||||
import XCTest
|
||||
|
||||
final class ChatServiceTests: XCTestCase {
|
||||
final class ChatServiceTests: TestCaseBase {
|
||||
private static let expectedStatus: UInt16 = 200
|
||||
private static let expectedMessage = "OK"
|
||||
private static let expectedContent = "content".data(using: .utf8)
|
||||
@ -104,6 +104,43 @@ final class ChatServiceTests: XCTestCase {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func testConnectUnauth() async throws {
|
||||
// Use the presence of the proxy server environment setting to know whether we should make network requests in our tests.
|
||||
guard ProcessInfo.processInfo.environment["LIBSIGNAL_TESTING_PROXY_SERVER"] != nil else {
|
||||
throw XCTSkip()
|
||||
}
|
||||
|
||||
let net = Net(env: .staging)
|
||||
let chat = net.createChatService(username: "", password: "")
|
||||
// Just make sure we can connect.
|
||||
try await chat.connectUnauthenticated()
|
||||
try await chat.disconnect()
|
||||
}
|
||||
|
||||
func testConnectUnauthThroughProxy() async throws {
|
||||
guard let PROXY_SERVER = ProcessInfo.processInfo.environment["LIBSIGNAL_TESTING_PROXY_SERVER"] else {
|
||||
throw XCTSkip()
|
||||
}
|
||||
|
||||
// The default TLS proxy config doesn't support staging, so we connect to production.
|
||||
let net = Net(env: .production)
|
||||
let host: Substring
|
||||
let port: UInt16
|
||||
if let colonIndex = PROXY_SERVER.firstIndex(of: ":") {
|
||||
host = PROXY_SERVER[..<colonIndex]
|
||||
port = UInt16(PROXY_SERVER[colonIndex...].dropFirst())!
|
||||
} else {
|
||||
host = PROXY_SERVER[...]
|
||||
port = 443
|
||||
}
|
||||
try net.setProxy(host: String(host), port: port)
|
||||
|
||||
let chat = net.createChatService(username: "", password: "")
|
||||
// Just make sure we can connect.
|
||||
try await chat.connectUnauthenticated()
|
||||
try await chat.disconnect()
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user