From 85e8af36bb2b4f1aaf73afa864d24c205fd07b4c Mon Sep 17 00:00:00 2001 From: "Jimmy W. Hough Jr" Date: Fri, 22 Nov 2024 07:17:49 -0600 Subject: [PATCH 1/8] updated to swift tools version 5.9 and fixed a test --- Package.swift | 2 +- Tests/WebSocketKitTests/AsyncWebSocketKitTests.swift | 12 +++++++++++- Tests/WebSocketKitTests/SSLTestHelpers.swift | 7 ++++--- 3 files changed, 16 insertions(+), 5 deletions(-) diff --git a/Package.swift b/Package.swift index 0c2cb084..c2bc7c9b 100644 --- a/Package.swift +++ b/Package.swift @@ -1,4 +1,4 @@ -// swift-tools-version:5.7 +// swift-tools-version:5.9 import PackageDescription let package = Package( diff --git a/Tests/WebSocketKitTests/AsyncWebSocketKitTests.swift b/Tests/WebSocketKitTests/AsyncWebSocketKitTests.swift index e662b2c6..ca01af98 100644 --- a/Tests/WebSocketKitTests/AsyncWebSocketKitTests.swift +++ b/Tests/WebSocketKitTests/AsyncWebSocketKitTests.swift @@ -47,8 +47,18 @@ final class AsyncWebSocketKitTests: XCTestCase { } func testBadURLInWebsocketConnect() async throws { + let server = try await ServerBootstrap.webSocket(on: self.elg) { req, ws in + ws.onText { ws, text in + ws.send(text) + } + }.bind(host: "localhost", port: 0).get() + + guard let port = server.localAddress?.port else { + XCTFail("couldn't get port from \(server.localAddress.debugDescription)") + return + } do { - try await WebSocket.connect(to: "%w", on: self.elg, onUpgrade: { _ async in }) + try await WebSocket.connect(to: "foo.doesntexist", on: self.elg, onUpgrade: { _ async in }) XCTAssertThrowsError({}()) } catch { XCTAssertThrowsError(try { throw error }()) { diff --git a/Tests/WebSocketKitTests/SSLTestHelpers.swift b/Tests/WebSocketKitTests/SSLTestHelpers.swift index a6776aab..812ddca3 100644 --- a/Tests/WebSocketKitTests/SSLTestHelpers.swift +++ b/Tests/WebSocketKitTests/SSLTestHelpers.swift @@ -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 @@ -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) } From b6bcaf781179d25f3515adbed53879969b2093a6 Mon Sep 17 00:00:00 2001 From: "Jimmy W. Hough Jr" Date: Fri, 22 Nov 2024 07:38:58 -0600 Subject: [PATCH 2/8] fixed some tests, deja vu --- .../AsyncWebSocketKitTests.swift | 29 +++++++++++++------ .../WebSocketKitTests/WebSocketKitTests.swift | 29 +++++++++++++++++-- 2 files changed, 47 insertions(+), 11 deletions(-) diff --git a/Tests/WebSocketKitTests/AsyncWebSocketKitTests.swift b/Tests/WebSocketKitTests/AsyncWebSocketKitTests.swift index ca01af98..66661417 100644 --- a/Tests/WebSocketKitTests/AsyncWebSocketKitTests.swift +++ b/Tests/WebSocketKitTests/AsyncWebSocketKitTests.swift @@ -47,18 +47,29 @@ final class AsyncWebSocketKitTests: XCTestCase { } func testBadURLInWebsocketConnect() async throws { - let server = try await ServerBootstrap.webSocket(on: self.elg) { req, ws in - ws.onText { ws, text in - ws.send(text) +// let server = try await ServerBootstrap.webSocket(on: self.elg) { req, ws in +// ws.onText { ws, text in +// ws.send(text) +// } +// }.bind(host: "localhost", port: 0).get() +// +// guard let port = server.localAddress?.port else { +// XCTFail("couldn't get port from \(server.localAddress.debugDescription)") +// return +// } + do { + try await WebSocket.connect(to: "", on: self.elg, onUpgrade: { _ async in }) + XCTAssertThrowsError({}()) + } catch { + XCTAssertThrowsError(try { throw error }()) { + guard case .invalidURL = $0 as? WebSocketClient.Error else { + return XCTFail("Expected .invalidURL but got \(String(reflecting: $0))") + } } - }.bind(host: "localhost", port: 0).get() - - guard let port = server.localAddress?.port else { - XCTFail("couldn't get port from \(server.localAddress.debugDescription)") - return } + do { - try await WebSocket.connect(to: "foo.doesntexist", on: self.elg, onUpgrade: { _ async in }) + try await WebSocket.connect(to: "", on: self.elg, onUpgrade: { _ async in }) XCTAssertThrowsError({}()) } catch { XCTAssertThrowsError(try { throw error }()) { diff --git a/Tests/WebSocketKitTests/WebSocketKitTests.swift b/Tests/WebSocketKitTests/WebSocketKitTests.swift index 9fa402ba..52c338e7 100644 --- a/Tests/WebSocketKitTests/WebSocketKitTests.swift +++ b/Tests/WebSocketKitTests/WebSocketKitTests.swift @@ -478,12 +478,37 @@ 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 testBadURLInWebsocketConnect() throws { + + let server = try ServerBootstrap.webSocket(on: self.elg) { $1.onText { $0.send($1) } }.bind(host: "localhost", port: 0).wait() + + guard let port = server.localAddress?.port else { + return XCTFail("couldn't get port from \(String(reflecting: server.localAddress))") + } + + XCTAssertThrowsError(try WebSocket.connect(to: "ws://%w:\(port)", on: self.elg, onUpgrade: { _ in }).wait()) { + guard case .invalidURL = $0 as? WebSocketClient.Error else { + return XCTFail("Expected .invalidURL but got \(String(reflecting: $0))") + } + } + + XCTAssertThrowsError(try WebSocket.connect(to: "ws://%w", on: self.elg, onUpgrade: { _ in }).wait()) { guard case .invalidURL = $0 as? WebSocketClient.Error else { return XCTFail("Expected .invalidURL but got \(String(reflecting: $0))") } } + + XCTAssertThrowsError(try WebSocket.connect(to: "", on: self.elg, onUpgrade: { _ in }).wait()) { + guard case .invalidURL = $0 as? WebSocketClient.Error else { + return XCTFail("Expected .invalidURL but got \(String(reflecting: $0))") + } + } + +// 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))") +// } +// } } func testOnBinary() throws { From c9eaeec3974db992ea7aa0e0f8356a41ad4a478c Mon Sep 17 00:00:00 2001 From: "Jimmy W. Hough Jr" Date: Fri, 22 Nov 2024 10:49:37 -0600 Subject: [PATCH 3/8] updated dependencies to latest versions as of Nov 22, 2024 --- Package.swift | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Package.swift b/Package.swift index c2bc7c9b..f615bb84 100644 --- a/Package.swift +++ b/Package.swift @@ -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: [ From e369277a980d4e076ec303d8ba8b38d7e4d721e6 Mon Sep 17 00:00:00 2001 From: "Jimmy W. Hough Jr" Date: Fri, 22 Nov 2024 17:13:59 -0600 Subject: [PATCH 4/8] renamed test to be more speccific and reduced the cases to what seems reliable and consistant across platforms. --- .../WebSocketKitTests/WebSocketKitTests.swift | 30 ++----------------- 1 file changed, 3 insertions(+), 27 deletions(-) diff --git a/Tests/WebSocketKitTests/WebSocketKitTests.swift b/Tests/WebSocketKitTests/WebSocketKitTests.swift index 52c338e7..293bfb84 100644 --- a/Tests/WebSocketKitTests/WebSocketKitTests.swift +++ b/Tests/WebSocketKitTests/WebSocketKitTests.swift @@ -478,37 +478,13 @@ final class WebSocketKitTests: XCTestCase { try server.close(mode: .all).wait() } - func testBadURLInWebsocketConnect() throws { - - let server = try ServerBootstrap.webSocket(on: self.elg) { $1.onText { $0.send($1) } }.bind(host: "localhost", port: 0).wait() - - guard let port = server.localAddress?.port else { - return XCTFail("couldn't get port from \(String(reflecting: server.localAddress))") - } - - XCTAssertThrowsError(try WebSocket.connect(to: "ws://%w:\(port)", on: self.elg, onUpgrade: { _ in }).wait()) { - guard case .invalidURL = $0 as? WebSocketClient.Error else { - return XCTFail("Expected .invalidURL but got \(String(reflecting: $0))") - } - } - - XCTAssertThrowsError(try WebSocket.connect(to: "ws://%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))") } } - - XCTAssertThrowsError(try WebSocket.connect(to: "", on: self.elg, onUpgrade: { _ in }).wait()) { - guard case .invalidURL = $0 as? WebSocketClient.Error else { - return XCTFail("Expected .invalidURL but got \(String(reflecting: $0))") - } - } - -// 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))") -// } -// } } func testOnBinary() throws { From 9c6ee70bb11eca5f6997f3ed2c4b7a0a9ffcf3f5 Mon Sep 17 00:00:00 2001 From: "Jimmy W. Hough Jr" Date: Fri, 22 Nov 2024 17:19:38 -0600 Subject: [PATCH 5/8] renmaed the async test for bad url scheme to be more speccific and test what is consistently behaved across platforms. --- .../AsyncWebSocketKitTests.swift | 26 +++---------------- 1 file changed, 3 insertions(+), 23 deletions(-) diff --git a/Tests/WebSocketKitTests/AsyncWebSocketKitTests.swift b/Tests/WebSocketKitTests/AsyncWebSocketKitTests.swift index 66661417..075c5968 100644 --- a/Tests/WebSocketKitTests/AsyncWebSocketKitTests.swift +++ b/Tests/WebSocketKitTests/AsyncWebSocketKitTests.swift @@ -46,30 +46,10 @@ final class AsyncWebSocketKitTests: XCTestCase { try await server.close(mode: .all) } - func testBadURLInWebsocketConnect() async throws { -// let server = try await ServerBootstrap.webSocket(on: self.elg) { req, ws in -// ws.onText { ws, text in -// ws.send(text) -// } -// }.bind(host: "localhost", port: 0).get() -// -// guard let port = server.localAddress?.port else { -// XCTFail("couldn't get port from \(server.localAddress.debugDescription)") -// return -// } - do { - try await WebSocket.connect(to: "", on: self.elg, onUpgrade: { _ async in }) - XCTAssertThrowsError({}()) - } catch { - XCTAssertThrowsError(try { throw error }()) { - guard case .invalidURL = $0 as? WebSocketClient.Error else { - return XCTFail("Expected .invalidURL but got \(String(reflecting: $0))") - } - } - } - + func testBadURLSchemeInWebsocketConnect() async throws { + do { - try await WebSocket.connect(to: "", on: self.elg, onUpgrade: { _ async in }) + try await WebSocket.connect(to: "ws$:", on: self.elg, onUpgrade: { _ async in }) XCTAssertThrowsError({}()) } catch { XCTAssertThrowsError(try { throw error }()) { From 88e0db9976775df8304df73d17e0f295ea1aa67b Mon Sep 17 00:00:00 2001 From: "Jimmy W. Hough Jr" Date: Fri, 22 Nov 2024 17:28:46 -0600 Subject: [PATCH 6/8] trying again to revalidate this test. --- Tests/WebSocketKitTests/AsyncWebSocketKitTests.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Tests/WebSocketKitTests/AsyncWebSocketKitTests.swift b/Tests/WebSocketKitTests/AsyncWebSocketKitTests.swift index 075c5968..051b2ab5 100644 --- a/Tests/WebSocketKitTests/AsyncWebSocketKitTests.swift +++ b/Tests/WebSocketKitTests/AsyncWebSocketKitTests.swift @@ -49,7 +49,7 @@ final class AsyncWebSocketKitTests: XCTestCase { func testBadURLSchemeInWebsocketConnect() async throws { do { - try await WebSocket.connect(to: "ws$:", on: self.elg, onUpgrade: { _ async in }) + try await WebSocket.connect(to: "w$:", on: self.elg, onUpgrade: { _ async in }) XCTAssertThrowsError({}()) } catch { XCTAssertThrowsError(try { throw error }()) { From 5b9ee8737f88a0d67f8825421f68ddc85b551465 Mon Sep 17 00:00:00 2001 From: "Jimmy W. Hough Jr" Date: Fri, 22 Nov 2024 18:41:01 -0600 Subject: [PATCH 7/8] found a string that works thanks to gwynne --- Tests/WebSocketKitTests/AsyncWebSocketKitTests.swift | 4 ++-- Tests/WebSocketKitTests/WebSocketKitTests.swift | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Tests/WebSocketKitTests/AsyncWebSocketKitTests.swift b/Tests/WebSocketKitTests/AsyncWebSocketKitTests.swift index 051b2ab5..68ecf798 100644 --- a/Tests/WebSocketKitTests/AsyncWebSocketKitTests.swift +++ b/Tests/WebSocketKitTests/AsyncWebSocketKitTests.swift @@ -47,9 +47,9 @@ final class AsyncWebSocketKitTests: XCTestCase { } 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 }()) { diff --git a/Tests/WebSocketKitTests/WebSocketKitTests.swift b/Tests/WebSocketKitTests/WebSocketKitTests.swift index 293bfb84..c608b541 100644 --- a/Tests/WebSocketKitTests/WebSocketKitTests.swift +++ b/Tests/WebSocketKitTests/WebSocketKitTests.swift @@ -480,7 +480,7 @@ final class WebSocketKitTests: XCTestCase { func testBadURLSchemeInWebsocketConnect() throws { - XCTAssertThrowsError(try WebSocket.connect(to: "w$:", on: self.elg, onUpgrade: { _ in }).wait()) { + 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))") } From 28594541823441d9d5fd29ade821efab1ffdeb3a Mon Sep 17 00:00:00 2001 From: "Jimmy W. Hough Jr" Date: Fri, 22 Nov 2024 18:50:14 -0600 Subject: [PATCH 8/8] I can hallucinate `'s now --- Tests/WebSocketKitTests/AsyncWebSocketKitTests.swift | 2 +- Tests/WebSocketKitTests/WebSocketKitTests.swift | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Tests/WebSocketKitTests/AsyncWebSocketKitTests.swift b/Tests/WebSocketKitTests/AsyncWebSocketKitTests.swift index 68ecf798..902eb0b4 100644 --- a/Tests/WebSocketKitTests/AsyncWebSocketKitTests.swift +++ b/Tests/WebSocketKitTests/AsyncWebSocketKitTests.swift @@ -49,7 +49,7 @@ final class AsyncWebSocketKitTests: XCTestCase { 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 }()) { diff --git a/Tests/WebSocketKitTests/WebSocketKitTests.swift b/Tests/WebSocketKitTests/WebSocketKitTests.swift index c608b541..caaaee49 100644 --- a/Tests/WebSocketKitTests/WebSocketKitTests.swift +++ b/Tests/WebSocketKitTests/WebSocketKitTests.swift @@ -480,7 +480,7 @@ final class WebSocketKitTests: XCTestCase { func testBadURLSchemeInWebsocketConnect() throws { - XCTAssertThrowsError(try WebSocket.connect(to: "w':", on: self.elg, onUpgrade: { _ in }).wait()) { + 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))") }