Skip to content

Commit

Permalink
[CONJS-256] changeUser can lead to error when using multi-authenticat…
Browse files Browse the repository at this point in the history
…ion and pipelining
  • Loading branch information
rusher committed May 25, 2023
1 parent ef85139 commit c4adb99
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
10 changes: 5 additions & 5 deletions lib/cmd/change-user.js
Expand Up @@ -7,15 +7,15 @@ const Capabilities = require('../const/capabilities');
const Ed25519PasswordAuth = require('./handshake/auth/ed25519-password-auth');
const NativePasswordAuth = require('./handshake/auth/native-password-auth');
const Collations = require('../const/collations');
const Handshake = require('./handshake/authentication');
const Authentication = require('./handshake/authentication');

/**
* send a COM_CHANGE_USER: resets the connection and re-authenticates with the given credentials
* see https://mariadb.com/kb/en/library/com_change_user/
*/
class ChangeUser extends Handshake {
constructor(cmdParam, connOpts, resolve, reject, addCommand) {
super(cmdParam, resolve, reject, () => {}, addCommand);
class ChangeUser extends Authentication {
constructor(cmdParam, connOpts, resolve, reject, getSocket) {
super(cmdParam, resolve, reject, () => {}, getSocket);
this.configAssign(connOpts, cmdParam.opts);
}

Expand Down Expand Up @@ -104,7 +104,7 @@ class ChangeUser extends Handshake {
}

out.flush();
this.onPacketReceive = this.handshakeResult;
this.plugin.onPacketReceive = this.handshakeResult.bind(this);
}

/**
Expand Down
5 changes: 3 additions & 2 deletions lib/connection.js
Expand Up @@ -1239,17 +1239,18 @@ class Connection extends EventEmitter {
reject(err);
return;
}

this.addCommand = this.addCommandEnable;
this.addCommand(
new ChangeUser(
cmdParam,
this.opts,
(res) => {
if (this.opts.pipelining) this.addCommand = this.addCommandEnablePipeline;
if (cmdParam.opts && cmdParam.opts.collation) this.opts.collation = cmdParam.opts.collation;
resolve(res);
},
this.authFailHandler.bind(this, reject),
this.addCommand.bind(this)
this.getSocket.bind(this)
)
);
}
Expand Down

0 comments on commit c4adb99

Please sign in to comment.