Skip to content

Commit e0df29c

Browse files
committed
Make sure to send using password: NO in auth switches as well
1 parent c20a99a commit e0df29c

File tree

2 files changed

+49
-0
lines changed

2 files changed

+49
-0
lines changed

server/auth_switch_response.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,12 @@ func (c *Conn) handleCachingSha2PasswordFullAuth(authData []byte) error {
7171
}
7272

7373
func (c *Conn) checkSha2CacheCredentials(clientAuthData []byte, credential Credential) error {
74+
if len(clientAuthData) == 0 {
75+
if credential.Password == "" {
76+
return nil
77+
}
78+
return ErrAccessDeniedNoPassword
79+
}
7480
match, err := auth.CheckHashingPassword([]byte(credential.Password), string(clientAuthData), mysql.AUTH_CACHING_SHA2_PASSWORD)
7581
if match && err == nil {
7682
return nil
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
package server
2+
3+
import (
4+
"testing"
5+
6+
"github.com/stretchr/testify/require"
7+
)
8+
9+
func TestCheckSha2CacheCredentials_EmptyPassword(t *testing.T) {
10+
tests := []struct {
11+
name string
12+
clientAuthData []byte
13+
serverPassword string
14+
wantErr error
15+
}{
16+
{
17+
name: "empty client auth, empty server password",
18+
clientAuthData: []byte{},
19+
serverPassword: "",
20+
wantErr: nil,
21+
},
22+
{
23+
name: "empty client auth, non-empty server password",
24+
clientAuthData: []byte{},
25+
serverPassword: "secret",
26+
wantErr: ErrAccessDeniedNoPassword,
27+
},
28+
}
29+
30+
for _, tt := range tests {
31+
t.Run(tt.name, func(t *testing.T) {
32+
c := &Conn{
33+
credential: Credential{Password: tt.serverPassword},
34+
}
35+
err := c.checkSha2CacheCredentials(tt.clientAuthData, c.credential)
36+
if tt.wantErr == nil {
37+
require.NoError(t, err)
38+
} else {
39+
require.ErrorIs(t, err, tt.wantErr)
40+
}
41+
})
42+
}
43+
}

0 commit comments

Comments
 (0)