Skip to content
This repository was archived by the owner on Jan 5, 2023. It is now read-only.

Commit 6f59da6

Browse files
authored
Merge pull request #9 from TeachersPayTeachers/fallback-to-default-auth-plugin
fix: fallback to default auth plugin if not set
2 parents 7ffcfc8 + fb41809 commit 6f59da6

File tree

2 files changed

+28
-3
lines changed

2 files changed

+28
-3
lines changed

proto/auth.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -113,9 +113,12 @@ func (a *Auth) UnPack(payload []byte) error {
113113
if a.pluginName, err = buf.ReadStringNUL(); err != nil {
114114
return fmt.Errorf("auth.unpack: can't read pluginName")
115115
}
116-
}
117-
if a.pluginName != DefaultAuthPluginName {
118-
return fmt.Errorf("invalid authPluginName, got %v but only support %v", a.pluginName, DefaultAuthPluginName)
116+
if a.pluginName != DefaultAuthPluginName {
117+
return fmt.Errorf("invalid authPluginName, got '%s' but only support %s", a.pluginName, DefaultAuthPluginName)
118+
}
119+
} else {
120+
// Allow fallback to default auth plugin
121+
a.pluginName = DefaultAuthPluginName
119122
}
120123
return nil
121124
}

proto/auth_test.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,28 @@ func TestAuthWithoutSecure(t *testing.T) {
198198
assert.Equal(t, want, got)
199199
}
200200

201+
func TestAuthWithoutPluginAuth(t *testing.T) {
202+
want := NewAuth()
203+
want.charset = 0x02
204+
want.authResponseLen = 20
205+
want.clientFlags = DefaultClientCapability ^ sqldb.CLIENT_PLUGIN_AUTH
206+
want.authResponse = nativePassword("sbtest", DefaultSalt)
207+
want.user = "sbtest"
208+
want.database = "test_db"
209+
210+
got := NewAuth()
211+
err := got.UnPack(want.Pack(
212+
DefaultClientCapability,
213+
0x02,
214+
"sbtest",
215+
"sbtest",
216+
DefaultSalt,
217+
"",
218+
))
219+
assert.Nil(t, err)
220+
assert.Equal(t, got.pluginName, DefaultAuthPluginName)
221+
}
222+
201223
func TestAuthUnPackError(t *testing.T) {
202224
capabilityFlags := DefaultClientCapability
203225
capabilityFlags |= sqldb.CLIENT_PROTOCOL_41

0 commit comments

Comments
 (0)