Skip to content

Commit 43cc679

Browse files
committed
Update to ensure we only request the password once
also update the caching test to allow for the fact that we request the password once on every auth attempt
1 parent 5f26fd6 commit 43cc679

File tree

3 files changed

+7
-6
lines changed

3 files changed

+7
-6
lines changed

server/auth.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,9 @@ func (c *Conn) compareAuthData(authPluginName string, clientAuthData []byte) err
6060
}
6161

6262
func (c *Conn) acquirePassword() error {
63+
if c.credential.password != "" {
64+
return nil
65+
}
6366
credential, found, err := c.credentialProvider.GetCredential(c.user)
6467
if err != nil {
6568
return err

server/caching_sha2_cache_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ func (s *cacheTestSuite) TestCache() {
147147
s.db.SetMaxIdleConns(4)
148148
s.runSelect()
149149
got = s.credProvider.(*RemoteThrottleProvider).getCredCallCount.Load()
150-
require.Equal(s.T(), int64(1), got)
150+
require.Equal(s.T(), int64(2), got)
151151

152152
if s.db != nil {
153153
s.db.Close()

server/handshake_resp.go

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -200,14 +200,12 @@ func (c *Conn) handlePublicKeyRetrieval(authData []byte) (bool, error) {
200200
func (c *Conn) handleAuthMatch() (bool, error) {
201201
// if the client responds the handshake with a different auth method, the server will send the AuthSwitchRequest packet
202202
// to the client to ask the client to switch.
203-
credential, _, err := c.credentialProvider.GetCredential(c.user)
204-
if err != nil {
203+
if err := c.acquirePassword(); err != nil {
205204
return false, err
206205
}
207-
c.credential = credential
208206

209-
if c.authPluginName != credential.authPluginName {
210-
if err := c.writeAuthSwitchRequest(credential.authPluginName); err != nil {
207+
if c.authPluginName != c.credential.authPluginName {
208+
if err := c.writeAuthSwitchRequest(c.credential.authPluginName); err != nil {
211209
return false, err
212210
}
213211
// handle AuthSwitchResponse

0 commit comments

Comments
 (0)