Skip to content

Commit c10bd8c

Browse files
committed
[CONJS-330] caching_sha2_password: avoid requiring RSA key pair when connecting via Unix socket
1 parent 46d2199 commit c10bd8c

File tree

2 files changed

+53
-14
lines changed

2 files changed

+53
-14
lines changed

.github/workflows/ci.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ jobs:
8888
TEST_DB_SERVER_CERT: ${{ matrix.db-type == 'container' && './.github/workflows/certs/ca_server.crt' || '' }}
8989
DB_VERSION: ${{ matrix.db-tag }}
9090
TEST_TRACE: 'true'
91+
LOCAL_SOCKET_AVAILABLE: ${{ steps.setup-env.outputs.database-type }}
9192

9293
- name: Run Tests deno
9394
if: ${{ matrix.deno }}
@@ -99,6 +100,7 @@ jobs:
99100
TEST_DB_SERVER_CERT: ${{ matrix.db-type == 'container' && './.github/workflows/certs/ca_server.crt' || '' }}
100101
DB_VERSION: ${{ matrix.db-tag }}
101102
TEST_TRACE: 'true'
103+
LOCAL_SOCKET_AVAILABLE: ${{ steps.setup-env.outputs.database-type }}
102104

103105
- name: Download Codecov uploader
104106
if: ${{ !matrix.deno }}

test/integration/auth-plugin.test.js

Lines changed: 51 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ describe.concurrent('authentication plugin', () => {
4141
await shareConn.query("DROP USER IF EXISTS 'cachingSha256User2'" + getHostSuffix()).catch((e) => {});
4242
await shareConn.query("DROP USER IF EXISTS 'cachingSha256User3'" + getHostSuffix()).catch((e) => {});
4343
await shareConn.query("DROP USER IF EXISTS 'cachingSha256User4'" + getHostSuffix()).catch((e) => {});
44+
await shareConn.query("DROP USER IF EXISTS 'cachingSha256User5'" + getHostSuffix()).catch((e) => {});
4445

4546
if (!shareConn.info.isMariaDB()) {
4647
if (shareConn.info.hasMinVersion(8, 0, 0)) {
@@ -65,6 +66,10 @@ describe.concurrent('authentication plugin', () => {
6566
"CREATE USER 'cachingSha256User4'" + getHostSuffix() + " IDENTIFIED WITH caching_sha2_password BY 'password'"
6667
);
6768
await shareConn.query("GRANT ALL PRIVILEGES ON *.* TO 'cachingSha256User4'" + getHostSuffix());
69+
await shareConn.query(
70+
"CREATE USER 'cachingSha256User5'" + getHostSuffix() + " IDENTIFIED WITH caching_sha2_password BY 'password'"
71+
);
72+
await shareConn.query("GRANT ALL PRIVILEGES ON *.* TO 'cachingSha256User5'" + getHostSuffix());
6873
} else {
6974
await shareConn.query("CREATE USER 'sha256User'" + getHostSuffix());
7075
await shareConn.query(
@@ -470,7 +475,7 @@ describe.concurrent('authentication plugin', () => {
470475
});
471476

472477
test('cachingsha256 authentication plugin', async ({ skip }) => {
473-
if (!rsaPublicKey || shareConn.info.isMariaDB() || !shareConn.info.hasMinVersion(8, 0, 0)) {
478+
if (!cachingRsaPublicKey || shareConn.info.isMariaDB() || !shareConn.info.hasMinVersion(8, 0, 0)) {
474479
skip();
475480
return;
476481
}
@@ -492,7 +497,7 @@ describe.concurrent('authentication plugin', () => {
492497
}
493498

494499
const filePath = path.join(os.tmpdir(), 'RSA_tmp_file2.txt');
495-
fs.writeFileSync(filePath, rsaPublicKey);
500+
fs.writeFileSync(filePath, cachingRsaPublicKey);
496501
try {
497502
const conn = await createConnection({
498503
user: 'cachingSha256User4',
@@ -514,7 +519,7 @@ describe.concurrent('authentication plugin', () => {
514519
try {
515520
const conn = await createConnection({
516521
user: 'cachingSha256User',
517-
cachingRsaPublicKey: rsaPublicKey
522+
cachingRsaPublicKey: cachingRsaPublicKey
518523
});
519524
await conn.end();
520525
throw new Error('must have thrown exception');
@@ -530,7 +535,7 @@ describe.concurrent('authentication plugin', () => {
530535
const conn = await createConnection({
531536
user: 'cachingSha256User',
532537
password: 'password',
533-
cachingRsaPublicKey: rsaPublicKey
538+
cachingRsaPublicKey: cachingRsaPublicKey
534539
});
535540
await conn.end();
536541
} catch (e) {
@@ -541,7 +546,7 @@ describe.concurrent('authentication plugin', () => {
541546
const conn = await createConnection({
542547
user: 'cachingSha256User',
543548
password: 'password',
544-
cachingRsaPublicKey: rsaPublicKey
549+
cachingRsaPublicKey: cachingRsaPublicKey
545550
});
546551
await conn.end();
547552
} catch (e) {
@@ -554,15 +559,6 @@ describe.concurrent('authentication plugin', () => {
554559
skip();
555560
return;
556561
}
557-
// request files since 5.7.40 / 8.0.31 fails when requesting public key
558-
if (
559-
!shareConn.info.isMariaDB() &&
560-
((!shareConn.info.hasMinVersion(8, 0, 0) && shareConn.info.hasMinVersion(5, 7, 40)) ||
561-
shareConn.info.hasMinVersion(8, 0, 31))
562-
) {
563-
skip();
564-
return;
565-
}
566562

567563
try {
568564
const conn = await createConnection({
@@ -704,4 +700,45 @@ describe.concurrent('authentication plugin', () => {
704700
await conn.end();
705701
}
706702
});
703+
704+
test('cachingsha256 authentication plugin via named pipe', async ({ skip }) => {
705+
if (process.platform !== 'win32') return skip();
706+
if (!process.env.LOCAL_SOCKET_AVAILABLE || isMaxscale()) return skip();
707+
if (!cachingRsaPublicKey || shareConn.info.isMariaDB() || !shareConn.info.hasMinVersion(8, 0, 0)) return skip();
708+
if (Conf.baseConfig.host !== 'localhost' && Conf.baseConfig.host !== 'mariadb.example.com') return skip();
709+
710+
const res = await shareConn.query('select @@version_compile_os,@@socket soc');
711+
try {
712+
const conn = await createConnection({
713+
user: 'cachingSha256User5',
714+
password: 'password',
715+
socketPath: '\\\\.\\pipe\\' + res[0].soc,
716+
cachingRsaPublicKey
717+
});
718+
conn.end();
719+
} catch (err) {
720+
if (err.message.includes('caching_sha2_password authentication plugin require node 11.6+')) self.skip();
721+
throw err;
722+
}
723+
});
724+
725+
test('cachingsha256 authentication plugin via Unix socket', async ({ skip }) => {
726+
if (process.platform === 'win32') return skip();
727+
if (shareConn.info.isMariaDB() || !shareConn.info.hasMinVersion(8, 0, 0)) return skip();
728+
if (!process.env.LOCAL_SOCKET_AVAILABLE) return skip();
729+
if (Conf.baseConfig.host !== 'localhost' && Conf.baseConfig.host !== 'mariadb.example.com') return skip();
730+
731+
const res = await shareConn.query('select @@version_compile_os,@@socket soc');
732+
try {
733+
const conn = await createConnection({
734+
user: 'cachingSha256User5',
735+
password: 'password',
736+
socketPath: res[0].soc
737+
});
738+
conn.end();
739+
} catch (err) {
740+
if (err.message.includes('caching_sha2_password authentication plugin require node 11.6+')) self.skip();
741+
throw err;
742+
}
743+
});
707744
});

0 commit comments

Comments
 (0)