mirror of
https://github.com/swift-server/async-http-client.git
synced 2026-06-02 07:37:34 +00:00
c621142327
Migrate CI to use GitHub Actions. ### Motivation: To migrate to GitHub actions and centralised infrastructure. ### Modifications: Changes of note: * Adopt swift-format using rules from SwiftNIO. * Remove scripts and docker files which are no longer needed. * Disabled warnings-as-errors on Swift 6.0 CI pipelines for now. ### Result: Feature parity with old CI.
104 lines
3.3 KiB
Swift
104 lines
3.3 KiB
Swift
//===----------------------------------------------------------------------===//
|
|
//
|
|
// This source file is part of the AsyncHTTPClient open source project
|
|
//
|
|
// Copyright (c) 2021 Apple Inc. and the AsyncHTTPClient project authors
|
|
// Licensed under Apache License v2.0
|
|
//
|
|
// See LICENSE.txt for license information
|
|
// See CONTRIBUTORS.txt for the list of AsyncHTTPClient project authors
|
|
//
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
import NIOCore
|
|
import NIOPosix
|
|
import NIOSSL
|
|
import XCTest
|
|
|
|
@testable import AsyncHTTPClient
|
|
|
|
final class SSLContextCacheTests: XCTestCase {
|
|
func testRequestingSSLContextWorks() {
|
|
let group = MultiThreadedEventLoopGroup(numberOfThreads: 1)
|
|
let eventLoop = group.next()
|
|
let cache = SSLContextCache()
|
|
defer {
|
|
XCTAssertNoThrow(try group.syncShutdownGracefully())
|
|
}
|
|
|
|
XCTAssertNoThrow(
|
|
try cache.sslContext(
|
|
tlsConfiguration: .makeClientConfiguration(),
|
|
eventLoop: eventLoop,
|
|
logger: HTTPClient.loggingDisabled
|
|
).wait()
|
|
)
|
|
}
|
|
|
|
func testCacheWorks() {
|
|
let group = MultiThreadedEventLoopGroup(numberOfThreads: 1)
|
|
let eventLoop = group.next()
|
|
let cache = SSLContextCache()
|
|
defer {
|
|
XCTAssertNoThrow(try group.syncShutdownGracefully())
|
|
}
|
|
|
|
var firstContext: NIOSSLContext?
|
|
var secondContext: NIOSSLContext?
|
|
|
|
XCTAssertNoThrow(
|
|
firstContext = try cache.sslContext(
|
|
tlsConfiguration: .makeClientConfiguration(),
|
|
eventLoop: eventLoop,
|
|
logger: HTTPClient.loggingDisabled
|
|
).wait()
|
|
)
|
|
XCTAssertNoThrow(
|
|
secondContext = try cache.sslContext(
|
|
tlsConfiguration: .makeClientConfiguration(),
|
|
eventLoop: eventLoop,
|
|
logger: HTTPClient.loggingDisabled
|
|
).wait()
|
|
)
|
|
XCTAssertNotNil(firstContext)
|
|
XCTAssertNotNil(secondContext)
|
|
XCTAssert(firstContext === secondContext)
|
|
}
|
|
|
|
func testCacheDoesNotReturnWrongEntry() {
|
|
let group = MultiThreadedEventLoopGroup(numberOfThreads: 1)
|
|
let eventLoop = group.next()
|
|
let cache = SSLContextCache()
|
|
defer {
|
|
XCTAssertNoThrow(try group.syncShutdownGracefully())
|
|
}
|
|
|
|
var firstContext: NIOSSLContext?
|
|
var secondContext: NIOSSLContext?
|
|
|
|
XCTAssertNoThrow(
|
|
firstContext = try cache.sslContext(
|
|
tlsConfiguration: .makeClientConfiguration(),
|
|
eventLoop: eventLoop,
|
|
logger: HTTPClient.loggingDisabled
|
|
).wait()
|
|
)
|
|
|
|
// Second one has a _different_ TLSConfiguration.
|
|
var testTLSConfig = TLSConfiguration.makeClientConfiguration()
|
|
testTLSConfig.certificateVerification = .none
|
|
XCTAssertNoThrow(
|
|
secondContext = try cache.sslContext(
|
|
tlsConfiguration: testTLSConfig,
|
|
eventLoop: eventLoop,
|
|
logger: HTTPClient.loggingDisabled
|
|
).wait()
|
|
)
|
|
XCTAssertNotNil(firstContext)
|
|
XCTAssertNotNil(secondContext)
|
|
XCTAssert(firstContext !== secondContext)
|
|
}
|
|
}
|