@@ -25,6 +25,7 @@ import (
2525 "testing"
2626
2727 "github.com/apache/kvrocks/tests/gocase/util"
28+ "github.com/redis/go-redis/v9"
2829 "github.com/stretchr/testify/require"
2930)
3031
@@ -65,3 +66,30 @@ func TestReset(t *testing.T) {
6566 require .Equal (t , rdb .Do (ctx , "subscribe" , "chan2" ).Val (), []interface {}{"subscribe" , "chan2" , (int64 )(1 )})
6667 })
6768}
69+
70+ func TestResetAdminOnly (t * testing.T ) {
71+ srv := util .StartServer (t , map [string ]string {
72+ "requirepass" : "admin" ,
73+ })
74+ defer srv .Close ()
75+
76+ ctx := context .Background ()
77+
78+ t .Run ("RESET command with namespace token should be forbidden" , func (t * testing.T ) {
79+ adminClient := srv .NewClientWithOption (& redis.Options {
80+ Password : "admin" ,
81+ })
82+ defer func () { require .NoError (t , adminClient .Close ()) }()
83+
84+ require .NoError (t , adminClient .Do (ctx , "NAMESPACE" , "ADD" , "test_ns" , "test_token" ).Err ())
85+ require .NoError (t , adminClient .Do (ctx , "RESET" ).Err ())
86+
87+ tokenClient := srv .NewClientWithOption (& redis.Options {
88+ Password : "test_token" ,
89+ })
90+ defer func () { require .NoError (t , tokenClient .Close ()) }()
91+
92+ r := tokenClient .Do (ctx , "RESET" )
93+ require .ErrorContains (t , r .Err (), "admin permission required to perform the command" )
94+ })
95+ }
0 commit comments