Skip to content

Commit 2e03694

Browse files
authored
fix: support deno + caching_sha2_password FULL_AUTHENTICATION_PACKET flow (#2704)
* use explicit padding in publicEncrypt so that it works consistently in node and deno
1 parent 8b5f691 commit 2e03694

File tree

3 files changed

+80
-1
lines changed

3 files changed

+80
-1
lines changed

.github/workflows/ci-linux.yml

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,3 +108,53 @@ jobs:
108108
FILTER: test-select-1|test-select-ssl
109109
run: bun run test:bun
110110
timeout-minutes: 1
111+
112+
tests-linux-deno:
113+
runs-on: ubuntu-latest
114+
strategy:
115+
fail-fast: false
116+
matrix:
117+
deno-version: [v1.43.6, canary]
118+
mysql-version: ["mysql:8.0.33"]
119+
use-compression: [0, 1]
120+
use-tls: [0,1]
121+
122+
name: Deno ${{ matrix.deno-version }} - DB ${{ matrix.mysql-version }} - SSL=${{matrix.use-tls}} Compression=${{matrix.use-compression}}
123+
124+
steps:
125+
- uses: actions/checkout@v4
126+
- name: Set up MySQL
127+
run: docker run -d -e MYSQL_ALLOW_EMPTY_PASSWORD=1 -e MYSQL_DATABASE=${{ env.MYSQL_DATABASE }} -v $PWD/mysqldata:/var/lib/mysql/ -v $PWD/test/fixtures/custom-conf:/etc/mysql/conf.d -v $PWD/test/fixtures/ssl/certs:/certs -p ${{ env.MYSQL_PORT }}:3306 ${{ matrix.mysql-version }}
128+
129+
- name: Set up Deno ${{ matrix.deno-version }}
130+
uses: denoland/setup-deno@v1
131+
with:
132+
deno-version: ${{ matrix.deno-version }}
133+
134+
- name: Set up Node.js
135+
uses: actions/setup-node@v4
136+
with:
137+
node-version: 20
138+
- name: Cache dependencies
139+
uses: actions/cache@v4
140+
with:
141+
path: ~/.npm
142+
key: npm-linux-${{ hashFiles('package-lock.json') }}
143+
restore-keys: npm-linux-
144+
145+
- name: Install npm dependencies
146+
run: npm ci
147+
148+
- name: Wait mysql server is ready
149+
run: node tools/wait-up.js
150+
151+
# todo: check what we need to do to run all tests with deno
152+
- name: run tests
153+
env:
154+
MYSQL_USER: ${{ env.MYSQL_USER }}
155+
MYSQL_DATABASE: ${{ env.MYSQL_DATABASE }}
156+
MYSQL_PORT: ${{ env.MYSQL_PORT }}
157+
MYSQL_USE_COMPRESSION: ${{ matrix.use-compression }}
158+
MYSQL_USE_TLS: ${{ matrix.use-tls }}
159+
run: deno test --allow-net --allow-env --allow-read test/deno.ts
160+
timeout-minutes: 1

lib/auth_plugins/caching_sha2_password.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,10 @@ function encrypt(password, scramble, key) {
3636
Buffer.from(`${password}\0`, 'utf8'),
3737
scramble
3838
);
39-
return crypto.publicEncrypt(key, stage1);
39+
return crypto.publicEncrypt({
40+
key,
41+
padding: crypto.constants.RSA_PKCS1_OAEP_PADDING
42+
}, stage1);
4043
}
4144

4245
module.exports = (pluginOptions = {}) => ({ connection }) => {

test/deno.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import { createRequire } from 'node:module';
2+
const require = createRequire(import.meta.url);
3+
const mysql = require('../index.js');
4+
5+
const connection = mysql.createConnection({
6+
host: Deno.env.get('MYSQL_HOST'),
7+
port: Deno.env.get('MYSQL_PORT'),
8+
user: Deno.env.get('MYSQL_USER'),
9+
password: Deno.env.get('MYSQL_PASSWORD'),
10+
database: Deno.env.get('MYSQL_DATABASE'),
11+
});
12+
13+
connection.on('error', (err: Error) => {
14+
console.error(err);
15+
Deno.exit(1);
16+
});
17+
18+
connection.on('connect', () => {
19+
connection.query('SELECT 1 + 1 AS solution', (err: Error) => {
20+
if (err) {
21+
console.error(err);
22+
Deno.exit(1);
23+
}
24+
connection.end();
25+
});
26+
});

0 commit comments

Comments
 (0)