Skip to content

Commit 853b434

Browse files
authored
Finally make non-TLS connections work with modern MySQL (#114)
* Bump the package to Swift 5.10. Lots of non-functional changes to make Concurrency warnings go away. CI updates. README and docs updates. * _CryptoExtras has had RSA for a long time now. Use it. * It would be nice if Xcode would actually tell me about these errors * Add CI that tests using non-TLS connections * Quick and dirty retry loop * MySQLCommand doesn't actually need to be Sendable, we can just silence the compiler since we already use it safely
1 parent 257e719 commit 853b434

28 files changed

+1668
-1493
lines changed

.github/contributing.md

Lines changed: 0 additions & 29 deletions
This file was deleted.

.github/workflows/test.yml

Lines changed: 45 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ on:
77
push: { branches: [ main ] }
88
env:
99
LOG_LEVEL: info
10-
SWIFT_DETERMINISTIC_HASHING: 1
1110
MYSQL_DATABASE: 'test_database'
1211
MYSQL_DATABASE_A: 'test_database'
1312
MYSQL_DATABASE_B: 'test_database'
@@ -25,7 +24,7 @@ jobs:
2524
api-breakage:
2625
if: ${{ !(github.event.pull_request.draft || false) }}
2726
runs-on: ubuntu-latest
28-
container: swift:jammy
27+
container: swift:noble
2928
steps:
3029
- name: Check out code
3130
uses: actions/checkout@v5
@@ -35,6 +34,44 @@ jobs:
3534
git config --global --add safe.directory "${GITHUB_WORKSPACE}"
3635
swift package diagnose-api-breaking-changes origin/main
3736
37+
linux-insecure-test:
38+
if: ${{ !(github.event.pull_request.draft || false) }}
39+
strategy:
40+
fail-fast: false
41+
matrix:
42+
dbimage:
43+
- mysql:9.4
44+
swiftver:
45+
- swift:6.1-noble
46+
runs-on: ubuntu-latest
47+
container:
48+
image: ${{ matrix.swiftver }}
49+
volumes: [ 'mysqlshare:/var/run/mysqld' ]
50+
services:
51+
mysql-a:
52+
image: ${{ matrix.dbimage }}
53+
volumes: [ 'mysqlshare:/var/run/mysqld' ]
54+
env: { MYSQL_ALLOW_EMPTY_PASSWORD: true, MYSQL_USER: test_username, MYSQL_PASSWORD: test_password, MYSQL_DATABASE: test_database }
55+
steps:
56+
- name: Force MySQL server to disallow TLS
57+
shell: bash
58+
run: |
59+
apt-get update && apt-get install -y 'mysql-client-core-*' curl
60+
i=0; while ((i<10)); do
61+
{ mysql -BS/var/run/mysqld/mysqld.sock <<<"SET PERSIST ssl_ca='',ssl_cert='',ssl_key='';ALTER INSTANCE RELOAD TLS NO ROLLBACK ON ERROR;" ; } && break
62+
sleep 2
63+
i=$((i+1))
64+
done
65+
((i<10))
66+
- name: Check out package
67+
uses: actions/checkout@v5
68+
- name: Run unit tests
69+
run: swift test --enable-code-coverage
70+
- name: Upload code coverage
71+
uses: vapor/[email protected]
72+
with:
73+
codecov_token: ${{ secrets.CODECOV_TOKEN }}
74+
3875
linux-all:
3976
if: ${{ !(github.event.pull_request.draft || false) }}
4077
strategy:
@@ -49,8 +86,10 @@ jobs:
4986
- percona:8
5087
swiftver:
5188
- swift:5.10-jammy
52-
- swift:6.0-jammy
53-
- swift:6.1-jammy
89+
- swift:6.0-noble
90+
- swift:6.1-noble
91+
- swiftlang/swift:nightly-6.2-noble
92+
- swiftlang/swift:nightly-main-noble
5493
runs-on: ubuntu-latest
5594
container: ${{ matrix.swiftver }}
5695
services:
@@ -67,7 +106,7 @@ jobs:
67106
uses: actions/checkout@v5
68107
with: { path: 'mysql-nio' }
69108
- name: Run unit tests
70-
run: swift test --package-path mysql-nio --enable-code-coverage --sanitize=thread
109+
run: swift test --package-path mysql-nio --enable-code-coverage
71110
- name: Upload code coverage
72111
uses: vapor/[email protected]
73112
with:
@@ -125,7 +164,7 @@ jobs:
125164
- name: Check out code
126165
uses: actions/checkout@v5
127166
- name: Run all tests
128-
run: swift test --sanitize=thread --enable-code-coverage
167+
run: swift test --enable-code-coverage
129168
- name: Upload code coverage
130169
uses: vapor/[email protected]
131170
with:

Package.swift

Lines changed: 30 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// swift-tools-version:5.7
1+
// swift-tools-version:5.10
22
import PackageDescription
33

44
let package = Package(
@@ -13,20 +13,40 @@ let package = Package(
1313
.library(name: "MySQLNIO", targets: ["MySQLNIO"]),
1414
],
1515
dependencies: [
16+
.package(url: "https://github.com/apple/swift-algorithms.git", from: "1.0.0"),
1617
.package(url: "https://github.com/apple/swift-crypto.git", "1.0.0" ..< "4.0.0"),
1718
.package(url: "https://github.com/apple/swift-log.git", from: "1.0.0"),
1819
.package(url: "https://github.com/apple/swift-nio.git", from: "2.0.0"),
1920
.package(url: "https://github.com/apple/swift-nio-ssl.git", from: "2.14.0"),
2021
],
2122
targets: [
22-
.target(name: "MySQLNIO", dependencies: [
23-
.product(name: "Crypto", package: "swift-crypto"),
24-
.product(name: "Logging", package: "swift-log"),
25-
.product(name: "NIO", package: "swift-nio"),
26-
.product(name: "NIOSSL", package: "swift-nio-ssl"),
27-
]),
28-
.testTarget(name: "MySQLNIOTests", dependencies: [
29-
.target(name: "MySQLNIO"),
30-
]),
23+
.target(
24+
name: "MySQLNIO",
25+
dependencies: [
26+
.product(name: "Algorithms", package: "swift-algorithms"),
27+
.product(name: "_CryptoExtras", package: "swift-crypto"),
28+
.product(name: "Crypto", package: "swift-crypto"),
29+
.product(name: "Logging", package: "swift-log"),
30+
.product(name: "NIO", package: "swift-nio"),
31+
.product(name: "NIOSSL", package: "swift-nio-ssl"),
32+
],
33+
swiftSettings: swiftSettings
34+
),
35+
.testTarget(
36+
name: "MySQLNIOTests",
37+
dependencies: [
38+
.target(name: "MySQLNIO"),
39+
],
40+
swiftSettings: swiftSettings
41+
),
3142
]
3243
)
44+
45+
var swiftSettings: [SwiftSetting] { [
46+
.enableUpcomingFeature("ExistentialAny"),
47+
.enableUpcomingFeature("ConciseMagicFile"),
48+
.enableUpcomingFeature("ForwardTrailingClosures"),
49+
.enableUpcomingFeature("DisableOutwardActorInference"),
50+
.enableUpcomingFeature("MemberImportVisibility"),
51+
.enableExperimentalFeature("StrictConcurrency=complete"),
52+
] }

README.md

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,13 @@
11
<p align="center">
2-
<picture>
3-
<source media="(prefers-color-scheme: dark)" srcset="https://github.com/vapor/mysql-nio/assets/1130717/8ef2ef8b-070d-4026-a425-8e25159ca398">
4-
<source media="(prefers-color-scheme: light)" srcset="https://github.com/vapor/mysql-nio/assets/1130717/595fbebd-8762-4a32-b990-3abde04a411c">
5-
<img src="https://github.com/vapor/mysql-nio/assets/1130717/595fbebd-8762-4a32-b990-3abde04a411c" height="96" alt="MySQLNIO">
6-
</picture>
2+
<img src="https://design.vapor.codes/images/vapor-mysqlnio.svg" height="96" alt="MySQLNIO">
73
<br>
84
<br>
95
<a href="https://docs.vapor.codes/4.0/"><img src="https://design.vapor.codes/images/readthedocs.svg" alt="Documentation"></a>
106
<a href="https://discord.gg/vapor"><img src="https://design.vapor.codes/images/discordchat.svg" alt="Team Chat"></a>
117
<a href="LICENSE"><img src="https://design.vapor.codes/images/mitlicense.svg" alt="MIT License"></a>
128
<a href="https://github.com/vapor/mysql-nio/actions/workflows/test.yml"><img src="https://img.shields.io/github/actions/workflow/status/vapor/mysql-nio/test.yml?event=push&style=plastic&logo=github&label=test&logoColor=%23ccc" alt="Continuous Integration"></a>
139
<a href="https://codecov.io/github/vapor/mysql-nio"><img src="https://img.shields.io/codecov/c/github/vapor/mysql-nio?style=plastic&logo=codecov&label=Codecov"></a>
14-
<a href="https://swift.org"><img src="https://design.vapor.codes/images/swift57up.svg" alt="Swift 5.7+"></a>
10+
<a href="https://swift.org"><img src="https://design.vapor.codes/images/swift510up.svg" alt="Swift 5.10+"></a>
1511
</p>
1612

1713
<br>
@@ -95,8 +91,6 @@ let conn = try await MySQLConnection(
9591
).get()
9692
```
9793

98-
Note: These examples will make use of `wait()` for simplicity. This is appropriate if you are using MySQLNIO on the main thread, like for a CLI tool or in tests. However, you should never use `wait()` on an event loop.
99-
10094
There are a few ways to create a `SocketAddress`:
10195

10296
- `init(ipAddress: String, port: Int)`
@@ -108,7 +102,7 @@ There are also some additional arguments you can supply to `connect`.
108102
- `tlsConfiguration` An optional `TLSConfiguration` struct. This will be used if the MySQL server supports TLS. Pass `nil` to opt-out of TLS.
109103
- `serverHostname` An optional `String` to use in conjunction with `tlsConfiguration` to specify the server's hostname.
110104

111-
`connect` will return a future `MySQLConnection`, or an error if it could not connect.
105+
`connect` will return a `MySQLConnection`, or an error if it could not connect.
112106

113107
### Database Protocol
114108

Lines changed: 19 additions & 15 deletions
Loading

0 commit comments

Comments
 (0)