Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit6426c00

Browse files
karwaLukasa
andauthored
[Tests] Add some basic IPv6 tests (#483)
Co-authored-by: Cory Benfield <lukasa@apple.com>
1 parent0ed00b8 commit6426c00

File tree

3 files changed

+52
-0
lines changed

3 files changed

+52
-0
lines changed

‎Tests/AsyncHTTPClientTests/HTTPClientTestUtils.swift‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import Foundation
1717
import Logging
1818
import NIOConcurrencyHelpers
1919
import NIOCore
20+
import NIOEmbedded
2021
import NIOHPACK
2122
import NIOHTTP1
2223
import NIOHTTP2
@@ -46,6 +47,18 @@ func getDefaultEventLoopGroup(numberOfThreads: Int) -> EventLoopGroup {
4647
returnMultiThreadedEventLoopGroup(numberOfThreads: numberOfThreads)
4748
}
4849

50+
letcanBindIPv6Loopback:Bool={
51+
letelg=MultiThreadedEventLoopGroup(numberOfThreads:1)
52+
defer{try! elg.syncShutdownGracefully()}
53+
letserverChannel=try?ServerBootstrap(group: elg)
54+
.serverChannelOption(ChannelOptions.socket(SocketOptionLevel(SOL_SOCKET), SO_REUSEADDR), value:1)
55+
.bind(host:"::1", port:0)
56+
.wait()
57+
letdidBind=(serverChannel!=nil)
58+
try! serverChannel?.close().wait()
59+
return didBind
60+
}()
61+
4962
classTestHTTPDelegate:HTTPClientResponseDelegate{
5063
typealiasResponse=Void
5164

@@ -266,6 +279,7 @@ internal final class HTTPBin<RequestHandler: ChannelInboundHandler> where
266279
enumBindTarget{
267280
case unixDomainSocket(String)
268281
case localhostIPv4RandomPort
282+
case localhostIPv6RandomPort
269283
}
270284

271285
enumMode{
@@ -331,6 +345,8 @@ internal final class HTTPBin<RequestHandler: ChannelInboundHandler> where
331345
switch bindTarget{
332346
case.localhostIPv4RandomPort:
333347
socketAddress=try!SocketAddress(ipAddress:"127.0.0.1", port:0)
348+
case.localhostIPv6RandomPort:
349+
socketAddress=try!SocketAddress(ipAddress:"::1", port:0)
334350
case.unixDomainSocket(let path):
335351
socketAddress=try!SocketAddress(unixDomainSocketPath: path)
336352
}

‎Tests/AsyncHTTPClientTests/HTTPClientTests+XCTest.swift‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ extension HTTPClientTests {
3838
("testGetHttps", testGetHttps),
3939
("testGetHttpsWithIP", testGetHttpsWithIP),
4040
("testGetHTTPSWorksOnMTELGWithIP", testGetHTTPSWorksOnMTELGWithIP),
41+
("testGetHttpsWithIPv6", testGetHttpsWithIPv6),
42+
("testGetHTTPSWorksOnMTELGWithIPv6", testGetHTTPSWorksOnMTELGWithIPv6),
4143
("testPostHttps", testPostHttps),
4244
("testHttpRedirect", testHttpRedirect),
4345
("testHttpHostRedirect", testHttpHostRedirect),

‎Tests/AsyncHTTPClientTests/HTTPClientTests.swift‎

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -333,6 +333,40 @@ class HTTPClientTests: XCTestCase {
333333
XCTAssertEqual(.ok, response.status)
334334
}
335335

336+
func testGetHttpsWithIPv6()throws{
337+
tryXCTSkipUnless(canBindIPv6Loopback,"Requires IPv6")
338+
letlocalHTTPBin=HTTPBin(.http1_1(ssl:true), bindTarget:.localhostIPv6RandomPort)
339+
letlocalClient=HTTPClient(eventLoopGroupProvider:.shared(self.clientGroup),
340+
configuration:HTTPClient.Configuration(certificateVerification:.none))
341+
defer{
342+
XCTAssertNoThrow(try localClient.syncShutdown())
343+
XCTAssertNoThrow(try localHTTPBin.shutdown())
344+
}
345+
varresponse:HTTPClient.Response?
346+
XCTAssertNoThrow(response=try localClient.get(url:"https://[::1]:\(localHTTPBin.port)/get").wait())
347+
XCTAssertEqual(.ok, response?.status)
348+
}
349+
350+
func testGetHTTPSWorksOnMTELGWithIPv6()throws{
351+
tryXCTSkipUnless(canBindIPv6Loopback,"Requires IPv6")
352+
// Same test as above but this one will use NIO on Sockets even on Apple platforms, just to make sure
353+
// this works.
354+
letgroup=MultiThreadedEventLoopGroup(numberOfThreads:1)
355+
defer{
356+
XCTAssertNoThrow(try group.syncShutdownGracefully())
357+
}
358+
letlocalHTTPBin=HTTPBin(.http1_1(ssl:true), bindTarget:.localhostIPv6RandomPort)
359+
letlocalClient=HTTPClient(eventLoopGroupProvider:.shared(group),
360+
configuration:HTTPClient.Configuration(certificateVerification:.none))
361+
defer{
362+
XCTAssertNoThrow(try localClient.syncShutdown())
363+
XCTAssertNoThrow(try localHTTPBin.shutdown())
364+
}
365+
varresponse:HTTPClient.Response?
366+
XCTAssertNoThrow(response=try localClient.get(url:"https://[::1]:\(localHTTPBin.port)/get").wait())
367+
XCTAssertEqual(.ok, response?.status)
368+
}
369+
336370
func testPostHttps()throws{
337371
letlocalHTTPBin=HTTPBin(.http1_1(ssl:true))
338372
letlocalClient=HTTPClient(eventLoopGroupProvider:.shared(self.clientGroup),

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp