diff --git a/.github/workflows/ci-bun.yml b/.github/workflows/ci-bun.yml index 7216d0cd5f..14ddb03faa 100644 --- a/.github/workflows/ci-bun.yml +++ b/.github/workflows/ci-bun.yml @@ -59,4 +59,4 @@ jobs: - name: Run tests # todo: run full test suite once test createServer is implemented using Bun.listen - run: DEBUG=1 MYSQL_PORT=3306 bun test/integration/connection/test-select-1.js \ No newline at end of file + run: FILTER=test-select MYSQL_PORT=3306 bun run test \ No newline at end of file diff --git a/.github/workflows/ci-linux.yml b/.github/workflows/ci-linux.yml index b7cf117052..57c511ab4c 100644 --- a/.github/workflows/ci-linux.yml +++ b/.github/workflows/ci-linux.yml @@ -55,7 +55,7 @@ jobs: mysql-version: "mysql:5.7" use-compression: 0 use-tls: 0 - - filter: "5.1only" + - filter: "test-select-1" node-version: "16.x" mysql-version: "datagrip/mysql:5.1" use-compression: 0 diff --git a/lib/auth_41.js b/lib/auth_41.js index bbdae41e49..15d6d032eb 100644 --- a/lib/auth_41.js +++ b/lib/auth_41.js @@ -41,16 +41,7 @@ function sha1(msg, msg1, msg2) { } function xor(a, b) { - if (!Buffer.isBuffer(a)) { - a = Buffer.from(a, 'binary'); - } - - if (!Buffer.isBuffer(b)) { - b = Buffer.from(b, 'binary'); - } - const result = Buffer.allocUnsafe(a.length); - for (let i = 0; i < a.length; i++) { result[i] = a[i] ^ b[i]; } @@ -60,7 +51,6 @@ function xor(a, b) { exports.xor = xor; function token(password, scramble1, scramble2) { - // TODO: use buffers (not sure why strings here) if (!password) { return Buffer.alloc(0); } @@ -94,14 +84,6 @@ exports.doubleSha1 = function(password) { }; function xorRotating(a, seed) { - if (!Buffer.isBuffer(a)) { - a = Buffer.from(a, 'binary'); - } - - if (!Buffer.isBuffer(seed)) { - seed = Buffer.from(seed, 'binary'); - } - const result = Buffer.allocUnsafe(a.length); const seedLen = seed.length; diff --git a/lib/auth_plugins/caching_sha2_password.js b/lib/auth_plugins/caching_sha2_password.js index 50e8589d58..3ed01e3c7f 100644 --- a/lib/auth_plugins/caching_sha2_password.js +++ b/lib/auth_plugins/caching_sha2_password.js @@ -17,24 +17,24 @@ const STATE_FINAL = -1; function sha256(msg) { const hash = crypto.createHash('sha256'); - hash.update(msg, 'binary'); - return hash.digest('binary'); + hash.update(msg); + return hash.digest(); } function calculateToken(password, scramble) { if (!password) { return Buffer.alloc(0); } - const stage1 = sha256(Buffer.from(password, 'utf8').toString('binary')); + const stage1 = sha256(Buffer.from(password)); const stage2 = sha256(stage1); - const stage3 = sha256(stage2 + scramble.toString('binary')); + const stage3 = sha256(Buffer.concat([stage2, scramble])); return xor(stage1, stage3); } function encrypt(password, scramble, key) { const stage1 = xorRotating( - Buffer.from(`${password}\0`, 'utf8').toString('binary'), - scramble.toString('binary') + Buffer.from(`${password}\0`, 'utf8'), + scramble ); return crypto.publicEncrypt(key, stage1); } @@ -86,6 +86,7 @@ module.exports = (pluginOptions = {}) => ({ connection }) => { `Invalid AuthMoreData packet received by ${PLUGIN_NAME} plugin in STATE_TOKEN_SENT state.` ); case STATE_WAIT_SERVER_KEY: + console.log('Server pub key:', data); if (pluginOptions.onServerPublicKey) { pluginOptions.onServerPublicKey(data); } diff --git a/lib/auth_plugins/sha256_password.js b/lib/auth_plugins/sha256_password.js index f787172d8c..9c104a0715 100644 --- a/lib/auth_plugins/sha256_password.js +++ b/lib/auth_plugins/sha256_password.js @@ -12,8 +12,8 @@ const STATE_FINAL = -1; function encrypt(password, scramble, key) { const stage1 = xorRotating( - Buffer.from(`${password}\0`, 'utf8').toString('binary'), - scramble.toString('binary') + Buffer.from(`${password}\0`, 'utf8'), + scramble ); return crypto.publicEncrypt(key, stage1); } diff --git a/test/integration/connection/test-select-1.js b/test/integration/connection/test-select-1.js index c778970167..b7066bda6c 100644 --- a/test/integration/connection/test-select-1.js +++ b/test/integration/connection/test-select-1.js @@ -1,41 +1,13 @@ 'use strict'; -console.log('Hello from bun test', typeof Bun); - +const assert = require('assert'); const common = require('../../common'); - -console.log('after import'); - const connection = common.createConnection(); -connection.on('connect', function(hello) { - console.log('connect', hello.serverVersion, hello.protocolVersion); -}) -console.log('after create connection'); -//const assert = require('assert'); -connection.query('SELECT 1', (err, _rows, _fields) => { - console.log('query callback', err, _rows, _fields); - connection.end(); - console.log('after end connection'); -}); - - -/* -let rows = undefined; -let fields = undefined; -connection.query('SELECT 1', (err, _rows, _fields) => { - if (err) { - throw err; - } - - rows = _rows; - fields = _fields; - connection.end(); -}); - -process.on('exit', () => { +connection.query('SELECT 1', (err, rows, fields) => { + console.log('query callback', err, rows, fields); + assert.ifError(err); assert.deepEqual(rows, [{ 1: 1 }]); assert.equal(fields[0].name, '1'); -}); - -*/ \ No newline at end of file + connection.end(); +}); \ No newline at end of file