diff --git a/gpMgmt/bin/Makefile b/gpMgmt/bin/Makefile index 8a4ba000f1977e556e4cbc58997fdaebd38440f8..bd42bf822dab95c6a91477713698923c794f5634 100644 --- a/gpMgmt/bin/Makefile +++ b/gpMgmt/bin/Makefile @@ -220,8 +220,13 @@ unitdevel: PYTHONPATH=$(SERVER_SRC):$(SERVER_SBIN):$(PYTHONPATH):$(PYTHONSRC_INSTALL_PYTHON_PATH):$(SRC)/ext:$(SBIN_DIR):$(LIB_DIR):$(PYLIB_DIR)/mock-1.0.1 \ python -m unittest discover --verbose -s $(SRC)/gppylib -p "test_unit*.py" + +.PHONY: installcheck-bash +installcheck-bash: + ./test/suite.bash + .PHONY: installcheck -installcheck: +installcheck: installcheck-bash $(MAKE) -C gpload_test $@ clean distclean: diff --git a/gpMgmt/bin/gpinitsystem b/gpMgmt/bin/gpinitsystem index 23acf63c9f705226a363e74dd5f8ed4ab1a14fb3..f63fe24bb55246d4fce4fc9d082761ee2819a4e4 100755 --- a/gpMgmt/bin/gpinitsystem +++ b/gpMgmt/bin/gpinitsystem @@ -1586,13 +1586,6 @@ START_QD_PRODUCTION () { LOG_MSG "[INFO]:-End Function $FUNCNAME" } -SET_GP_USER_PW () { - LOG_MSG "[INFO]:-Start Function $FUNCNAME" - $PSQL -p $MASTER_PORT -d "$DEFAULTDB" -c"alter user $USER_NAME password '$GP_PASSWD';" >> $LOG_FILE 2>&1 - ERROR_CHK $? "update Greenplum superuser password" 1 - LOG_MSG "[INFO]:-End Function $FUNCNAME" -} - CREATE_DATABASE () { LOG_MSG "[INFO]:-Start Function $FUNCNAME" SET_VAR $QD_PRIMARY_ARRAY diff --git a/gpMgmt/bin/lib/gp_bash_functions.sh b/gpMgmt/bin/lib/gp_bash_functions.sh index 354936091dfdf58f551950abd6ec9d37c92893a3..01419ba9d1dad9041a4017b57f2bce4e2945e250 100755 --- a/gpMgmt/bin/lib/gp_bash_functions.sh +++ b/gpMgmt/bin/lib/gp_bash_functions.sh @@ -1297,6 +1297,21 @@ CHK_GPDB_ID () { LOG_MSG "[INFO]:-End Function $FUNCNAME" } +SET_GP_USER_PW () { + LOG_MSG "[INFO]:-Start Function $FUNCNAME" + + local alter_statement="alter user :\"username\" password :'password';" + + $PSQL --variable=ON_ERROR_STOP=1 \ + -p $MASTER_PORT \ + -d "$DEFAULTDB" \ + --variable=username="$USER_NAME" \ + --variable=password="$GP_PASSWD" <<< "$alter_statement" >> $LOG_FILE 2>&1 + + ERROR_CHK $? "update Greenplum superuser password" 1 + LOG_MSG "[INFO]:-End Function $FUNCNAME" +} + #****************************************************************************** # Main Section #****************************************************************************** diff --git a/gpMgmt/bin/test/gpinitsystem_test.bash b/gpMgmt/bin/test/gpinitsystem_test.bash new file mode 100755 index 0000000000000000000000000000000000000000..7177bfb4f429aeca0dde7a67ff3705a01d15b38c --- /dev/null +++ b/gpMgmt/bin/test/gpinitsystem_test.bash @@ -0,0 +1,65 @@ +#!/usr/bin/env bash + +. lib/gp_bash_functions.sh + +__cleanupTestUsers() { + dropuser 123456 + dropuser abc123456 +} + +mimic_gpinitsystem_setup() { + # ensure MASTER_PORT is set, it is needed by SET_GP_USER_PW + GET_MASTER_PORT "$MASTER_DATA_DIRECTORY" + + # the return value set when performing ERROR_CHK + # on the status code returned from $PSQL + # + # set it to a default value + RETVAL=0 +} + +it_should_quote_the_username_during_alter_user_in_SET_GP_USER_PW() { + mimic_gpinitsystem_setup + + # given a user that is only a number + USER_NAME=123456 + createuser $USER_NAME + trap __cleanupTestUsers EXIT + + # when we run set user password + SET_GP_USER_PW + + # then it should succeed + if [ "$RETVAL" != "0" ]; then + local error_message="$(tail -n 10 "$LOG_FILE")" + echo "got an exit status of $RETVAL while running SET_GP_USER_PW for $USER_NAME, wanted success: $error_message" + exit 1 + fi +} + +it_should_quote_the_password_during_alter_user_in_SET_GP_USER_PW() { + mimic_gpinitsystem_setup + + # given a user + USER_NAME=abc123456 + createuser $USER_NAME + trap __cleanupTestUsers EXIT + + # when we run set user password with a password containing single quotes + GP_PASSWD="abc'" + SET_GP_USER_PW + + # then it should succeed + if [ "$RETVAL" != "0" ]; then + local error_message="$(tail -n 10 "$LOG_FILE")" + echo "got an exit status of $RETVAL while running SET_GP_USER_PW for $USER_NAME with password $GP_PASSWD, wanted success: $error_message" + exit 1 + fi +} + +main() { + it_should_quote_the_username_during_alter_user_in_SET_GP_USER_PW + it_should_quote_the_password_during_alter_user_in_SET_GP_USER_PW +} + +main diff --git a/gpMgmt/bin/test/suite.bash b/gpMgmt/bin/test/suite.bash new file mode 100755 index 0000000000000000000000000000000000000000..3cf581e0ef9cd89a57824512260cd75b4635d363 --- /dev/null +++ b/gpMgmt/bin/test/suite.bash @@ -0,0 +1,5 @@ +#!/usr/bin/env bash + +set -o errexit + +./test/gpinitsystem_test.bash