Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Failing Tests, Address Client Connection Issue #155

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
12 changes: 6 additions & 6 deletions Package.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// swift-tools-version:5.7
// swift-tools-version:5.9
import PackageDescription

let package = Package(
Expand All @@ -13,11 +13,11 @@ let package = Package(
.library(name: "WebSocketKit", targets: ["WebSocketKit"]),
],
dependencies: [
.package(url: "https://github.com/apple/swift-nio.git", from: "2.53.0"),
.package(url: "https://github.com/apple/swift-nio-extras.git", from: "1.16.0"),
.package(url: "https://github.com/apple/swift-nio-ssl.git", from: "2.24.0"),
.package(url: "https://github.com/apple/swift-nio-transport-services.git", from: "1.16.0"),
.package(url: "https://github.com/apple/swift-atomics.git", from: "1.1.0"),
.package(url: "https://github.com/apple/swift-nio.git", from: "2.76.1"),
.package(url: "https://github.com/apple/swift-nio-extras.git", from: "1.24.1"),
.package(url: "https://github.com/apple/swift-nio-ssl.git", from: "2.29.0"),
.package(url: "https://github.com/apple/swift-nio-transport-services.git", from: "1.23.0"),
.package(url: "https://github.com/apple/swift-atomics.git", from: "1.2.0"),
],
targets: [
.target(name: "WebSocketKit", dependencies: [
Expand Down
5 changes: 3 additions & 2 deletions Tests/WebSocketKitTests/AsyncWebSocketKitTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,10 @@ final class AsyncWebSocketKitTests: XCTestCase {
try await server.close(mode: .all)
}

func testBadURLInWebsocketConnect() async throws {
func testBadURLSchemeInWebsocketConnect() async throws {

do {
try await WebSocket.connect(to: "%w", on: self.elg, onUpgrade: { _ async in })
try await WebSocket.connect(to: "w`:", on: self.elg, onUpgrade: { _ async in })
XCTAssertThrowsError({}())
} catch {
XCTAssertThrowsError(try { throw error }()) {
Expand Down
7 changes: 4 additions & 3 deletions Tests/WebSocketKitTests/SSLTestHelpers.swift
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,13 @@ func generateRSAPrivateKey() -> OpaquePointer {

CNIOBoringSSL_BN_set_u64(exponent, 0x10001)

let rsa = CNIOBoringSSL_RSA_new()!
let rsa = CNIOBoringSSL_RSA_new()
let generateRC = CNIOBoringSSL_RSA_generate_key_ex(rsa, CInt(2048), exponent, nil)
precondition(generateRC == 1)

let pkey = CNIOBoringSSL_EVP_PKEY_new()!
let assignRC = CNIOBoringSSL_EVP_PKEY_assign(pkey, EVP_PKEY_RSA, rsa)
let p = UnsafeMutableRawPointer(rsa)
let assignRC = CNIOBoringSSL_EVP_PKEY_assign(pkey, EVP_PKEY_RSA, p)

precondition(assignRC == 1)
return pkey
Expand Down Expand Up @@ -125,7 +126,7 @@ func generateSelfSignedCert(keygenFunction: () -> OpaquePointer = generateRSAPri
NID_commonName,
MBSTRING_UTF8,
UnsafeMutablePointer(mutating: pointer),
CInt(commonName.lengthOfBytes(using: .utf8)),
ossl_ssize_t(CInt(commonName.lengthOfBytes(using: .utf8))),
-1,
0)
}
Expand Down
5 changes: 3 additions & 2 deletions Tests/WebSocketKitTests/WebSocketKitTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -478,8 +478,9 @@ final class WebSocketKitTests: XCTestCase {
try server.close(mode: .all).wait()
}

func testBadURLInWebsocketConnect() async throws {
XCTAssertThrowsError(try WebSocket.connect(to: "%w", on: self.elg, onUpgrade: { _ in }).wait()) {
func testBadURLSchemeInWebsocketConnect() throws {

XCTAssertThrowsError(try WebSocket.connect(to: "w`:", on: self.elg, onUpgrade: { _ in }).wait()) {
guard case .invalidURL = $0 as? WebSocketClient.Error else {
return XCTFail("Expected .invalidURL but got \(String(reflecting: $0))")
}
Expand Down