Skip to content

Commit

Permalink
Add end to end test for ACL inline update
Browse files Browse the repository at this point in the history
Signed-off-by: Dirkjan Bussink <[email protected]>
  • Loading branch information
dbussink committed Dec 9, 2024
1 parent 3329f06 commit c84400f
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 4 deletions.
1 change: 1 addition & 0 deletions go/test/endtoend/cluster/vtgate_process.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ func (vtgate *VtgateProcess) Setup() (err error) {
return err
}
vtgate.proc.Stderr = errFile
vtgate.ErrorLog = errFile.Name()

vtgate.proc.Env = append(vtgate.proc.Env, os.Environ()...)
vtgate.proc.Env = append(vtgate.proc.Env, DefaultVttestEnv)
Expand Down
39 changes: 35 additions & 4 deletions go/test/endtoend/vtgate/vschema/vschema_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,25 @@ package vschema

import (
"context"
"encoding/json"
"flag"
"fmt"
"os"
"path"
"testing"
"time"

"vitess.io/vitess/go/test/endtoend/utils"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

"vitess.io/vitess/go/mysql"
"vitess.io/vitess/go/test/endtoend/cluster"
"vitess.io/vitess/go/test/endtoend/utils"
)

var (
clusterInstance *cluster.LocalProcessCluster
configFile string
vtParams mysql.ConnParams
hostname = "localhost"
keyspaceName = "ks"
Expand All @@ -53,7 +57,6 @@ var (
)

func TestMain(m *testing.M) {
defer cluster.PanicHandler(nil)
flag.Parse()

exitcode, err := func() (int, error) {
Expand All @@ -66,7 +69,17 @@ func TestMain(m *testing.M) {
}

// List of users authorized to execute vschema ddl operations
clusterInstance.VtGateExtraArgs = []string{"--vschema_ddl_authorized_users=%", "--schema_change_signal=false"}
timeNow := time.Now().Unix()
configFile = path.Join(os.TempDir(), fmt.Sprintf("vtgate-config-%d.json", timeNow))
err := writeConfig(configFile, map[string]string{
"vschema_ddl_authorized_users": "%",
})
if err != nil {
return 1, err
}
defer os.Remove(configFile)

clusterInstance.VtGateExtraArgs = []string{fmt.Sprintf("--config-file=%s", configFile), "--schema_change_signal=false"}

// Start keyspace
keyspace := &cluster.Keyspace{
Expand Down Expand Up @@ -96,6 +109,15 @@ func TestMain(m *testing.M) {

}

func writeConfig(path string, cfg map[string]string) error {
file, err := os.Create(path)
if err != nil {
return err
}
defer file.Close()
return json.NewEncoder(file).Encode(cfg)
}

func TestVSchema(t *testing.T) {
defer cluster.PanicHandler(t)
ctx := context.Background()
Expand Down Expand Up @@ -138,4 +160,13 @@ func TestVSchema(t *testing.T) {

utils.AssertMatches(t, conn, "delete from vt_user", `[]`)

writeConfig(configFile, map[string]string{
"vschema_ddl_authorized_users": "",
})

require.EventuallyWithT(t, func(t *assert.CollectT) {
_, err = conn.ExecuteFetch("ALTER VSCHEMA DROP TABLE main", 1000, false)
assert.Error(t, err)
assert.ErrorContains(t, err, "is not authorized to perform vschema operations")
}, 5*time.Second, 100*time.Millisecond)
}

0 comments on commit c84400f

Please sign in to comment.