From e2642d64b9657910bf06dda6008cf3f5a9c0e459 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Markus=20M=C3=A4kel=C3=A4?= Date: Mon, 25 May 2020 19:26:14 +0300 Subject: [PATCH] MXS-3010: Fix maxkeys and the test The test doesn't work properly if the maxscale user doesn't exist and the key file permissions cannot be given to it. The test should use the current user as the owner of the file but it turned out that the -u option is broken. Extended the test case to make sure the same password with the same encryption key results in the same hash. --- server/core/maxkeys.cc | 4 ++-- server/core/test/test_maxpasswd.sh | 18 ++++++++++++++---- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/server/core/maxkeys.cc b/server/core/maxkeys.cc index b5b1ef8ce..360c5455b 100644 --- a/server/core/maxkeys.cc +++ b/server/core/maxkeys.cc @@ -62,9 +62,9 @@ int main(int argc, char** argv) int c; #ifdef HAVE_GLIBC - while ((c = getopt_long(argc, argv, "h", options, NULL)) != -1) + while ((c = getopt_long(argc, argv, "hu:", options, NULL)) != -1) #else - while ((c = getopt(argc, argv, "h")) != -1) + while ((c = getopt(argc, argv, "hu:")) != -1) #endif { switch (c) diff --git a/server/core/test/test_maxpasswd.sh b/server/core/test/test_maxpasswd.sh index 098f5b5fe..b996ccfa3 100755 --- a/server/core/test/test_maxpasswd.sh +++ b/server/core/test/test_maxpasswd.sh @@ -4,22 +4,32 @@ SECRETS_DIR=`mktemp -d` # Generate a .secrets file. -../maxkeys ${SECRETS_DIR} || exit 1 +../maxkeys -u $(whoami) ${SECRETS_DIR} || exit 1 # Generate a key. -KEY=`../maxpasswd ${SECRETS_DIR} dummy` +KEY1=$(../maxpasswd ${SECRETS_DIR} dummy) +KEY2=$(../maxpasswd ${SECRETS_DIR} dummy) # Remove the temporary directory. rm -rf ${SECRETS_DIR} # Get the length of the generated KEY. -LENGTH=${#KEY} +LENGTH=${#KEY1} if [ ${LENGTH} -eq 32 ] then # Exactly 32 characters => Ok! - exit 0 + + if [ "$KEY1" == "$KEY2" ] + then + # Password encryption returns the same results when invoked multiple times + exit 0 + else + echo "First generated key ($KEY1) and second generated key ($KEY2) do not match." + exit 1 + fi else # Something else; chances are maxpasswd outputs garbage. + echo "Expected 32 characters, got $LENGTH" exit 1 fi