Skip to content

Commit

Permalink
Add error handling in MySQL auth plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
ohkinozomu committed Jul 27, 2024
1 parent 9c7e011 commit 6754444
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
12 changes: 10 additions & 2 deletions plugin/auth/mysql/mysql.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,16 @@ func (a *Auth) Init(config any) error {
a.config.Auth.PasswordColumn, a.config.Auth.AllowColumn, a.config.Auth.Table, a.config.Auth.UserColumn)
aclSql := fmt.Sprintf("select %s, %s from %s where %s=?",
a.config.Acl.TopicColumn, a.config.Acl.AccessColumn, a.config.Acl.Table, a.config.Acl.UserColumn)
a.authStmt, _ = sqlxDB.Preparex(authSql)
a.aclStmt, _ = sqlxDB.Preparex(aclSql)
a.authStmt, err = sqlxDB.Preparex(authSql)
if err != nil {
a.Log.Error("Unable to create prepared statement for auth-sql", "authSql", authSql)
return err
}
a.aclStmt, err = sqlxDB.Preparex(aclSql)
if err != nil {
a.Log.Error("Unable to create prepared statement for acl-sql", "aclStmt", aclSql)
return err
}
a.db = sqlxDB
return nil
}
Expand Down
6 changes: 3 additions & 3 deletions plugin/auth/mysql/mysql_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ var (
pkc = packets.Packet{Connect: packets.ConnectParams{Password: []byte("123456")}}
)

func teardown(a *Auth, t *testing.T) {
func teardown(a *Auth) {
if a.db != nil {
a.Stop()
}
Expand Down Expand Up @@ -106,7 +106,7 @@ func TestOnConnectAuthenticate(t *testing.T) {
t.SkipNow()
}
a := newAuth(t)
defer teardown(a, t)
defer teardown(a)
result := a.OnConnectAuthenticate(client, pkc)
require.Equal(t, true, result)
}
Expand All @@ -116,7 +116,7 @@ func TestOnACLCheck(t *testing.T) {
t.SkipNow()
}
a := newAuth(t)
defer teardown(a, t)
defer teardown(a)
topic := "topictest/1"
topic2 := "topictest/2"
result := a.OnACLCheck(client, topic, true) //publish
Expand Down

0 comments on commit 6754444

Please sign in to comment.