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: support deno + caching_sha2_password FULL_AUTHENTICATION_PACKET flow #2704

Merged
merged 9 commits into from
May 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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();
});
});
Loading