From 80a3b2a563a119414af1b10099d13a4749bf0583 Mon Sep 17 00:00:00 2001 From: Felix Bartels <1257835+fbartels@users.noreply.github.com> Date: Tue, 8 Oct 2019 23:00:36 +0200 Subject: [PATCH] experiment with overriding exec to test bash script functions (#254) * experiment with overriding exec to test bash script functions Signed-off-by: Felix Bartels * refine tests Signed-off-by: Felix Bartels * test installation of packages Signed-off-by: Felix Bartels * make sure package list is not updated when there are not additional packages * basic commander tests for webapp Signed-off-by: Felix Bartels * add webapp commander to makefile Signed-off-by: Felix Bartels * basic tests for webapp Signed-off-by: Felix Bartels * check webapp config.php Signed-off-by: Felix Bartels * add tests for z-push Signed-off-by: Felix Bartels --- Makefile | 2 ++ core/commander/server/commander.yaml | 46 ++++++++++++++++++++---- core/start-service.sh | 2 ++ webapp/commander.yaml | 52 ++++++++++++++++++++++++++++ webapp/start.sh | 2 ++ zpush/commander.yaml | 43 +++++++++++++++++++++++ zpush/start.sh | 2 ++ 7 files changed, 142 insertions(+), 7 deletions(-) create mode 100644 webapp/commander.yaml create mode 100644 zpush/commander.yaml diff --git a/Makefile b/Makefile index 88eea89..21ad7c4 100644 --- a/Makefile +++ b/Makefile @@ -386,6 +386,8 @@ test-commander: ## Test scripts with commander commander test tests/commander.yaml COMMANDER_OPTS="--concurrent 1" COMMANDER_FILES_PATH=core/commander/server dccommander run kopano_server COMMANDER_OPTS="--concurrent 1" COMMANDER_FILES_PATH=core/commander/spooler dccommander run kopano_spooler + COMMANDER_OPTS="--concurrent 1" COMMANDER_FILES_PATH=webapp dccommander run kopano_webapp + COMMANDER_OPTS="--concurrent 1" COMMANDER_FILES_PATH=zpush dccommander run kopano_zpush test-security: ## Scan containers with Trivy for known security risks (not part of CI workflow for now). cat $(TAG_FILE) | xargs -I % sh -c 'trivy --exit-code 0 --severity HIGH --quiet --auto-refresh %' diff --git a/core/commander/server/commander.yaml b/core/commander/server/commander.yaml index a64f582..9d8f153 100644 --- a/core/commander/server/commander.yaml +++ b/core/commander/server/commander.yaml @@ -1,22 +1,55 @@ tests: - test run of config update script for core: - command: /usr/bin/python3 /kopano/server.py + start-service script: + command: bash -c "shopt -s expand_aliases; alias exec='echo'; . /kopano/start-service.sh" exit-code: 0 - config update kopano-server: - command: /usr/bin/python3 /kopano/server.py && cat /etc/kopano/server.cfg /etc/kopano/ldap.cfg + stdout: + not-contains: + - "Reading package lists..." + start-service script (installing new package): + command: bash -c "shopt -s expand_aliases; alias exec='echo'; . /kopano/start-service.sh" + exit-code: 0 + stdout: + contains: + - "Setting up nano" + config: + env: + ADDITIONAL_KOPANO_PACKAGES: "nano" + start-service script (installing existing package): + command: bash -c "shopt -s expand_aliases; alias exec='echo'; . /kopano/start-service.sh" + exit-code: 0 + stdout: + contains: + - "INFO: kopano-server is already installed" + config: + env: + ADDITIONAL_KOPANO_PACKAGES: "kopano-server" + generate configuration for kopano-server: + command: /usr/bin/python3 /kopano/server.py && cat /etc/kopano/server.cfg exit-code: 0 stdout: contains: - server_listen_tls = *:237 + - server_ssl_key_file = /kopano/ssl/kopano_server.pem + not-contains: + - #server_listen_tls = *:237 + generate ldap configuration openLDAP (default): + command: /usr/bin/python3 /kopano/server.py && cat /etc/kopano/ldap.cfg + exit-code: 0 + stdout: + contains: - "!include /usr/share/kopano/ldap.openldap.cfg" - "#!include /usr/share/kopano/ldap.active-directory.cfg" - config update ldap ads: + not-contains: + - "#!include /usr/share/kopano/ldap.openldap.cfg" + generate ldap configuration for ADS: command: /usr/bin/python3 /kopano/server.py && cat /etc/kopano/ldap.cfg exit-code: 0 stdout: contains: - "#!include /usr/share/kopano/ldap.openldap.cfg" - "!include /usr/share/kopano/ldap.active-directory.cfg" + not-contains: + - "#!include /usr/share/kopano/ldap.active-directory.cfg" config: env: KCCOMMENT_LDAP_1: "!include /usr/share/kopano/ldap.openldap.cfg" @@ -48,7 +81,6 @@ config: KCCONF_SERVER_SSLKEYS_PATH: ${KCCONF_SERVER_SSLKEYS_PATH} KCCONF_SERVER_SYSTEM_EMAIL_ADDRESS: ${KCCONF_SERVER_SYSTEM_EMAIL_ADDRESS} KCUNCOMMENT_LDAP_1: ${KCUNCOMMENT_LDAP_1} - KOPANO_LOCALE: ${KOPANO_LOCALE} - KOPANO_USERSCRIPT_LOCALE: ${KOPANO_USERSCRIPT_LOCALE} LANG: ${LANG} SERVICE_TO_START: ${SERVICE_TO_START} + PATH: ${PATH} diff --git a/core/start-service.sh b/core/start-service.sh index e295d19..26b2b6e 100755 --- a/core/start-service.sh +++ b/core/start-service.sh @@ -17,6 +17,8 @@ ADDITIONAL_KOPANO_PACKAGES=$(echo "$ADDITIONAL_KOPANO_PACKAGES" | tr -d '"') # shellcheck disable=SC2016 disable=SC2086 if [ "$(dpkg-query -W -f='${Status}' $installpkg 2>/dev/null | grep -c 'ok installed')" -eq 0 ]; then apt --assume-yes --no-upgrade install "$installpkg" + else + echo "INFO: $installpkg is already installed" fi done diff --git a/webapp/commander.yaml b/webapp/commander.yaml new file mode 100644 index 0000000..5e1e587 --- /dev/null +++ b/webapp/commander.yaml @@ -0,0 +1,52 @@ +tests: + start-service script: + command: bash -c "shopt -s expand_aliases; alias exec='echo exec'; alias php-fpm7.0='echo php-fpm7.0'; . /kopano/start.sh" + exit-code: 0 + stdout: + not-contains: + - "Reading package lists..." + start-service script (installing new package): + command: bash -c "shopt -s expand_aliases; alias exec='echo exec'; alias php-fpm7.0='echo php-fpm7.0'; . /kopano/start.sh" + exit-code: 0 + stdout: + contains: + - "Setting up nano" + config: + env: + ADDITIONAL_KOPANO_PACKAGES: "nano" + start-service script (installing existing package): + command: bash -c "shopt -s expand_aliases; alias exec='echo exec'; alias php-fpm7.0='echo php-fpm7.0'; . /kopano/start.sh" + exit-code: 0 + stdout: + contains: + - "INFO: kopano-webapp is already installed" + config: + env: + ADDITIONAL_KOPANO_PACKAGES: "kopano-webapp" + start-service script (webapp configuration): + command: bash -c "shopt -s expand_aliases; alias exec='echo exec'; alias php-fpm7.0='echo php-fpm7.0'; . /kopano/start.sh" && cat /etc/kopano/webapp/config.php + exit-code: 0 + stdout: + contains: + - "define('OIDC_CLIENT_ID', 'webapp');" + config: + env: + KCCONF_WEBAPP_OIDC_CLIENT_ID: "webapp" + start-service script (installing & configuring webapp mdm plugin): + command: bash -c "shopt -s expand_aliases; alias exec='echo exec'; alias php-fpm7.0='echo php-fpm7.0'; . /kopano/start.sh" && cat /etc/kopano/webapp/config-mdm.php + exit-code: 0 + stdout: + contains: + - "define('PLUGIN_MDM_USER_DEFAULT_ENABLE_MDM', true);" + config: + env: + ADDITIONAL_KOPANO_WEBAPP_PLUGINS: "kopano-webapp-plugin-mdm" + KCCONF_WEBAPPPLUGIN_MDM_PLUGIN_MDM_USER_DEFAULT_ENABLE_MDM: "true" +config: + env: + DEBUG: ${DEBUG} + KCCONF_WEBAPP_OIDC_ISS: ${KCCONF_WEBAPP_OIDC_ISS} + KCCONF_WEBAPP_OIDC_CLIENT_ID: ${KCCONF_WEBAPP_OIDC_CLIENT_ID} + LANG: ${LANG} + PATH: ${PATH} + TZ: ${TZ} diff --git a/webapp/start.sh b/webapp/start.sh index f79aff4..d86dda0 100755 --- a/webapp/start.sh +++ b/webapp/start.sh @@ -20,6 +20,8 @@ ADDITIONAL_KOPANO_PACKAGES=$(echo "$ADDITIONAL_KOPANO_PACKAGES" | tr -d '"') # shellcheck disable=SC2016 disable=SC2086 if [ "$(dpkg-query -W -f='${Status}' $installpkg 2>/dev/null | grep -c 'ok installed')" -eq 0 ]; then apt --assume-yes --no-upgrade install "$installpkg" + else + echo "INFO: $installpkg is already installed" fi done diff --git a/zpush/commander.yaml b/zpush/commander.yaml new file mode 100644 index 0000000..160e9c3 --- /dev/null +++ b/zpush/commander.yaml @@ -0,0 +1,43 @@ +tests: + start-service script: + command: bash -c "shopt -s expand_aliases; alias exec='echo exec'; alias php-fpm7.0='echo php-fpm7.0'; . /kopano/start.sh" + exit-code: 0 + stdout: + not-contains: + - "Reading package lists..." + start-service script (installing new package): + command: bash -c "shopt -s expand_aliases; alias exec='echo exec'; alias php-fpm7.0='echo php-fpm7.0'; . /kopano/start.sh" + exit-code: 0 + stdout: + contains: + - "Setting up nano" + config: + env: + ADDITIONAL_KOPANO_PACKAGES: "nano" + start-service script (installing existing package): + command: bash -c "shopt -s expand_aliases; alias exec='echo exec'; alias php-fpm7.0='echo php-fpm7.0'; . /kopano/start.sh" + exit-code: 0 + stdout: + contains: + - "INFO: z-push-kopano is already installed" + config: + env: + ADDITIONAL_KOPANO_PACKAGES: "z-push-kopano" + start-service script (z-push configuration): + command: bash -c "shopt -s expand_aliases; alias exec='echo exec'; alias php-fpm7.0='echo php-fpm7.0'; . /kopano/start.sh" && cat /etc/z-push/z-push.conf.php + exit-code: 0 + stdout: + contains: + - "define('USE_CUSTOM_REMOTE_IP_HEADER', 'HTTP_X_FORWARDED_FOR');" + start-service script (configuring gabsync): + command: bash -c "shopt -s expand_aliases; alias exec='echo exec'; alias php-fpm7.0='echo php-fpm7.0'; . /kopano/start.sh" && cat /etc/z-push/gabsync.conf.php + exit-code: 0 + stdout: + contains: + - "define('USERNAME', 'SYSTEM');" +config: + env: + DEBUG: ${DEBUG} + LANG: ${LANG} + PATH: ${PATH} + TZ: ${TZ} diff --git a/zpush/start.sh b/zpush/start.sh index 686cc8c..57555f6 100755 --- a/zpush/start.sh +++ b/zpush/start.sh @@ -44,6 +44,8 @@ ADDITIONAL_KOPANO_PACKAGES=$(echo "$ADDITIONAL_KOPANO_PACKAGES" | tr -d '"') # shellcheck disable=SC2016 disable=SC2086 if [ "$(dpkg-query -W -f='${Status}' $installpkg 2>/dev/null | grep -c 'ok installed')" -eq 0 ]; then apt --assume-yes --no-upgrade install "$installpkg" + else + echo "INFO: $installpkg is already installed" fi done