Skip to content

Commit 343ff28

Browse files
Merge branch 'unstable' into feature/3351-cf-add-ci-fix
2 parents cb91f43 + 47e0893 commit 343ff28

2 files changed

Lines changed: 33 additions & 3 deletions

File tree

src/commands/cmd_replication.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -483,9 +483,9 @@ class CommandWait : public Commander,
483483
};
484484

485485
REDIS_REGISTER_COMMANDS(Replication, MakeCmdAttr<CommandReplConf>("replconf", -3, "read-only no-script", NO_KEY),
486-
MakeCmdAttr<CommandPSync>("psync", -2, "read-only no-multi no-script", NO_KEY),
487-
MakeCmdAttr<CommandFetchMeta>("_fetch_meta", 1, "read-only no-multi no-script", NO_KEY),
488-
MakeCmdAttr<CommandFetchFile>("_fetch_file", 2, "read-only no-multi no-script", NO_KEY),
486+
MakeCmdAttr<CommandPSync>("psync", -2, "read-only no-multi no-script admin", NO_KEY),
487+
MakeCmdAttr<CommandFetchMeta>("_fetch_meta", 1, "read-only no-multi no-script admin", NO_KEY),
488+
MakeCmdAttr<CommandFetchFile>("_fetch_file", 2, "read-only no-multi no-script admin", NO_KEY),
489489
MakeCmdAttr<CommandDBName>("_db_name", 1, "read-only no-multi", NO_KEY),
490490
MakeCmdAttr<CommandWait>("wait", 3, "read-only no-multi no-script blocking", NO_KEY), )
491491

tests/gocase/integration/replication/replication_test.go

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,36 @@ func TestReplicationWithHostname(t *testing.T) {
117117
})
118118
}
119119

120+
func TestReplicationTransferCommandsRequireAdminPermission(t *testing.T) {
121+
srv := util.StartServer(t, map[string]string{
122+
"requirepass": "admin",
123+
})
124+
defer srv.Close()
125+
126+
ctx := context.Background()
127+
adminClient := srv.NewClientWithOption(&redis.Options{Password: "admin"})
128+
defer func() { require.NoError(t, adminClient.Close()) }()
129+
130+
require.NoError(t, adminClient.Do(ctx, "NAMESPACE", "ADD", "test_ns", "test_token").Err())
131+
132+
userClient := srv.NewClientWithOption(&redis.Options{Password: "test_token"})
133+
defer func() { require.NoError(t, userClient.Close()) }()
134+
135+
for _, cmd := range []struct {
136+
name string
137+
args []interface{}
138+
}{
139+
{name: "PSYNC", args: []interface{}{"1"}},
140+
{name: "_FETCH_META"},
141+
{name: "_FETCH_FILE", args: []interface{}{"MANIFEST-000001"}},
142+
} {
143+
t.Run(cmd.name, func(t *testing.T) {
144+
args := append([]interface{}{cmd.name}, cmd.args...)
145+
require.ErrorContains(t, userClient.Do(ctx, args...).Err(), "admin permission required to perform the command")
146+
})
147+
}
148+
}
149+
120150
func TestReplicationLoading(t *testing.T) {
121151
t.Parallel()
122152
srvA := util.StartServer(t, map[string]string{})

0 commit comments

Comments
 (0)