Skip to content

Commit 066999f

Browse files
committed
[CONJS-336] connection attribute _server_host send host, but IP resulting of name resolution
1 parent 331e95b commit 066999f

File tree

5 files changed

+21
-10
lines changed

5 files changed

+21
-10
lines changed

lib/cmd/change-user.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import packageJson from '../../package.json' with { type: 'json' };
1919
*/
2020
class ChangeUser extends Authentication {
2121
constructor(cmdParam, connOpts, resolve, reject, getSocket) {
22-
super(cmdParam, resolve, reject, () => {}, getSocket);
22+
super(cmdParam, connOpts.host, resolve, reject, () => {}, getSocket);
2323
this.configAssign(connOpts, cmdParam.opts);
2424
}
2525

lib/cmd/handshake/auth/handshake.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,15 @@ const driverVersion = packageJson.version;
1919
* Handshake response
2020
*/
2121
class Handshake extends PluginAuth {
22-
constructor(auth, getSocket, multiAuthResolver, reject) {
22+
constructor(auth, host, getSocket, multiAuthResolver, reject) {
2323
super(null, multiAuthResolver, reject);
2424
this.sequenceNo = 0;
2525
this.compressSequenceNo = 0;
2626
this.auth = auth;
2727
this.getSocket = getSocket;
2828
this.counter = 0;
2929
this.onPacketReceive = this.parseHandshakeInit;
30+
this.host = host;
3031
}
3132

3233
start(out, opts, info) {}
@@ -160,10 +161,9 @@ class Handshake extends PluginAuth {
160161
Handshake.writeAttribute(out, '_client_version', encoding);
161162
Handshake.writeAttribute(out, driverVersion, encoding);
162163

163-
const address = cmd.getSocket().address().address;
164-
if (address) {
164+
if (this.host) {
165165
Handshake.writeAttribute(out, '_server_host', encoding);
166-
Handshake.writeAttribute(out, address, encoding);
166+
Handshake.writeAttribute(out, this.host, encoding);
167167
}
168168

169169
Handshake.writeAttribute(out, '_os', encoding);

lib/cmd/handshake/authentication.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,12 @@ const authenticationPlugins = {
3636
* see https://mariadb.com/kb/en/library/1-connecting-connecting/
3737
*/
3838
class Authentication extends Command {
39-
constructor(cmdParam, resolve, reject, _createSecureContext, getSocket) {
39+
constructor(cmdParam, host, resolve, reject, _createSecureContext, getSocket) {
4040
super(cmdParam, resolve, reject);
4141
this.cmdParam = cmdParam;
4242
this._createSecureContext = _createSecureContext;
4343
this.getSocket = getSocket;
44-
this.plugin = new Handshake(this, getSocket, this.handshakeResult, reject);
44+
this.plugin = new Handshake(this, host, getSocket, this.handshakeResult, reject);
4545
}
4646

4747
onPacketReceive(packet, out, opts, info) {

lib/connection.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@ class Connection extends EventEmitter {
134134
// Add a handshake to msg queue
135135
const authentication = new Authentication(
136136
authenticationParam,
137+
conn.opts.host,
137138
conn.authSucceedHandler.bind(conn),
138139
conn.authFailHandler.bind(conn),
139140
conn.createSecureContext.bind(conn),

test/integration/auth-plugin.test.js

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -645,15 +645,25 @@ describe.concurrent('authentication plugin', () => {
645645
return;
646646
}
647647

648+
let strictPasswordValidation;
649+
try {
650+
const res = await shareConn.query('SELECT @@global.strict_password_validation');
651+
strictPasswordValidation = res[0]['@@global.strict_password_validation'] === 1;
652+
} catch (e) {
653+
strictPasswordValidation = false;
654+
}
655+
648656
await shareConn.query('drop user verifParsec' + getHostSuffix()).catch(() => {});
649657
await shareConn.query(
650658
'CREATE USER verifParsec' + getHostSuffix() + " IDENTIFIED VIA parsec USING PASSWORD('MySup8%rPassw@ord')"
651659
);
652660
await shareConn.query('GRANT SELECT on `' + Conf.baseConfig.database + '`.* to verifParsec' + getHostSuffix());
653661

654-
await shareConn.query('drop user verifParsec2' + getHostSuffix()).catch(() => {});
655-
await shareConn.query('CREATE USER verifParsec2' + getHostSuffix() + " IDENTIFIED VIA parsec USING PASSWORD('')");
656-
await shareConn.query('GRANT SELECT on `' + Conf.baseConfig.database + '`.* to verifParsec2' + getHostSuffix());
662+
if (!strictPasswordValidation) {
663+
await shareConn.query('drop user verifParsec2' + getHostSuffix()).catch(() => {});
664+
await shareConn.query('CREATE USER verifParsec2' + getHostSuffix() + " IDENTIFIED VIA parsec USING PASSWORD('')");
665+
await shareConn.query('GRANT SELECT on `' + Conf.baseConfig.database + '`.* to verifParsec2' + getHostSuffix());
666+
}
657667

658668
let conn = await createConnection({
659669
user: 'verifParsec',

0 commit comments

Comments
 (0)