Skip to content

Commit f63b937

Browse files
authored
SOLR-16780: Prevent ZK subcommands from being run without the bin/solr zk prefix (#2297)
* Prevent zk subcommands to being run without the zk prefix!
1 parent c5709bd commit f63b937

File tree

3 files changed

+14
-3
lines changed

3 files changed

+14
-3
lines changed

solr/bin/solr

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -873,6 +873,12 @@ if [[ "$SCRIPT_CMD" == "delete" ]]; then
873873
exit $?
874874
fi
875875

876+
# Prevent any zk subcommands from going through with out invoking zk command
877+
if [[ "$SCRIPT_CMD" == "upconfig" || $SCRIPT_CMD == "downconfig" || $SCRIPT_CMD == "cp" || $SCRIPT_CMD == "rm" || $SCRIPT_CMD == "mv" || $SCRIPT_CMD == "ls" || $SCRIPT_CMD == "mkroot" ]]; then
878+
print_short_zk_usage "You must invoke this subcommand using the zk command. bin/solr zk $SCRIPT_CMD."
879+
exit $?
880+
fi
881+
876882
ZK_RECURSE=false
877883
# Zookeeper file maintenance (upconfig, downconfig, files up/down etc.)
878884
# It's a little clumsy to have the parsing go round and round for upconfig and downconfig, but that's

solr/bin/solr.cmd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,7 @@ IF "%SCRIPT_CMD%"=="stop" goto stop_usage
298298
IF "%SCRIPT_CMD%"=="healthcheck" goto run_solrcli
299299
IF "%SCRIPT_CMD%"=="create" goto run_solrcli
300300
IF "%SCRIPT_CMD%"=="delete" goto run_solrcli
301-
IF "%SCRIPT_CMD%"=="zk" goto zk_usage
301+
IF "%SCRIPT_CMD%"=="zk" goto zk_usage
302302
IF "%SCRIPT_CMD%"=="auth" goto auth_usage
303303
IF "%SCRIPT_CMD%"=="status" goto run_solrcli
304304
IF "%SCRIPT_CMD%"=="postlogs" goto run_solrcli

solr/packaging/test/test_zk.bats

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,11 @@ teardown() {
3636
save_home_on_failure
3737
}
3838

39+
@test "running subcommands with zk is prevented" {
40+
run solr ls / -z localhost:${ZK_PORT}
41+
assert_output --partial "You must invoke this subcommand using the zk command"
42+
}
43+
3944
@test "listing out files" {
4045
sleep 1
4146
run solr zk ls / -z localhost:${ZK_PORT}
@@ -44,8 +49,8 @@ teardown() {
4449

4550
@test "copying files around" {
4651
touch myfile.txt
47-
# Umm, what is solr cp? It's like bin/solr zk cp but not?
48-
run solr cp -src myfile.txt -dst zk:/myfile.txt -z localhost:${ZK_PORT}
52+
53+
run solr zk cp myfile.txt zk:/myfile.txt -z localhost:${ZK_PORT}
4954
assert_output --partial "Copying from 'myfile.txt' to 'zk:/myfile.txt'. ZooKeeper at localhost:${ZK_PORT}"
5055
sleep 1
5156
run solr zk ls / -z localhost:${ZK_PORT}

0 commit comments

Comments
 (0)