Skip to content

Commit

Permalink
Fail loading an ACL config if the provided file is empty and enforceT…
Browse files Browse the repository at this point in the history
…ableACLConfig is true (#17274)

Signed-off-by: garfthoffman <109185460+garfthoffman@users.noreply.github.com>
Signed-off-by: Mohamed Hamza <mhamza15@github.com>
Co-authored-by: Mohamed Hamza <mhamza15@github.com>
  • Loading branch information
garfthoffman and mhamza15 authored Feb 21, 2025
1 parent 0a6f982 commit a9192fd
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
4 changes: 4 additions & 0 deletions go/vt/tableacl/tableacl.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,10 @@ func (tacl *tableACL) init(configFile string, aclCB func()) error {
log.Errorf("unable to read tableACL config file: %v Error: %v", configFile, err)
return err
}
if len(data) == 0 {
return errors.New("tableACL config file is empty")
}

config := &tableaclpb.Config{}
if err := config.UnmarshalVT(data); err != nil {
// try to parse tableacl as json file
Expand Down
14 changes: 14 additions & 0 deletions go/vt/tableacl/tableacl_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"reflect"
"testing"

"github.com/stretchr/testify/require"
"google.golang.org/protobuf/proto"

"vitess.io/vitess/go/vt/tableacl/acl"
Expand Down Expand Up @@ -74,6 +75,19 @@ func TestInitWithValidConfig(t *testing.T) {
}
}

func TestInitWithEmptyConfig(t *testing.T) {
tacl := tableACL{factory: &simpleacl.Factory{}}
f, err := os.CreateTemp("", "tableacl")
require.NoError(t, err)

defer os.Remove(f.Name())
err = f.Close()
require.NoError(t, err)

err = tacl.init(f.Name(), func() {})
require.Error(t, err)
}

func TestInitFromProto(t *testing.T) {
tacl := tableACL{factory: &simpleacl.Factory{}}
readerACL := tacl.Authorized("my_test_table", READER)
Expand Down

0 comments on commit a9192fd

Please sign in to comment.