3
0
mirror of https://github.com/rvalitov/zabbix-php-fpm.git synced 2023-11-05 03:30:27 +01:00

[add] tests for root privileges (#55)

This commit is contained in:
Ramil Valitov 2020-09-14 18:39:58 +03:00 committed by GitHub
parent 106874e029
commit 467f31abe5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 29 additions and 0 deletions

View File

@ -562,6 +562,23 @@ testZabbixGetVersion() {
printSuccess "${FUNCNAME[0]}" printSuccess "${FUNCNAME[0]}"
} }
testNonRootUserPrivilegesDiscovery() {
#Run the script under non root user
DATA=$(sudo -u zabbix "/etc/zabbix/zabbix_php_fpm_discovery.sh")
IS_OK=$(echo "$DATA" | grep -F 'Insufficient privileges')
assertNotNull "The discovery script must not work for non root user" "$IS_OK"
printSuccess "${FUNCNAME[0]}"
}
testNonRootUserPrivilegesStatus() {
#Run the script under non root user
assertNotNull "Test socket is not defined" "$TEST_SOCKET"
DATA=$(sudo -u zabbix "/etc/zabbix/zabbix_php_fpm_status.sh" "$TEST_SOCKET" "/php-fpm-status")
IS_OK=$(echo "$DATA" | grep -F 'Insufficient privileges')
assertNotNull "The status script must not work for non root user" "$IS_OK"
printSuccess "${FUNCNAME[0]}"
}
testPHPIsRunning() { testPHPIsRunning() {
IS_OK=$(sudo ps ax | grep -F "php-fpm: pool " | grep -F -v "grep" | head -n1) IS_OK=$(sudo ps ax | grep -F "php-fpm: pool " | grep -F -v "grep" | head -n1)
assertNotNull "No running PHP-FPM instances found" "$IS_OK" assertNotNull "No running PHP-FPM instances found" "$IS_OK"

View File

@ -132,6 +132,12 @@ if [[ ! -d "$CACHE_ROOT" ]]; then
exit 1 exit 1
fi fi
USER_ID=$(id -u)
if [[ $USER_ID -ne 0 ]]; then
echo "Insufficient privileges. This script must be run under 'root' user or with 'sudo'."
exit 1
fi
function createCacheDirectory() { function createCacheDirectory() {
if [[ ! -d "$CACHE_DIRECTORY" ]]; then if [[ ! -d "$CACHE_DIRECTORY" ]]; then
mkdir "$CACHE_DIRECTORY" mkdir "$CACHE_DIRECTORY"

View File

@ -16,6 +16,12 @@ if [[ ! -x $S_GREP ]]; then
exit 1 exit 1
fi fi
USER_ID=$(id -u)
if [[ $USER_ID -ne 0 ]]; then
echo "Insufficient privileges. This script must be run under 'root' user or with 'sudo'."
exit 1
fi
if [[ -z $1 ]] || [[ -z $2 ]]; then if [[ -z $1 ]] || [[ -z $2 ]]; then
echo "No input data specified" echo "No input data specified"
echo "Usage: $0 php-path status" echo "Usage: $0 php-path status"