Skip to content

Commit c4e9fdf

Browse files
Added tests for http+unix and https+unix url schemes
Motivation: Using a base URL as the socket path only works when the URL object is maintained as long as possible through the stack. Additionally, it doesn't currently provide a way to use TLS over UNIX sockets. Modifications: Added two tests to test out the to-be supported URL schemes, http+unix, and https+unix, which encode the socket path as a %-escaped hostname, as some existing services already do. Result: Some failing tests.
1 parent 070c1e5 commit c4e9fdf

File tree

2 files changed

+39
-0
lines changed

2 files changed

+39
-0
lines changed

Diff for: Tests/AsyncHTTPClientTests/HTTPClientTests+XCTest.swift

+2
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,8 @@ extension HTTPClientTests {
9090
("testMakeSecondRequestWhilstFirstIsOngoing", testMakeSecondRequestWhilstFirstIsOngoing),
9191
("testUDSBasic", testUDSBasic),
9292
("testUDSSocketAndPath", testUDSSocketAndPath),
93+
("testHTTPPlusUNIX", testHTTPPlusUNIX),
94+
("testHTTPSPlusUNIX", testHTTPSPlusUNIX),
9395
("testUseExistingConnectionOnDifferentEL", testUseExistingConnectionOnDifferentEL),
9496
("testWeRecoverFromServerThatClosesTheConnectionOnUs", testWeRecoverFromServerThatClosesTheConnectionOnUs),
9597
("testPoolClosesIdleConnections", testPoolClosesIdleConnections),

Diff for: Tests/AsyncHTTPClientTests/HTTPClientTests.swift

+37
Original file line numberDiff line numberDiff line change
@@ -1325,6 +1325,43 @@ class HTTPClientTests: XCTestCase {
13251325
})
13261326
}
13271327

1328+
func testHTTPPlusUNIX() {
1329+
// Here, we're testing a URL where the UNIX domain socket is encoded as the host name
1330+
XCTAssertNoThrow(try TemporaryFileHelpers.withTemporaryUnixDomainSocketPathName { path in
1331+
let localHTTPBin = HTTPBin(bindTarget: .unixDomainSocket(path))
1332+
defer {
1333+
XCTAssertNoThrow(try localHTTPBin.shutdown())
1334+
}
1335+
guard let target = URL(string: "http+unix://\(path.addingPercentEncoding(withAllowedCharacters: .urlHostAllowed)!)/echo-uri"),
1336+
let request = try? Request(url: target) else {
1337+
XCTFail("couldn't build URL for request")
1338+
return
1339+
}
1340+
XCTAssertNoThrow(XCTAssertEqual(["/echo-uri"[...]],
1341+
try self.defaultClient.execute(request: request).wait().headers[canonicalForm: "X-Calling-URI"]))
1342+
})
1343+
}
1344+
1345+
func testHTTPSPlusUNIX() {
1346+
// Here, we're testing a URL where the UNIX domain socket is encoded as the host name
1347+
XCTAssertNoThrow(try TemporaryFileHelpers.withTemporaryUnixDomainSocketPathName { path in
1348+
let localHTTPBin = HTTPBin(ssl: true, bindTarget: .unixDomainSocket(path))
1349+
let localClient = HTTPClient(eventLoopGroupProvider: .shared(self.clientGroup),
1350+
configuration: HTTPClient.Configuration(certificateVerification: .none))
1351+
defer {
1352+
XCTAssertNoThrow(try localClient.syncShutdown())
1353+
XCTAssertNoThrow(try localHTTPBin.shutdown())
1354+
}
1355+
guard let target = URL(string: "https+unix://\(path.addingPercentEncoding(withAllowedCharacters: .urlHostAllowed)!)/echo-uri"),
1356+
let request = try? Request(url: target) else {
1357+
XCTFail("couldn't build URL for request")
1358+
return
1359+
}
1360+
XCTAssertNoThrow(XCTAssertEqual(["/echo-uri"[...]],
1361+
try localClient.execute(request: request).wait().headers[canonicalForm: "X-Calling-URI"]))
1362+
})
1363+
}
1364+
13281365
func testUseExistingConnectionOnDifferentEL() throws {
13291366
let threadCount = 16
13301367
let elg = getDefaultEventLoopGroup(numberOfThreads: threadCount)

0 commit comments

Comments
 (0)