Skip to content

Commit 8c91a13

Browse files
committed
[misc] add code coverage
1 parent 8e975c3 commit 8c91a13

File tree

10 files changed

+210
-62
lines changed

10 files changed

+210
-62
lines changed

lib/cmd/column-definition.js

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,7 @@ class ColumnDef {
2727
break;
2828

2929
default:
30-
// skip data
31-
const len = subPacket.readUnsignedLength();
32-
if (len) {
33-
subPacket.skip(len);
34-
}
30+
subPacket.skip(subPacket.readUnsignedLength());
3531
break;
3632
}
3733
}

lib/cmd/handshake/auth/caching-sha2-password-auth.js

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -106,14 +106,6 @@ class CachingSha2PasswordAuth extends PluginAuth {
106106
}
107107
}
108108

109-
static sendSha256PwdPacket(cmd, pluginData, publicKey, password, out) {
110-
const truncatedSeed = pluginData.slice(0, pluginData.length - 1);
111-
out.startPacket(cmd);
112-
const enc = Sha256PasswordAuth.encrypt(truncatedSeed, password, publicKey);
113-
out.writeBuffer(enc, 0, enc.length);
114-
out.flushPacket();
115-
}
116-
117109
response(packet, out, opts, info) {
118110
const marker = packet.peek();
119111
switch (marker) {

lib/connection-callback.js

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,9 @@ class ConnectionCallback {
2525
#noop = () => {};
2626

2727
release = (cb) => {
28-
this.#conn.release(
29-
() => {
30-
if (cb) cb();
31-
},
32-
(err) => {
33-
if (cb) cb(err);
34-
}
35-
);
28+
this.#conn.release(() => {
29+
if (cb) cb();
30+
});
3631
};
3732

3833
/**

lib/connection-promise.js

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,10 +87,6 @@ class ConnectionPromise {
8787
return new Promise(this.#conn.query.bind(this.#conn, cmdParam));
8888
}
8989

90-
static _QUERY_CMD(conn, cmdParam) {
91-
return new Promise(conn.query.bind(conn, cmdParam));
92-
}
93-
9490
static _PARAM(options, sql, values) {
9591
let _cmdOpt,
9692
_sql = sql,

lib/pool.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -402,7 +402,7 @@ class Pool extends EventEmitter {
402402
await conn.connect();
403403
const pool = this;
404404
conn.forceEnd = conn.end;
405-
conn.release = function (resolve, reject) {
405+
conn.release = function (resolve) {
406406
if (pool.#closed || !conn.isValid()) {
407407
pool._destroy(conn);
408408
resolve();

test/integration/test-auth-plugin.js

Lines changed: 121 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
const base = require('../base.js');
44
const { assert } = require('chai');
55
const Conf = require('../conf');
6+
const fs = require('fs');
7+
const os = require('os');
8+
const path = require('path');
69

710
describe('authentication plugin', () => {
811
let rsaPublicKey = process.env.TEST_RSA_PUBLIC_KEY;
@@ -33,6 +36,7 @@ describe('authentication plugin', () => {
3336
await shareConn.query("DROP USER 'cachingSha256User'@'%'").catch((e) => {});
3437
await shareConn.query("DROP USER 'cachingSha256User2'@'%'").catch((e) => {});
3538
await shareConn.query("DROP USER 'cachingSha256User3'@'%'").catch((e) => {});
39+
await shareConn.query("DROP USER 'cachingSha256User4'@'%'").catch((e) => {});
3640

3741
if (!shareConn.info.isMariaDB()) {
3842
if (shareConn.info.hasMinVersion(8, 0, 0)) {
@@ -51,6 +55,10 @@ describe('authentication plugin', () => {
5155
"CREATE USER 'cachingSha256User3'@'%' IDENTIFIED WITH caching_sha2_password BY 'password'"
5256
);
5357
await shareConn.query("GRANT ALL PRIVILEGES ON *.* TO 'cachingSha256User3'@'%'");
58+
await shareConn.query(
59+
"CREATE USER 'cachingSha256User4'@'%' IDENTIFIED WITH caching_sha2_password BY 'password'"
60+
);
61+
await shareConn.query("GRANT ALL PRIVILEGES ON *.* TO 'cachingSha256User4'@'%'");
5462
} else {
5563
await shareConn.query("CREATE USER 'sha256User'@'%'");
5664
await shareConn.query(
@@ -121,6 +129,7 @@ describe('authentication plugin', () => {
121129
assert(expectedMsg);
122130
}
123131
});
132+
124133
it('name pipe authentication plugin', function (done) {
125134
if (process.platform !== 'win32') this.skip();
126135
if (process.env.srv === 'maxscale') this.skip();
@@ -329,25 +338,63 @@ describe('authentication plugin', () => {
329338
.catch(done);
330339
});
331340

332-
it('sha256 authentication plugin', function (done) {
333-
if (process.platform === 'win32') this.skip();
341+
it('sha256 authentication plugin', async function () {
334342
if (!rsaPublicKey || shareConn.info.isMariaDB() || !shareConn.info.hasMinVersion(5, 7, 0)) this.skip();
335343

336344
const self = this;
337-
base
338-
.createConnection({
345+
try {
346+
const conn = await base.createConnection({
339347
user: 'sha256User',
340348
password: 'password',
341349
rsaPublicKey: rsaPublicKey
342-
})
343-
.then((conn) => {
344-
conn.end();
345-
done();
346-
})
347-
.catch((err) => {
348-
if (err.message.includes('sha256_password authentication plugin require node 11.6+')) self.skip();
349-
done(err);
350350
});
351+
conn.end();
352+
} catch (err) {
353+
if (err.message.includes('sha256_password authentication plugin require node 11.6+')) self.skip();
354+
throw err;
355+
}
356+
357+
try {
358+
const conn = await base.createConnection({
359+
user: 'sha256User',
360+
password: 'password',
361+
rsaPublicKey: '/wrongPath'
362+
});
363+
conn.end();
364+
throw new Error('must have thrown exception');
365+
} catch (err) {
366+
if (err.message.includes('sha256_password authentication plugin require node 11.6+')) self.skip();
367+
assert.isTrue(err.message.includes('/wrongPath'));
368+
}
369+
370+
const filePath = path.join(os.tmpdir(), 'RSA_tmp_file.txt');
371+
fs.writeFileSync(filePath, rsaPublicKey);
372+
try {
373+
const conn = await base.createConnection({
374+
user: 'sha256User',
375+
password: 'password',
376+
rsaPublicKey: filePath
377+
});
378+
conn.end();
379+
} catch (err) {
380+
if (err.message.includes('sha256_password authentication plugin require node 11.6+')) self.skip();
381+
throw err;
382+
}
383+
try {
384+
fs.unlinkSync(filePath);
385+
} catch (e) {}
386+
387+
try {
388+
const conn = await base.createConnection({
389+
user: 'sha256User',
390+
rsaPublicKey: rsaPublicKey
391+
});
392+
conn.end();
393+
throw new Error('must have thrown exception');
394+
} catch (err) {
395+
if (err.message.includes('sha256_password authentication plugin require node 11.6+')) self.skip();
396+
assert.isTrue(err.message.includes('Access denied'));
397+
}
351398
});
352399

353400
it('sha256 authentication plugin with public key retrieval', function (done) {
@@ -424,36 +471,75 @@ describe('authentication plugin', () => {
424471
.catch(done);
425472
});
426473

427-
it('cachingsha256 authentication plugin', function (done) {
428-
if (process.platform === 'win32') this.skip();
474+
it('cachingsha256 authentication plugin', async function () {
475+
// if (process.platform === 'win32') this.skip();
429476
if (!rsaPublicKey || shareConn.info.isMariaDB() || !shareConn.info.hasMinVersion(8, 0, 0)) this.skip();
430477

431478
const self = this;
432-
base
433-
.createConnection({
479+
480+
try {
481+
const conn = await base.createConnection({
482+
user: 'cachingSha256User4',
483+
password: 'password',
484+
cachingRsaPublicKey: '/wrongPath'
485+
});
486+
conn.end();
487+
throw new Error('must have thrown exception');
488+
} catch (err) {
489+
if (err.message.includes('sha256_password authentication plugin require node 11.6+')) self.skip();
490+
assert.isTrue(err.message.includes('/wrongPath'));
491+
}
492+
493+
const filePath = path.join(os.tmpdir(), 'RSA_tmp_file.txt');
494+
fs.writeFileSync(filePath, rsaPublicKey);
495+
try {
496+
const conn = await base.createConnection({
497+
user: 'cachingSha256User4',
498+
password: 'password',
499+
cachingRsaPublicKey: filePath
500+
});
501+
conn.end();
502+
} catch (err) {
503+
if (err.message.includes('sha256_password authentication plugin require node 11.6+')) self.skip();
504+
throw err;
505+
}
506+
try {
507+
fs.unlinkSync(filePath);
508+
} catch (e) {}
509+
510+
try {
511+
const conn = await base.createConnection({
512+
user: 'cachingSha256User',
513+
cachingRsaPublicKey: rsaPublicKey
514+
});
515+
conn.end();
516+
throw new Error('must have thrown exception');
517+
} catch (err) {
518+
if (err.message.includes('sha256_password authentication plugin require node 11.6+')) self.skip();
519+
assert.isTrue(err.message.includes('Access denied'));
520+
}
521+
522+
try {
523+
const conn = await base.createConnection({
434524
user: 'cachingSha256User',
435525
password: 'password',
436526
cachingRsaPublicKey: rsaPublicKey
437-
})
438-
.then((conn) => {
439-
conn.end();
440-
//using fast auth
441-
base
442-
.createConnection({
443-
user: 'cachingSha256User',
444-
password: 'password',
445-
cachingRsaPublicKey: rsaPublicKey
446-
})
447-
.then((conn) => {
448-
conn.end();
449-
done();
450-
})
451-
.catch(done);
452-
})
453-
.catch((err) => {
454-
if (err.message.includes('caching_sha2_password authentication plugin require node 11.6+')) self.skip();
455-
done(err);
456527
});
528+
conn.end();
529+
} catch (e) {
530+
throw e;
531+
}
532+
533+
try {
534+
const conn = await base.createConnection({
535+
user: 'cachingSha256User',
536+
password: 'password',
537+
cachingRsaPublicKey: rsaPublicKey
538+
});
539+
conn.end();
540+
} catch (e) {
541+
throw e;
542+
}
457543
});
458544

459545
it('cachingsha256 authentication plugin with public key retrieval', function (done) {

test/integration/test-pool-callback.js

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -938,4 +938,44 @@ describe('Pool callback', () => {
938938
});
939939
pool.end();
940940
});
941+
942+
it('pool execute timeout', function (done) {
943+
if (process.env.srv === 'maxscale' || process.env.srv === 'skysql-ha') this.skip(); //to avoid host being blocked
944+
this.timeout(10000);
945+
const pool = base.createPoolCallback({
946+
connectionLimit: 1,
947+
acquireTimeout: 400
948+
});
949+
assert.isFalse(pool.closed);
950+
pool.query('DO SLEEP(1)');
951+
pool.execute('SELECT 1', (err, res) => {
952+
pool.end();
953+
assert.isTrue(pool.closed);
954+
if (err) {
955+
assert.isTrue(err.message.includes('retrieve connection from pool timeout'));
956+
done();
957+
} else {
958+
done(new Error('must have thrown error'));
959+
}
960+
});
961+
});
962+
963+
it('pool batch timeout', function (done) {
964+
if (process.env.srv === 'maxscale' || process.env.srv === 'skysql-ha') this.skip(); //to avoid host being blocked
965+
this.timeout(10000);
966+
const pool = base.createPoolCallback({
967+
connectionLimit: 1,
968+
acquireTimeout: 400
969+
});
970+
pool.query('DO SLEEP(1)');
971+
pool.batch('SELECT ?', [[1]], (err, res) => {
972+
pool.end();
973+
if (err) {
974+
assert.isTrue(err.message.includes('retrieve connection from pool timeout'));
975+
done();
976+
} else {
977+
done(new Error('must have thrown error'));
978+
}
979+
});
980+
});
941981
});

test/integration/test-pool.js

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -344,6 +344,44 @@ describe('Pool', () => {
344344
}
345345
});
346346

347+
it('pool execute timeout', async function () {
348+
if (process.env.srv === 'maxscale' || process.env.srv === 'skysql-ha') this.skip(); //to avoid host being blocked
349+
this.timeout(10000);
350+
const pool = base.createPool({
351+
connectionLimit: 1,
352+
acquireTimeout: 400
353+
});
354+
assert.isFalse(pool.closed);
355+
pool.query('DO SLEEP(1)');
356+
try {
357+
await pool.execute('SELECT 1');
358+
throw new Error('must have thrown error');
359+
} catch (err) {
360+
assert.isTrue(err.message.includes('retrieve connection from pool timeout'));
361+
} finally {
362+
await pool.end();
363+
assert.isTrue(pool.closed);
364+
}
365+
});
366+
367+
it('pool batch timeout', async function () {
368+
if (process.env.srv === 'maxscale' || process.env.srv === 'skysql-ha') this.skip(); //to avoid host being blocked
369+
this.timeout(10000);
370+
const pool = base.createPool({
371+
connectionLimit: 1,
372+
acquireTimeout: 400
373+
});
374+
pool.query('DO SLEEP(1)');
375+
try {
376+
await pool.batch('SELECT 1', [[1]]);
377+
throw new Error('must have thrown error');
378+
} catch (err) {
379+
assert.isTrue(err.message.includes('retrieve connection from pool timeout'));
380+
} finally {
381+
await pool.end();
382+
}
383+
});
384+
347385
it('pool error event', async function () {
348386
if (process.env.srv === 'maxscale' || process.env.srv === 'skysql-ha') this.skip(); //to avoid host being blocked
349387
this.timeout(10000);

test/integration/test-typecast.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,12 @@ describe('TypeCast', () => {
2121
typeCast: changeCaseCast
2222
});
2323
assert.deepEqual(rows, [{ upper: 'BLABLA', lower: 'blabla', std: 'blaBLA', r: '1' }]);
24+
const rows2 = await shareConn.query({
25+
sql: "SELECT 'blaBLA' as upper, 'blaBLA' as lower, 'blaBLA' as std, '1' as r",
26+
typeCast: changeCaseCast,
27+
rowsAsArray: true
28+
});
29+
assert.deepEqual(rows2, [['BLABLA', 'blabla', 'blaBLA', '1']]);
2430
});
2531

2632
it('query level typecast function execute', async function () {

types/mariadb-tests.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,6 @@ async function testMisc(): Promise<void> {
120120
);
121121
console.log(rows[0].t === 2);
122122

123-
124123
try {
125124
rows = await connection.query({ sql: 'SELECT 1', nestTables: '_' });
126125
throw new Error('Should have thrown error!' + rows);

0 commit comments

Comments
 (0)