From d4abfb2a878e28670f5a202078a3fb8139a67e69 Mon Sep 17 00:00:00 2001 From: Jason Tedor Date: Fri, 18 Mar 2016 08:25:21 -0400 Subject: [PATCH] Centralize umask utilities in bats tests --- .../scripts/packaging_test_utils.bash | 20 +++++++++++++++++-- .../resources/packaging/scripts/plugins.bash | 4 ++-- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/qa/vagrant/src/test/resources/packaging/scripts/packaging_test_utils.bash b/qa/vagrant/src/test/resources/packaging/scripts/packaging_test_utils.bash index c2c19236f48..cb18363d60a 100644 --- a/qa/vagrant/src/test/resources/packaging/scripts/packaging_test_utils.bash +++ b/qa/vagrant/src/test/resources/packaging/scripts/packaging_test_utils.bash @@ -188,7 +188,7 @@ assert_module_or_plugin_directory() { config_user=$(find "$ESHOME" -maxdepth 0 -printf "%u") config_owner=$(find "$ESHOME" -maxdepth 0 -printf "%g") # directories should use the user file-creation mask - config_privileges=$((0777 & ~$(sudo -E -u $ESPLUGIN_COMMAND_USER sh -c umask) | 0111)) + config_privileges=$(executable_privileges_for_user_from_umask $ESPLUGIN_COMMAND_USER) assert_file $directory d $config_user $config_owner $(printf "%o" $config_privileges) } @@ -201,7 +201,7 @@ assert_module_or_plugin_file() { # config files should not be executable and otherwise use the user # file-creation mask - expected_file_privileges=$((0777 & ~$(sudo -E -u $ESPLUGIN_COMMAND_USER sh -c umask) & ~0111)) + expected_file_privileges=$(file_privileges_for_user_from_umask $ESPLUGIN_COMMAND_USER) assert_file $file f $config_user $config_owner $(printf "%o" $expected_file_privileges) } @@ -473,3 +473,19 @@ install_script() { echo "Installing $script to $ESSCRIPTS" cp $script $ESSCRIPTS } + +# permissions from the user umask with the executable bit set +executable_privileges_for_user_from_umask() { + local user=$1 + shift + + echo $((0777 & ~$(sudo -E -u $user sh -c umask) | 0111)) +} + +# permissions from the user umask without the executable bit set +file_privileges_for_user_from_umask() { + local user=$1 + shift + + echo $((0777 & ~$(sudo -E -u $user sh -c umask) & ~0111)) +} diff --git a/qa/vagrant/src/test/resources/packaging/scripts/plugins.bash b/qa/vagrant/src/test/resources/packaging/scripts/plugins.bash index 3931c91e776..da6b9a44427 100644 --- a/qa/vagrant/src/test/resources/packaging/scripts/plugins.bash +++ b/qa/vagrant/src/test/resources/packaging/scripts/plugins.bash @@ -92,11 +92,11 @@ install_jvm_example() { config_user=$(find "$ESCONFIG" -maxdepth 0 -printf "%u") config_owner=$(find "$ESCONFIG" -maxdepth 0 -printf "%g") # directories should user the user file-creation mask - config_privileges=$((0777 & ~$(sudo -E -u $ESPLUGIN_COMMAND_USER sh -c umask) | 0111)) + config_privileges=$(executable_privileges_for_user_from_umask $ESPLUGIN_COMMAND_USER) assert_file "$ESCONFIG/jvm-example" d $config_user $config_owner $(printf "%o" $config_privileges) # config files should not be executable and otherwise use the user # file-creation mask - expected_file_privileges=$((0777 & ~$(sudo -E -u $ESPLUGIN_COMMAND_USER sh -c umask) & ~0111)) + expected_file_privileges=$(file_privileges_for_user_from_umask $ESPLUGIN_COMMAND_USER) assert_file "$ESCONFIG/jvm-example/example.yaml" f $config_user $config_owner $(printf "%o" $expected_file_privileges) echo "Running jvm-example's bin script...."