Skip to content

Commit

Permalink
fix: support deno + caching_sha2_password FULL_AUTHENTICATION_PACKET …
Browse files Browse the repository at this point in the history
…flow (#2704)

* use explicit padding in publicEncrypt so that it works consistently in node and deno
  • Loading branch information
sidorares authored May 26, 2024
1 parent 8b5f691 commit 2e03694
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 1 deletion.
50 changes: 50 additions & 0 deletions .github/workflows/ci-linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -108,3 +108,53 @@ jobs:
FILTER: test-select-1|test-select-ssl
run: bun run test:bun
timeout-minutes: 1

tests-linux-deno:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
deno-version: [v1.43.6, canary]
mysql-version: ["mysql:8.0.33"]
use-compression: [0, 1]
use-tls: [0,1]

name: Deno ${{ matrix.deno-version }} - DB ${{ matrix.mysql-version }} - SSL=${{matrix.use-tls}} Compression=${{matrix.use-compression}}

steps:
- uses: actions/checkout@v4
- name: Set up MySQL
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 }}

- name: Set up Deno ${{ matrix.deno-version }}
uses: denoland/setup-deno@v1
with:
deno-version: ${{ matrix.deno-version }}

- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: 20
- name: Cache dependencies
uses: actions/cache@v4
with:
path: ~/.npm
key: npm-linux-${{ hashFiles('package-lock.json') }}
restore-keys: npm-linux-

- name: Install npm dependencies
run: npm ci

- name: Wait mysql server is ready
run: node tools/wait-up.js

# todo: check what we need to do to run all tests with deno
- name: run tests
env:
MYSQL_USER: ${{ env.MYSQL_USER }}
MYSQL_DATABASE: ${{ env.MYSQL_DATABASE }}
MYSQL_PORT: ${{ env.MYSQL_PORT }}
MYSQL_USE_COMPRESSION: ${{ matrix.use-compression }}
MYSQL_USE_TLS: ${{ matrix.use-tls }}
run: deno test --allow-net --allow-env --allow-read test/deno.ts
timeout-minutes: 1
5 changes: 4 additions & 1 deletion lib/auth_plugins/caching_sha2_password.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,10 @@ function encrypt(password, scramble, key) {
Buffer.from(`${password}\0`, 'utf8'),
scramble
);
return crypto.publicEncrypt(key, stage1);
return crypto.publicEncrypt({
key,
padding: crypto.constants.RSA_PKCS1_OAEP_PADDING
}, stage1);
}

module.exports = (pluginOptions = {}) => ({ connection }) => {
Expand Down
26 changes: 26 additions & 0 deletions test/deno.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { createRequire } from 'node:module';
const require = createRequire(import.meta.url);
const mysql = require('../index.js');

const connection = mysql.createConnection({
host: Deno.env.get('MYSQL_HOST'),
port: Deno.env.get('MYSQL_PORT'),
user: Deno.env.get('MYSQL_USER'),
password: Deno.env.get('MYSQL_PASSWORD'),
database: Deno.env.get('MYSQL_DATABASE'),
});

connection.on('error', (err: Error) => {
console.error(err);
Deno.exit(1);
});

connection.on('connect', () => {
connection.query('SELECT 1 + 1 AS solution', (err: Error) => {
if (err) {
console.error(err);
Deno.exit(1);
}
connection.end();
});
});

0 comments on commit 2e03694

Please sign in to comment.