Skip to content

Commit

Permalink
backend: fix authenticator tests (#296)
Browse files Browse the repository at this point in the history
  • Loading branch information
djshow832 authored May 31, 2023
1 parent df69e53 commit 98555ee
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 21 deletions.
36 changes: 18 additions & 18 deletions pkg/proxy/backend/authenticator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,50 +27,50 @@ func TestUnsupportedCapability(t *testing.T) {
cfgs := [][]cfgOverrider{
{
func(cfg *testConfig) {
cfg.clientConfig.capability = defaultTestClientCapability & ^pnet.ClientSSL
cfg.clientConfig.capability &= ^pnet.ClientSSL
},
func(cfg *testConfig) {
cfg.clientConfig.capability = defaultTestClientCapability | pnet.ClientSSL
cfg.clientConfig.capability |= pnet.ClientSSL
},
},
{
func(cfg *testConfig) {
cfg.backendConfig.capability = defaultTestBackendCapability & ^pnet.ClientSSL
cfg.backendConfig.capability &= ^pnet.ClientSSL
},
func(cfg *testConfig) {
cfg.backendConfig.capability = defaultTestBackendCapability | pnet.ClientSSL
cfg.backendConfig.capability |= pnet.ClientSSL
},
},
{
func(cfg *testConfig) {
cfg.backendConfig.capability = defaultTestBackendCapability & ^pnet.ClientDeprecateEOF
cfg.backendConfig.capability &= ^pnet.ClientDeprecateEOF
},
func(cfg *testConfig) {
cfg.backendConfig.capability = defaultTestBackendCapability | pnet.ClientDeprecateEOF
cfg.backendConfig.capability |= pnet.ClientDeprecateEOF
},
},
{
func(cfg *testConfig) {
cfg.clientConfig.capability = defaultTestClientCapability & ^pnet.ClientProtocol41
cfg.clientConfig.capability &= ^pnet.ClientProtocol41
},
func(cfg *testConfig) {
cfg.clientConfig.capability = defaultTestClientCapability | pnet.ClientProtocol41
cfg.clientConfig.capability |= pnet.ClientProtocol41
},
},
{
func(cfg *testConfig) {
cfg.backendConfig.capability = defaultTestClientCapability & ^pnet.ClientPSMultiResults
cfg.backendConfig.capability &= ^pnet.ClientPSMultiResults
},
func(cfg *testConfig) {
cfg.backendConfig.capability = defaultTestClientCapability | pnet.ClientPSMultiResults
cfg.backendConfig.capability |= pnet.ClientPSMultiResults
},
},
{
func(cfg *testConfig) {
cfg.clientConfig.capability = defaultTestClientCapability & ^pnet.ClientPSMultiResults
cfg.clientConfig.capability &= ^pnet.ClientPSMultiResults
},
func(cfg *testConfig) {
cfg.clientConfig.capability = defaultTestClientCapability | pnet.ClientPSMultiResults
cfg.clientConfig.capability |= pnet.ClientPSMultiResults
},
},
}
Expand Down Expand Up @@ -151,27 +151,27 @@ func TestCapability(t *testing.T) {
cfgs := [][]cfgOverrider{
{
func(cfg *testConfig) {
cfg.clientConfig.capability = defaultTestClientCapability & ^pnet.ClientConnectWithDB
cfg.clientConfig.capability &= ^pnet.ClientConnectWithDB
},
func(cfg *testConfig) {
cfg.clientConfig.capability = defaultTestClientCapability | pnet.ClientConnectWithDB
cfg.clientConfig.capability |= pnet.ClientConnectWithDB
},
},
{
func(cfg *testConfig) {
cfg.clientConfig.capability = defaultTestClientCapability & ^pnet.ClientConnectAttrs
cfg.clientConfig.capability &= ^pnet.ClientConnectAttrs
},
func(cfg *testConfig) {
cfg.clientConfig.capability = defaultTestClientCapability | pnet.ClientConnectAttrs
cfg.clientConfig.capability |= pnet.ClientConnectAttrs
cfg.clientConfig.attrs = map[string]string{"key": "value"}
},
},
{
func(cfg *testConfig) {
cfg.clientConfig.capability = defaultTestClientCapability & ^pnet.ClientSecureConnection
cfg.clientConfig.capability &= ^pnet.ClientSecureConnection
},
func(cfg *testConfig) {
cfg.clientConfig.capability = defaultTestClientCapability | pnet.ClientSecureConnection
cfg.clientConfig.capability |= pnet.ClientSecureConnection
},
},
}
Expand Down
13 changes: 10 additions & 3 deletions pkg/proxy/backend/testsuite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,10 @@ func getCfgCombinations(cfgs [][]cfgOverrider) [][]cfgOverrider {
// Append the cfg to each of the existing overrider list.
for _, cfg := range cfgList {
for _, o := range cfgOverriders {
newOverriders = append(newOverriders, append(o, cfg))
newOverrider := make([]cfgOverrider, 0, len(o)+1)
newOverrider = append(newOverrider, o...)
newOverrider = append(newOverrider, cfg)
newOverriders = append(newOverriders, newOverrider)
}
}
cfgOverriders = newOverriders
Expand Down Expand Up @@ -187,9 +190,13 @@ func (ts *testSuite) authenticateFirstTime(t *testing.T, c checker) {
// Check the data received by client equals to the data sent from the server and vice versa.
require.Equal(t, ts.mb.authSucceed, ts.mc.authSucceed)
require.Equal(t, ts.mc.username, ts.mb.username)
require.Equal(t, ts.mc.dbName, ts.mb.db)
if ts.mc.capability&pnet.ClientConnectWithDB > 0 {
require.Equal(t, ts.mc.dbName, ts.mb.db)
}
require.Equal(t, ts.mc.authData, ts.mb.authData)
require.Equal(t, ts.mc.attrs, ts.mb.attrs)
if ts.mc.capability&pnet.ClientConnectAttrs > 0 {
require.Equal(t, ts.mc.attrs, ts.mb.attrs)
}
}
}

Expand Down

0 comments on commit 98555ee

Please sign in to comment.