Skip to content

Commit ec404e7

Browse files
authored
Merge pull request #1805 from sidorares/bun-support
Bun support
2 parents 8a000e0 + a2392e2 commit ec404e7

File tree

8 files changed

+81
-45
lines changed

8 files changed

+81
-45
lines changed

.github/workflows/ci-bun.yml

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
name: CI - Linux (bun)
2+
3+
# this will be merged with ci-linux.yml
4+
5+
on:
6+
pull_request:
7+
push:
8+
branches: [ main ]
9+
10+
workflow_dispatch:
11+
12+
env:
13+
MYSQL_PORT: 3306
14+
MYSQL_USER: root
15+
MYSQL_DATABASE: test
16+
17+
jobs:
18+
tests-linux:
19+
runs-on: ubuntu-latest
20+
strategy:
21+
fail-fast: false
22+
matrix:
23+
bun-version: [0.5.1]
24+
mysql-version: ["mysql:5.7", "mysql:8.0.18", "mysql:8.0.22"]
25+
use-compression: [0]
26+
use-tls: [0]
27+
28+
name: Bun ${{ matrix.bun-version }} - DB ${{ matrix.mysql-version }} - SSL=${{matrix.use-tls}} Compression=${{matrix.use-compression}}
29+
30+
steps:
31+
- uses: actions/checkout@v3
32+
- name: Set up MySQL
33+
run: docker run -d -e MYSQL_ALLOW_EMPTY_PASSWORD=1 -e MYSQL_DATABASE=${{ env.MYSQL_DATABASE }} -v $PWD/mysqldata:/var/lib/mysql/ -v $PWD/examples/custom-conf:/etc/mysql/conf.d -v $PWD/examples/ssl/certs:/certs -p ${{ env.MYSQL_PORT }}:3306 ${{ matrix.mysql-version }}
34+
35+
- name: Set up Bun ${{ matrix.bun-version }}
36+
uses: oven-sh/[email protected]
37+
with:
38+
bun-version: ${{ matrix.bun-version }}
39+
40+
- name: Set up Node.js
41+
uses: actions/setup-node@v3
42+
with:
43+
node-version: 18
44+
- name: Cache dependencies
45+
uses: actions/cache@v3
46+
with:
47+
path: ~/.npm
48+
key: npm-${{ hashFiles('package-lock.json') }}
49+
restore-keys: npm-
50+
51+
- name: Install npm dependencies
52+
run: npm ci
53+
54+
# - name: Install npm dependencies
55+
# run: bun install
56+
57+
- name: Wait mysql server is ready
58+
run: node tools/wait-up.js
59+
60+
- name: Run tests
61+
# todo: run full test suite once test createServer is implemented using Bun.listen
62+
run: FILTER=test-select MYSQL_PORT=3306 bun run test

.github/workflows/ci-linux.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ jobs:
5555
mysql-version: "mysql:5.7"
5656
use-compression: 0
5757
use-tls: 0
58-
- filter: "5.1only"
58+
- filter: "test-select-1"
5959
node-version: "16.x"
6060
mysql-version: "datagrip/mysql:5.1"
6161
use-compression: 0

lib/auth_41.js

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -41,16 +41,7 @@ function sha1(msg, msg1, msg2) {
4141
}
4242

4343
function xor(a, b) {
44-
if (!Buffer.isBuffer(a)) {
45-
a = Buffer.from(a, 'binary');
46-
}
47-
48-
if (!Buffer.isBuffer(b)) {
49-
b = Buffer.from(b, 'binary');
50-
}
51-
5244
const result = Buffer.allocUnsafe(a.length);
53-
5445
for (let i = 0; i < a.length; i++) {
5546
result[i] = a[i] ^ b[i];
5647
}
@@ -60,7 +51,6 @@ function xor(a, b) {
6051
exports.xor = xor;
6152

6253
function token(password, scramble1, scramble2) {
63-
// TODO: use buffers (not sure why strings here)
6454
if (!password) {
6555
return Buffer.alloc(0);
6656
}
@@ -94,14 +84,6 @@ exports.doubleSha1 = function(password) {
9484
};
9585

9686
function xorRotating(a, seed) {
97-
if (!Buffer.isBuffer(a)) {
98-
a = Buffer.from(a, 'binary');
99-
}
100-
101-
if (!Buffer.isBuffer(seed)) {
102-
seed = Buffer.from(seed, 'binary');
103-
}
104-
10587
const result = Buffer.allocUnsafe(a.length);
10688
const seedLen = seed.length;
10789

lib/auth_plugins/caching_sha2_password.js

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,24 +17,24 @@ const STATE_FINAL = -1;
1717

1818
function sha256(msg) {
1919
const hash = crypto.createHash('sha256');
20-
hash.update(msg, 'binary');
21-
return hash.digest('binary');
20+
hash.update(msg);
21+
return hash.digest();
2222
}
2323

2424
function calculateToken(password, scramble) {
2525
if (!password) {
2626
return Buffer.alloc(0);
2727
}
28-
const stage1 = sha256(Buffer.from(password, 'utf8').toString('binary'));
28+
const stage1 = sha256(Buffer.from(password));
2929
const stage2 = sha256(stage1);
30-
const stage3 = sha256(stage2 + scramble.toString('binary'));
30+
const stage3 = sha256(Buffer.concat([stage2, scramble]));
3131
return xor(stage1, stage3);
3232
}
3333

3434
function encrypt(password, scramble, key) {
3535
const stage1 = xorRotating(
36-
Buffer.from(`${password}\0`, 'utf8').toString('binary'),
37-
scramble.toString('binary')
36+
Buffer.from(`${password}\0`, 'utf8'),
37+
scramble
3838
);
3939
return crypto.publicEncrypt(key, stage1);
4040
}
@@ -86,6 +86,7 @@ module.exports = (pluginOptions = {}) => ({ connection }) => {
8686
`Invalid AuthMoreData packet received by ${PLUGIN_NAME} plugin in STATE_TOKEN_SENT state.`
8787
);
8888
case STATE_WAIT_SERVER_KEY:
89+
console.log('Server pub key:', data);
8990
if (pluginOptions.onServerPublicKey) {
9091
pluginOptions.onServerPublicKey(data);
9192
}

lib/auth_plugins/sha256_password.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ const STATE_FINAL = -1;
1212

1313
function encrypt(password, scramble, key) {
1414
const stage1 = xorRotating(
15-
Buffer.from(`${password}\0`, 'utf8').toString('binary'),
16-
scramble.toString('binary')
15+
Buffer.from(`${password}\0`, 'utf8'),
16+
scramble
1717
);
1818
return crypto.publicEncrypt(key, stage1);
1919
}

lib/connection_config.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ class ConnectionConfig {
9191
this.isServer = options.isServer;
9292
this.stream = options.stream;
9393
this.host = options.host || 'localhost';
94-
this.port = options.port || 3306;
94+
this.port = (typeof options.port === 'string' ? parseInt(options.port, 10) : options.port)|| 3306;
9595
this.localAddress = options.localAddress;
9696
this.socketPath = options.socketPath;
9797
this.user = options.user || undefined;
@@ -254,7 +254,7 @@ class ConnectionConfig {
254254
const parsedUrl = new URL(url);
255255
const options = {
256256
host: parsedUrl.hostname,
257-
port: parsedUrl.port,
257+
port: parseInt(parsedUrl.port, 10),
258258
database: parsedUrl.pathname.slice(1),
259259
user: parsedUrl.username,
260260
password: parsedUrl.password

test/common.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ exports.config = config;
3030
exports.waitDatabaseReady = function(callback) {
3131
const start = Date.now();
3232
const tryConnect = function() {
33-
const conn = exports.createConnection({ database: 'mysql' });
33+
const conn = exports.createConnection({ database: 'mysql', password: process.env.MYSQL_PASSWORD });
3434
conn.once('error', err => {
3535
if (err.code !== 'PROTOCOL_CONNECTION_LOST' && err.code !== 'ETIMEDOUT') {
3636
console.log('Unexpected error waiting for connection', err);
Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,13 @@
11
'use strict';
22

3+
const assert = require('assert');
34
const common = require('../../common');
45
const connection = common.createConnection();
5-
const assert = require('assert');
6-
7-
let rows = undefined;
8-
let fields = undefined;
9-
connection.query('SELECT 1', (err, _rows, _fields) => {
10-
if (err) {
11-
throw err;
12-
}
136

14-
rows = _rows;
15-
fields = _fields;
16-
connection.end();
17-
});
18-
19-
process.on('exit', () => {
7+
connection.query('SELECT 1', (err, rows, fields) => {
8+
console.log('query callback', err, rows, fields);
9+
assert.ifError(err);
2010
assert.deepEqual(rows, [{ 1: 1 }]);
2111
assert.equal(fields[0].name, '1');
22-
});
12+
connection.end();
13+
});

0 commit comments

Comments
 (0)