From 6ed167bfafc4c4f27fa463790fcfd76960b96564 Mon Sep 17 00:00:00 2001 From: OniriCorpe Date: Sat, 29 Jun 2024 20:57:21 +0200 Subject: [PATCH 01/28] automatically ignore the service in diagnosis if it has been deactivated with the ynh cli --- src/service.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/service.py b/src/service.py index b0dc82827..0a0c37378 100644 --- a/src/service.py +++ b/src/service.py @@ -26,6 +26,7 @@ from glob import glob from datetime import datetime from moulinette import m18n +from yunohost.utils.diagnosis import diagnosis_ignore, diagnosis_unignore from yunohost.utils.error import YunohostError, YunohostValidationError from moulinette.utils.process import check_output from moulinette.utils.log import getActionLogger @@ -296,6 +297,9 @@ def service_enable(names): names = [names] for name in names: if _run_service_command("enable", name): + services = _get_services() + if name in services: + diagnosis_unignore({"services": [{"service": name}]}) logger.success(m18n.n("service_enabled", service=name)) else: raise YunohostError( @@ -315,6 +319,9 @@ def service_disable(names): names = [names] for name in names: if _run_service_command("disable", name): + services = _get_services() + if name in services: + diagnosis_ignore({"services": [{"service": name}]}) logger.success(m18n.n("service_disabled", service=name)) else: raise YunohostError( From 3f973669fc14de9fd45cbe1b376004b6d422d9fe Mon Sep 17 00:00:00 2001 From: Alexandre Aubin Date: Sun, 30 Jun 2024 01:37:56 +0200 Subject: [PATCH 02/28] helpers2.1: fix automigration of phpversion to php_version --- helpers/helpers.v2.1.d/php | 12 ------------ helpers/helpers.v2.1.d/setting | 15 +++++++++++++++ 2 files changed, 15 insertions(+), 12 deletions(-) diff --git a/helpers/helpers.v2.1.d/php b/helpers/helpers.v2.1.d/php index 3cca2c8fb..b7165e010 100644 --- a/helpers/helpers.v2.1.d/php +++ b/helpers/helpers.v2.1.d/php @@ -3,18 +3,6 @@ # (this is used in the apt helpers, big meh ...) readonly YNH_DEFAULT_PHP_VERSION=7.4 -# Legacy: auto-convert phpversion to php_version (for consistency with nodejs_version, ruby_version, ...) -if [[ -n "${app:-}" ]] && [[ -n "${phpversion:-}" ]] -then - if [[ -z "${php_version:-}" ]] - then - php_version=$phpversion - ynh_app_setting_set --key=php_version --value=$php_version - fi - ynh_app_setting_delete --key=phpversion - unset phpversion -fi - # Create a dedicated PHP-FPM config # # usage: ynh_config_add_phpfpm diff --git a/helpers/helpers.v2.1.d/setting b/helpers/helpers.v2.1.d/setting index 82528efa5..01480331c 100644 --- a/helpers/helpers.v2.1.d/setting +++ b/helpers/helpers.v2.1.d/setting @@ -122,3 +122,18 @@ else: EOF eval "$xtrace_enable" } + +# Legacy: auto-convert phpversion to php_version (for consistency with nodejs_version, ruby_version, ...) +# This has to be here and not in the "php" code file because ynh_app_setting_set/delete need to be defined @_@ +if [[ -n "${app:-}" ]] && [[ -n "${phpversion:-}" ]] +then + if [[ -z "${php_version:-}" ]] + then + php_version=$phpversion + ynh_app_setting_set --key=php_version --value=$php_version + fi + ynh_app_setting_delete --key=phpversion + unset phpversion +fi + + From a48bfa67de552abcf9f9a14cc94c3fe072ffe5d3 Mon Sep 17 00:00:00 2001 From: Alexandre Aubin Date: Sun, 30 Jun 2024 17:46:52 +0200 Subject: [PATCH 03/28] helpers2.1: change source patches location + raise an error instead of a warning when a patch fails to apply on CI MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Félix Piédallu --- helpers/helpers.v2.1.d/sources | 38 ++++++++++++++++++---------------- 1 file changed, 20 insertions(+), 18 deletions(-) diff --git a/helpers/helpers.v2.1.d/sources b/helpers/helpers.v2.1.d/sources index c0c2fb863..59dd4f12d 100644 --- a/helpers/helpers.v2.1.d/sources +++ b/helpers/helpers.v2.1.d/sources @@ -8,11 +8,7 @@ # | arg: --keep= - Space-separated list of files/folders that will be backup/restored in $dest_dir, such as a config file you don't want to overwrite. For example 'conf.json secrets.json logs' (no trailing `/` for folders) # | arg: --full_replace= - Remove previous sources before installing new sources (can be 1 or 0, default to 0) # -# ##### New 'sources' resources -# -# (See also the resources documentation which may be more complete?) -# -# This helper will read infos from the 'sources' resources in the manifest.toml of the app +# This helper will read infos from the 'sources' resources in the `manifest.toml` of the app # and expect a structure like: # # ```toml @@ -22,7 +18,9 @@ # sha256 = "0123456789abcdef" # The sha256 sum of the asset obtained from the URL # ``` # -# ##### Optional flags +# (See also the resources documentation which may be more complete?) +# +# ##### Optional flags in the 'sources' resource # # ```text # format = "tar.gz"/xz/bz2 # automatically guessed from the extension of the URL, but can be set explicitly. Will use `tar` to extract @@ -60,7 +58,8 @@ # - Uncompress the archive to `$dest_dir`. # - If `in_subdir` is true, the first level directory of the archive will be removed. # - If `in_subdir` is a numeric value, the N first level directories will be removed. -# - Patches named `patches/${src_id}-*.patch` will be applied to `$dest_dir` +# - Patches named `patches/${src_id}/*.patch` will be applied to `$dest_dir` +# - Apply sane default permissions (see _ynh_apply_default_permissions) ynh_setup_source() { # ============ Argument parsing ============= local -A args_array=([d]=dest_dir= [s]=source_id= [k]=keep= [r]=full_replace) @@ -222,17 +221,20 @@ ynh_setup_source() { fi # Apply patches - if [ -d "$YNH_APP_BASEDIR/patches/" ]; then - local patches_folder=$(realpath $YNH_APP_BASEDIR/patches/) - # Check if any file matching the pattern exists, cf https://stackoverflow.com/a/34195247 - if compgen -G "$patches_folder/${source_id}-*.patch" >/dev/null; then - pushd "$dest_dir" - for p in $patches_folder/${source_id}-*.patch; do - echo $p - patch --strip=1 <$p || ynh_print_warn "Packagers /!\\ patch $p failed to apply" - done - popd - fi + local patches_folder=$(realpath "$YNH_APP_BASEDIR/patches/$source_id") + if [ -d "$patches_folder" ]; then + pushd "$dest_dir" + for patchfile in "$patches_folder/"*.patch; do + echo "Applying $patchfile" + if ! patch --strip=1 < "$patchfile"; then + if ynh_in_ci_tests; then + ynh_die "Patch $patchfile failed to apply!" + else + ynh_print_warn "Warn your packagers /!\\ Patch $patchfile failed to apply" + fi + fi + done + popd fi # Keep files to be backup/restored at the end of the helper From 20741c63aafe11f4443319a35dbfb4b00732c6ca Mon Sep 17 00:00:00 2001 From: OniriCorpe Date: Sun, 30 Jun 2024 18:28:18 +0200 Subject: [PATCH 04/28] change an irrelevant error to a warning --- src/diagnosis.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/diagnosis.py b/src/diagnosis.py index 9e5d4235d..3f20f9093 100644 --- a/src/diagnosis.py +++ b/src/diagnosis.py @@ -322,7 +322,7 @@ def _diagnosis_ignore(add_filter=None, remove_filter=None, list=False): configuration["ignore_filters"][category] = [] if criterias not in configuration["ignore_filters"][category]: - raise YunohostValidationError("This filter does not exists.") + logger.warning("This filter does not exists.") configuration["ignore_filters"][category].remove(criterias) _diagnosis_write_configuration(configuration) From 5ef0c84c0f438ebfe5d73b560a95034a4f48c665 Mon Sep 17 00:00:00 2001 From: Alexandre Aubin <4533074+alexAubin@users.noreply.github.com> Date: Sun, 30 Jun 2024 18:34:38 +0200 Subject: [PATCH 05/28] Update tools.py: use _run_service_command to enable+start yunohost-firewall during postinstall and prevent a warning about lack of diagnosis ignore rule --- src/tools.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/tools.py b/src/tools.py index 7c6b39d5c..726841e48 100644 --- a/src/tools.py +++ b/src/tools.py @@ -41,7 +41,6 @@ from yunohost.app_catalog import ( ) from yunohost.domain import domain_add from yunohost.firewall import firewall_upnp -from yunohost.service import service_start, service_enable from yunohost.regenconf import regen_conf from yunohost.utils.system import ( _dump_sources_list, @@ -156,6 +155,7 @@ def tools_postinstall( force_diskspace=False, overwrite_root_password=True, ): + from yunohost.service import _run_service_command from yunohost.dyndns import _dyndns_available, dyndns_unsubscribe from yunohost.utils.dns import is_yunohost_dyndns_domain from yunohost.utils.password import ( @@ -270,8 +270,8 @@ def tools_postinstall( os.system("touch /etc/yunohost/installed") # Enable and start YunoHost firewall at boot time - service_enable("yunohost-firewall") - service_start("yunohost-firewall") + _run_service_command("enable", "yunohost-firewall") + _run_service_command("start", "yunohost-firewall") regen_conf(names=["ssh"], force=True) From 9727765ecff6d4a035224db0d1071ab01f8e9675 Mon Sep 17 00:00:00 2001 From: Alexandre Aubin <4533074+alexAubin@users.noreply.github.com> Date: Sun, 30 Jun 2024 18:39:11 +0200 Subject: [PATCH 06/28] Update diagnosis.py: improve warning to make it more explicit when called from another context --- src/diagnosis.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/diagnosis.py b/src/diagnosis.py index 3f20f9093..2244b6795 100644 --- a/src/diagnosis.py +++ b/src/diagnosis.py @@ -304,7 +304,7 @@ def _diagnosis_ignore(add_filter=None, remove_filter=None, list=False): configuration["ignore_filters"][category] = [] if criterias in configuration["ignore_filters"][category]: - logger.warning("This filter already exists.") + logger.warning(f"(There is already a diagnosis {category} filter with these criterias)") return configuration["ignore_filters"][category].append(criterias) @@ -322,7 +322,7 @@ def _diagnosis_ignore(add_filter=None, remove_filter=None, list=False): configuration["ignore_filters"][category] = [] if criterias not in configuration["ignore_filters"][category]: - logger.warning("This filter does not exists.") + logger.warning(f"(There is no such diagnosis {category} filter with these criterias to remove)") configuration["ignore_filters"][category].remove(criterias) _diagnosis_write_configuration(configuration) From c0bccc3ac9bfe289108d7b4aad922c89317f3e55 Mon Sep 17 00:00:00 2001 From: Alexandre Aubin <4533074+alexAubin@users.noreply.github.com> Date: Sun, 30 Jun 2024 18:40:23 +0200 Subject: [PATCH 07/28] Update diagnosis.py: gotta "return" now if the key doesn't exist, otherwise the next code fails --- src/diagnosis.py | 1 + 1 file changed, 1 insertion(+) diff --git a/src/diagnosis.py b/src/diagnosis.py index 2244b6795..8fd3ffd45 100644 --- a/src/diagnosis.py +++ b/src/diagnosis.py @@ -323,6 +323,7 @@ def _diagnosis_ignore(add_filter=None, remove_filter=None, list=False): if criterias not in configuration["ignore_filters"][category]: logger.warning(f"(There is no such diagnosis {category} filter with these criterias to remove)") + return configuration["ignore_filters"][category].remove(criterias) _diagnosis_write_configuration(configuration) From 636c9e563ec3a697facaf77de9d7b3ddb8d1755b Mon Sep 17 00:00:00 2001 From: Alexandre Aubin <4533074+alexAubin@users.noreply.github.com> Date: Sun, 30 Jun 2024 18:41:50 +0200 Subject: [PATCH 08/28] Update diagnosis.py: more messages improvement --- src/diagnosis.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/diagnosis.py b/src/diagnosis.py index 8fd3ffd45..7b9975db2 100644 --- a/src/diagnosis.py +++ b/src/diagnosis.py @@ -309,7 +309,7 @@ def _diagnosis_ignore(add_filter=None, remove_filter=None, list=False): configuration["ignore_filters"][category].append(criterias) _diagnosis_write_configuration(configuration) - logger.success("Filter added") + logger.success(f"Added a {category} diagnosis filter") return if remove_filter: @@ -327,7 +327,7 @@ def _diagnosis_ignore(add_filter=None, remove_filter=None, list=False): configuration["ignore_filters"][category].remove(criterias) _diagnosis_write_configuration(configuration) - logger.success("Filter removed") + logger.success(f"Removed a {category} diagnosis filter") return From 4b43d8d99d621f339eb967e4694a1708afbd2a57 Mon Sep 17 00:00:00 2001 From: Alexandre Aubin <4533074+alexAubin@users.noreply.github.com> Date: Sun, 30 Jun 2024 18:52:19 +0200 Subject: [PATCH 09/28] Update service.py: typo --- src/service.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/service.py b/src/service.py index 0a0c37378..db96a099a 100644 --- a/src/service.py +++ b/src/service.py @@ -26,7 +26,7 @@ from glob import glob from datetime import datetime from moulinette import m18n -from yunohost.utils.diagnosis import diagnosis_ignore, diagnosis_unignore +from yunohost.diagnosis import diagnosis_ignore, diagnosis_unignore from yunohost.utils.error import YunohostError, YunohostValidationError from moulinette.utils.process import check_output from moulinette.utils.log import getActionLogger From f2b5f0f22cd3b88e17579b842b607be6d2ab49a4 Mon Sep 17 00:00:00 2001 From: Alexandre Aubin Date: Sun, 30 Jun 2024 18:53:41 +0200 Subject: [PATCH 10/28] helpers2.1: when using ynh_die, also return the error via YNH_STDRETURN such that it can be obtained from the python and displayed in the main error message, to increase the chance that people may read it and have something more useful than "An error happened in the script" --- helpers/helpers.v2.1.d/apt | 4 ++-- helpers/helpers.v2.1.d/logging | 6 +++++- src/hook.py | 3 +++ 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/helpers/helpers.v2.1.d/apt b/helpers/helpers.v2.1.d/apt index d8425ee58..4c78a2147 100644 --- a/helpers/helpers.v2.1.d/apt +++ b/helpers/helpers.v2.1.d/apt @@ -134,12 +134,12 @@ EOF # Fake an install of those dependencies to see the errors # The sed command here is, Print only from 'Reading state info' to the end. [[ -n "$problematic_dependencies" ]] && _ynh_apt_install $problematic_dependencies --dry-run 2>&1 | sed --quiet '/Reading state info/,$p' | grep -v "fix-broken\|Reading state info" >&2 - ynh_die "Unable to install dependencies" + ynh_die "Unable to install apt dependencies" } rm --recursive --force "$TMPDIR" # Remove the temp dir. # check if the package is actually installed - _ynh_apt_package_is_installed "${app_ynh_deps}" || ynh_die "Unable to install dependencies" + _ynh_apt_package_is_installed "${app_ynh_deps}" || ynh_die "Unable to install apt dependencies" # Specific tweak related to Postgresql # -> trigger postgresql regenconf if we may have just installed postgresql diff --git a/helpers/helpers.v2.1.d/logging b/helpers/helpers.v2.1.d/logging index 4649cf670..eb4ddbb59 100644 --- a/helpers/helpers.v2.1.d/logging +++ b/helpers/helpers.v2.1.d/logging @@ -4,7 +4,11 @@ # # usage: ynh_die "Some message" ynh_die() { - echo "$1" 1>&2 + if [[ -n "${1:-}" ]] + then + python3 -c 'import yaml, sys; print(yaml.dump({"error": sys.stdin.read()}))' <<< "${1:-}" >>"$YNH_STDRETURN" + echo "${1:-}" 1>&2 + fi exit 1 } diff --git a/src/hook.py b/src/hook.py index ee9f08e48..49c2f4cc3 100644 --- a/src/hook.py +++ b/src/hook.py @@ -538,6 +538,9 @@ def hook_exec_with_script_debug_if_failure(*args, **kwargs): failed = True if retcode != 0 else False if failed: error = error_message_if_script_failed + # check more specific error message added by ynh_die in $YNH_STDRETURN + if isinstance(retpayload, dict) and "error" in retpayload: + error += " : " + retpayload["error"].strip() logger.error(error_message_if_failed(error)) failure_message_with_debug_instructions = operation_logger.error(error) if Moulinette.interface.type != "api": From fcaa366e9154740ed72cc22c55848604b63cb007 Mon Sep 17 00:00:00 2001 From: Alexandre Aubin Date: Sun, 30 Jun 2024 19:28:18 +0200 Subject: [PATCH 11/28] helpers2.1: zzzz --- helpers/helpers.v2.1.d/utils | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/helpers/helpers.v2.1.d/utils b/helpers/helpers.v2.1.d/utils index 859cd29d9..5d2c72e16 100644 --- a/helpers/helpers.v2.1.d/utils +++ b/helpers/helpers.v2.1.d/utils @@ -272,7 +272,7 @@ _ynh_apply_default_permissions() { fi # Files inside should be owned by $app with rw-r----- (+x for folders or files that already have +x) # The group needs read/dirtraversal (in particular if it's www-data) - chmod -R u=rwX,g=r-X,o=--- "$target" + chmod -R u=rwX,g=rX,o=--- "$target" chown -R "$app:$group" "$target" return fi From 1e1409c7d7fb708f8832570e81a7e1f52be8086d Mon Sep 17 00:00:00 2001 From: Alexandre Aubin Date: Sun, 30 Jun 2024 19:43:18 +0200 Subject: [PATCH 12/28] helpers2.1: logging tweak in ynh_die --- helpers/helpers.v2.1.d/logging | 1 + 1 file changed, 1 insertion(+) diff --git a/helpers/helpers.v2.1.d/logging b/helpers/helpers.v2.1.d/logging index eb4ddbb59..1d729178a 100644 --- a/helpers/helpers.v2.1.d/logging +++ b/helpers/helpers.v2.1.d/logging @@ -4,6 +4,7 @@ # # usage: ynh_die "Some message" ynh_die() { + set +o xtrace # set +x if [[ -n "${1:-}" ]] then python3 -c 'import yaml, sys; print(yaml.dump({"error": sys.stdin.read()}))' <<< "${1:-}" >>"$YNH_STDRETURN" From 1c62960e25c9004162a0cdc272dd2898b85952f6 Mon Sep 17 00:00:00 2001 From: Alexandre Aubin Date: Sun, 30 Jun 2024 20:10:21 +0200 Subject: [PATCH 13/28] helpers2.1: remove the ynh_clean_setup mechanism underused/useless.. --- helpers/helpers.v2.1.d/utils | 16 ---------------- 1 file changed, 16 deletions(-) diff --git a/helpers/helpers.v2.1.d/utils b/helpers/helpers.v2.1.d/utils index 5d2c72e16..4c611395d 100644 --- a/helpers/helpers.v2.1.d/utils +++ b/helpers/helpers.v2.1.d/utils @@ -6,17 +6,6 @@ YNH_APP_BASEDIR=${YNH_APP_BASEDIR:-$(realpath ..)} # # [internal] # -# usage: -# ynh_exit_properly is used only by the helper ynh_abort_if_errors. -# You should not use it directly. -# Instead, add to your script: -# ynh_clean_setup () { -# instructions... -# } -# -# This function provide a way to clean some residual of installation that not managed by remove script. -# -# It prints a warning to inform that the script was failed, and execute the ynh_clean_setup function if used in the app script ynh_exit_properly() { local exit_code=$? @@ -37,10 +26,6 @@ ynh_exit_properly() { # Small tempo to avoid the next message being mixed up with other DEBUG messages sleep 0.5 - if type -t ynh_clean_setup >/dev/null; then # Check if the function exist in the app script. - ynh_clean_setup # Call the function to do specific cleaning for the app. - fi - # Exit with error status # We don't call ynh_die basically to avoid unecessary 10-ish # debug lines about parsing args and stuff just to exit 1.. @@ -55,7 +40,6 @@ ynh_exit_properly() { # # This configure the rest of the script execution such that, if an error occurs # or if an empty variable is used, the execution of the script stops immediately -# and a call to `ynh_clean_setup` is triggered if it has been defined by your script. ynh_abort_if_errors() { set -o errexit # set -e; Exit if a command fail set -o nounset # set -u; And if a variable is used unset From e75b4b3b3b59eac81e7873e48a001b6c2965f7a6 Mon Sep 17 00:00:00 2001 From: Sebastian Gumprich Date: Sun, 30 Jun 2024 20:16:51 +0200 Subject: [PATCH 14/28] add support for downloading tar-files this is needed for invoiceninja, see https://github.com/YunoHost-Apps/invoiceninja5_ynh/pull/280 --- helpers/helpers.v2.1.d/sources | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/helpers/helpers.v2.1.d/sources b/helpers/helpers.v2.1.d/sources index 59dd4f12d..656819ec7 100644 --- a/helpers/helpers.v2.1.d/sources +++ b/helpers/helpers.v2.1.d/sources @@ -23,10 +23,10 @@ # ##### Optional flags in the 'sources' resource # # ```text -# format = "tar.gz"/xz/bz2 # automatically guessed from the extension of the URL, but can be set explicitly. Will use `tar` to extract -# "zip" # automatically guessed from the extension of the URL, but can be set explicitly. Will use `unzip` to extract -# "docker" # useful to extract files from an already-built docker image (instead of rebuilding them locally). Will use `docker-image-extract` to extract -# "whatever" # an arbitrary value, not really meaningful except to imply that the file won't be extracted +# format = "tar.gz"/xz/bz2/tar # automatically guessed from the extension of the URL, but can be set explicitly. Will use `tar` to extract +# "zip" # automatically guessed from the extension of the URL, but can be set explicitly. Will use `unzip` to extract +# "docker" # useful to extract files from an already-built docker image (instead of rebuilding them locally). Will use `docker-image-extract` to extract +# "whatever" # an arbitrary value, not really meaningful except to imply that the file won't be extracted # # in_subdir = true # default, there's an intermediate subdir in the archive before accessing the actual files # false # sources are directly in the archive root @@ -107,6 +107,8 @@ ynh_setup_source() { elif [[ "$src_url" =~ ^.*\.tar\.bz2$ ]] then src_format="tar.bz2" + elif [[ "$src_url" =~ ^.*\.tar$ ]] + src_format="tar" elif [[ -z "$src_extract" ]] then src_extract="false" @@ -212,7 +214,7 @@ ynh_setup_source() { fi strip="--strip-components $sub_dirs" fi - if [[ "$src_format" =~ ^tar.gz|tar.bz2|tar.xz$ ]]; then + if [[ "$src_format" =~ ^tar.gz|tar.bz2|tar.xz|tar$ ]]; then tar --extract --file=$src_filename --directory="$dest_dir" $strip else ynh_die "Archive format unrecognized." From 7b0383f865e1375c0827b03dcac3ab0e2c1798f3 Mon Sep 17 00:00:00 2001 From: alexAubin <4533074+alexAubin@users.noreply.github.com> Date: Sun, 30 Jun 2024 19:38:06 +0000 Subject: [PATCH 15/28] :art: Format Python code with Black --- src/diagnosis.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/diagnosis.py b/src/diagnosis.py index 7b9975db2..c56c2f22c 100644 --- a/src/diagnosis.py +++ b/src/diagnosis.py @@ -304,7 +304,9 @@ def _diagnosis_ignore(add_filter=None, remove_filter=None, list=False): configuration["ignore_filters"][category] = [] if criterias in configuration["ignore_filters"][category]: - logger.warning(f"(There is already a diagnosis {category} filter with these criterias)") + logger.warning( + f"(There is already a diagnosis {category} filter with these criterias)" + ) return configuration["ignore_filters"][category].append(criterias) @@ -322,7 +324,9 @@ def _diagnosis_ignore(add_filter=None, remove_filter=None, list=False): configuration["ignore_filters"][category] = [] if criterias not in configuration["ignore_filters"][category]: - logger.warning(f"(There is no such diagnosis {category} filter with these criterias to remove)") + logger.warning( + f"(There is no such diagnosis {category} filter with these criterias to remove)" + ) return configuration["ignore_filters"][category].remove(criterias) From ef622ffe4d52415887edef9a926abd81ad57bf9e Mon Sep 17 00:00:00 2001 From: Alexandre Aubin Date: Mon, 1 Jul 2024 18:24:58 +0200 Subject: [PATCH 16/28] helpers2.1: switch to posisional args for ynh_multimedia_addaccess because that's what 99% of apps already do --- helpers/helpers.v2.1.d/multimedia | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/helpers/helpers.v2.1.d/multimedia b/helpers/helpers.v2.1.d/multimedia index d71346969..270ae1950 100644 --- a/helpers/helpers.v2.1.d/multimedia +++ b/helpers/helpers.v2.1.d/multimedia @@ -78,19 +78,12 @@ ynh_multimedia_addfolder() { setfacl -RL -m m::rwx "$source_dir" } -# Allow an user to have an write authorisation in multimedia directories +# Add an user to the multimedia group, in turn having write permission in multimedia directories # # usage: ynh_multimedia_addaccess user_name # -# | arg: --user_name= - The name of the user which gain this access. +# | arg: user_name - The name of the user which gain this access. ynh_multimedia_addaccess() { - - # ============ Argument parsing ============= - local -A args_array=([u]=user_name=) - local user_name - ynh_handle_getopts_args "$@" - # =========================================== - groupadd -f multimedia - usermod -a -G multimedia $user_name + usermod -a -G multimedia $1 } From 50034aabddc6222f3cce3be9b8d1f787a34bd209 Mon Sep 17 00:00:00 2001 From: Alexandre Aubin Date: Mon, 1 Jul 2024 18:49:36 +0200 Subject: [PATCH 17/28] helpers2.1: use the MEDIA_GROUP global var for consistency --- helpers/helpers.v2.1.d/multimedia | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/helpers/helpers.v2.1.d/multimedia b/helpers/helpers.v2.1.d/multimedia index 270ae1950..630e92ecc 100644 --- a/helpers/helpers.v2.1.d/multimedia +++ b/helpers/helpers.v2.1.d/multimedia @@ -84,6 +84,6 @@ ynh_multimedia_addfolder() { # # | arg: user_name - The name of the user which gain this access. ynh_multimedia_addaccess() { - groupadd -f multimedia - usermod -a -G multimedia $1 + groupadd -f $MEDIA_GROUP + usermod -a -G $MEDIA_GROUP $1 } From 6b77e19bbdef6be7a4d19716999b590b6c365dc7 Mon Sep 17 00:00:00 2001 From: Alexandre Aubin Date: Mon, 1 Jul 2024 18:49:47 +0200 Subject: [PATCH 18/28] Update changelog for 11.2.20 --- debian/changelog | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/debian/changelog b/debian/changelog index 7a8dfacc9..21ddd5311 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,17 @@ +yunohost (11.2.20) stable; urgency=low + + - helpers2.1: fix automigration of phpversion to php_version (3f973669) + - helpers2.1: change source patches location + raise an error instead of a warning when a patch fails to apply on CI (a48bfa67) + - helpers2.1: when using ynh_die, also return the error via YNH_STDRETURN such that it can be obtained from the python and displayed in the main error message, to increase the chance that people may read it and have something more useful than "An error happened in the script" (f2b5f0f2) + - helpers2.1: remove the ynh_clean_setup mechanism underused/useless.. (1c62960e) + - helpers2.1: switch to posisional args for ynh_multimedia_addaccess because that's what 99% of apps already do (ef622ffe) + - helpers2.1: add support for downloading .tar files ([#1889](http://github.com/YunoHost/yunohost/pull/1889)) + - services/diagnosis: automatically ignore the service in diagnosis if it has been deactivated with the ynh cli ([#1886](http://github.com/YunoHost/yunohost/pull/1886)) + + Thanks to all contributors <3 ! (alexAubin, OniriCorpe, Sebastian Gumprich) + + -- Alexandre Aubin Mon, 01 Jul 2024 18:46:52 +0200 + yunohost (11.2.19) stable; urgency=low - apps: tweaks to be more robust and prevent the stupid flood of 'sh: 0: getcwd() failed: No such file or directory' when running an app upgrade/remove from /var/www/$app, sometimes making it look like the upgrade failed when it didnt (a349fc03) From 1ed56952e62db6273d0e0fd546095adea3419033 Mon Sep 17 00:00:00 2001 From: Alexandre Aubin Date: Mon, 1 Jul 2024 20:25:10 +0200 Subject: [PATCH 19/28] What do we say about testing before releasing? Not today! --- helpers/helpers.v2.1.d/sources | 1 + 1 file changed, 1 insertion(+) diff --git a/helpers/helpers.v2.1.d/sources b/helpers/helpers.v2.1.d/sources index 656819ec7..312014b67 100644 --- a/helpers/helpers.v2.1.d/sources +++ b/helpers/helpers.v2.1.d/sources @@ -108,6 +108,7 @@ ynh_setup_source() { then src_format="tar.bz2" elif [[ "$src_url" =~ ^.*\.tar$ ]] + then src_format="tar" elif [[ -z "$src_extract" ]] then From 92807afb160432cde550ad782d562dc3f3ea2191 Mon Sep 17 00:00:00 2001 From: Alexandre Aubin Date: Mon, 1 Jul 2024 20:55:45 +0200 Subject: [PATCH 20/28] helpers: yolo add tests for helpersv2.1 --- .gitlab/ci/test.gitlab-ci.yml | 11 +- tests/test_helpers.sh | 5 +- tests/test_helpers.v2.1.d/ynhtest_apt.sh | 22 + .../ynhtest_config.sh | 0 tests/test_helpers.v2.1.d/ynhtest_logging.sh | 92 +++ tests/test_helpers.v2.1.d/ynhtest_safe_rm.sh | 71 ++ tests/test_helpers.v2.1.d/ynhtest_settings.sh | 63 ++ .../ynhtest_setup_source.sh | 111 +++ .../test_helpers.v2.1.d/ynhtest_templating.sh | 62 ++ .../ynhtest_user.sh | 0 .../ynhtest_apt.sh | 0 tests/test_helpers.v2.d/ynhtest_config.sh | 662 ++++++++++++++++++ .../ynhtest_logging.sh | 0 .../ynhtest_network.sh | 0 .../ynhtest_secure_remove.sh | 0 .../ynhtest_settings.sh | 0 .../ynhtest_setup_source.sh | 0 .../ynhtest_templating.sh | 0 tests/test_helpers.v2.d/ynhtest_user.sh | 25 + 19 files changed, 1119 insertions(+), 5 deletions(-) create mode 100644 tests/test_helpers.v2.1.d/ynhtest_apt.sh rename tests/{test_helpers.d => test_helpers.v2.1.d}/ynhtest_config.sh (100%) create mode 100644 tests/test_helpers.v2.1.d/ynhtest_logging.sh create mode 100644 tests/test_helpers.v2.1.d/ynhtest_safe_rm.sh create mode 100644 tests/test_helpers.v2.1.d/ynhtest_settings.sh create mode 100644 tests/test_helpers.v2.1.d/ynhtest_setup_source.sh create mode 100644 tests/test_helpers.v2.1.d/ynhtest_templating.sh rename tests/{test_helpers.d => test_helpers.v2.1.d}/ynhtest_user.sh (100%) rename tests/{test_helpers.d => test_helpers.v2.d}/ynhtest_apt.sh (100%) create mode 100644 tests/test_helpers.v2.d/ynhtest_config.sh rename tests/{test_helpers.d => test_helpers.v2.d}/ynhtest_logging.sh (100%) rename tests/{test_helpers.d => test_helpers.v2.d}/ynhtest_network.sh (100%) rename tests/{test_helpers.d => test_helpers.v2.d}/ynhtest_secure_remove.sh (100%) rename tests/{test_helpers.d => test_helpers.v2.d}/ynhtest_settings.sh (100%) rename tests/{test_helpers.d => test_helpers.v2.d}/ynhtest_setup_source.sh (100%) rename tests/{test_helpers.d => test_helpers.v2.d}/ynhtest_templating.sh (100%) create mode 100644 tests/test_helpers.v2.d/ynhtest_user.sh diff --git a/.gitlab/ci/test.gitlab-ci.yml b/.gitlab/ci/test.gitlab-ci.yml index cded5bf7d..349665b68 100644 --- a/.gitlab/ci/test.gitlab-ci.yml +++ b/.gitlab/ci/test.gitlab-ci.yml @@ -57,14 +57,17 @@ test-actionmap: changes: - share/actionsmap.yml -test-helpers: +test-helpers2: extends: .test-stage script: - cd tests - bash test_helpers.sh -# only: -# changes: -# - helpers/* + +test-helpers2.1: + extends: .test-stage + script: + - cd tests + - bash test_helpers.sh 2.1 test-domains: extends: .test-stage diff --git a/tests/test_helpers.sh b/tests/test_helpers.sh index a2ccb75c4..78299f59c 100644 --- a/tests/test_helpers.sh +++ b/tests/test_helpers.sh @@ -1,5 +1,7 @@ #!/bin/bash +VERSION=${1:-2} + readonly NORMAL=$(printf '\033[0m') readonly BOLD=$(printf '\033[1m') readonly RED=$(printf '\033[31m') @@ -47,7 +49,7 @@ getent passwd ynhtest &>/dev/null || useradd --system ynhtest # ========================================================= -for TEST_SUITE in $(ls test_helpers.d/*) +for TEST_SUITE in $(ls test_helpers.v$VERSION.d/*) do source $TEST_SUITE done @@ -64,6 +66,7 @@ do (mkdir conf mkdir scripts cd scripts + export YNH_HELPERS_VERSION=$VERSION source /usr/share/yunohost/helpers app=ynhtest YNH_APP_ID=$app diff --git a/tests/test_helpers.v2.1.d/ynhtest_apt.sh b/tests/test_helpers.v2.1.d/ynhtest_apt.sh new file mode 100644 index 000000000..e415c8135 --- /dev/null +++ b/tests/test_helpers.v2.1.d/ynhtest_apt.sh @@ -0,0 +1,22 @@ +ynhtest_apt_install_apt_deps_regular() { + + dpkg --list | grep -q "ii *$app-ynh-deps" && apt remove $app-ynh-deps --assume-yes || true + dpkg --list | grep -q 'ii *nyancat' && apt remove nyancat --assume-yes || true + dpkg --list | grep -q 'ii *sl' && apt remove sl --assume-yes || true + + ! _ynh_apt_package_is_installed "$app-ynh-deps" + ! _ynh_apt_package_is_installed "nyancat" + ! _ynh_apt_package_is_installed "sl" + + ynh_apt_install_dependencies "nyancat sl" + + _ynh_apt_package_is_installed "$app-ynh-deps" + _ynh_apt_package_is_installed "nyancat" + _ynh_apt_package_is_installed "sl" + + ynh_apt_remove_dependencies + + ! _ynh_apt_package_is_installed "$app-ynh-deps" + ! _ynh_apt_package_is_installed "nyancat" + ! _ynh_apt_package_is_installed "sl" +} diff --git a/tests/test_helpers.d/ynhtest_config.sh b/tests/test_helpers.v2.1.d/ynhtest_config.sh similarity index 100% rename from tests/test_helpers.d/ynhtest_config.sh rename to tests/test_helpers.v2.1.d/ynhtest_config.sh diff --git a/tests/test_helpers.v2.1.d/ynhtest_logging.sh b/tests/test_helpers.v2.1.d/ynhtest_logging.sh new file mode 100644 index 000000000..1b2452bc4 --- /dev/null +++ b/tests/test_helpers.v2.1.d/ynhtest_logging.sh @@ -0,0 +1,92 @@ +ynhtest_exec_warn_less() { + + FOO='foo' + bar="" + BAR='$bar' + FOOBAR="foo bar" + + # These looks like stupid edge case + # but in fact happens when dealing with passwords + # (which could also contain bash chars like [], {}, ...) + # or urls containing &, ... + FOOANDBAR="foo&bar" + FOO1QUOTEBAR="foo'bar" + FOO2QUOTEBAR="foo\"bar" + + ynh_hide_warnings uptime + + test ! -e $FOO + ynh_hide_warnings touch $FOO + test -e $FOO + rm $FOO + + test ! -e $FOO1QUOTEBAR + ynh_hide_warnings touch $FOO1QUOTEBAR + test -e $FOO1QUOTEBAR + rm $FOO1QUOTEBAR + + test ! -e $FOO2QUOTEBAR + ynh_hide_warnings touch $FOO2QUOTEBAR + test -e $FOO2QUOTEBAR + rm $FOO2QUOTEBAR + + test ! -e $BAR + ynh_hide_warnings touch $BAR + test -e $BAR + rm $BAR + + test ! -e "$FOOBAR" + ynh_hide_warnings touch "$FOOBAR" + test -e "$FOOBAR" + rm "$FOOBAR" + + test ! -e "$FOOANDBAR" + ynh_hide_warnings touch $FOOANDBAR + test -e "$FOOANDBAR" + rm "$FOOANDBAR" + + ########################### + # Legacy stuff using eval # + ########################### + + test ! -e $FOO + ynh_hide_warnings "touch $FOO" + test -e $FOO + rm $FOO + + test ! -e $FOO1QUOTEBAR + ynh_hide_warnings "touch \"$FOO1QUOTEBAR\"" + # (this works but expliciy *double* quotes have to be provided) + test -e $FOO1QUOTEBAR + rm $FOO1QUOTEBAR + + #test ! -e $FOO2QUOTEBAR + #ynh_hide_warnings "touch \'$FOO2QUOTEBAR\'" + ## (this doesn't work with simple or double quotes) + #test -e $FOO2QUOTEBAR + #rm $FOO2QUOTEBAR + + test ! -e $BAR + ynh_hide_warnings 'touch $BAR' + # That one works because $BAR is only interpreted during eval + test -e $BAR + rm $BAR + + #test ! -e $BAR + #ynh_hide_warnings "touch $BAR" + # That one doesn't work because $bar gets interpreted as empty var by eval... + #test -e $BAR + #rm $BAR + + test ! -e "$FOOBAR" + ynh_hide_warnings "touch \"$FOOBAR\"" + # (works but requires explicit double quotes otherwise eval would interpret 'foo bar' as two separate args..) + test -e "$FOOBAR" + rm "$FOOBAR" + + test ! -e "$FOOANDBAR" + ynh_hide_warnings "touch \"$FOOANDBAR\"" + # (works but requires explicit double quotes otherwise eval would interpret '&' as a "run command in background" and also bar is not a valid command) + test -e "$FOOANDBAR" + rm "$FOOANDBAR" +} diff --git a/tests/test_helpers.v2.1.d/ynhtest_safe_rm.sh b/tests/test_helpers.v2.1.d/ynhtest_safe_rm.sh new file mode 100644 index 000000000..a967d6f8a --- /dev/null +++ b/tests/test_helpers.v2.1.d/ynhtest_safe_rm.sh @@ -0,0 +1,71 @@ +ynhtest_acceptable_path_to_delete() { + + mkdir -p /home/someuser + mkdir -p /home/$app + mkdir -p /home/yunohost.app/$app + mkdir -p /var/www/$app + touch /var/www/$app/bar + touch /etc/cron.d/$app + + ! _acceptable_path_to_delete / + ! _acceptable_path_to_delete //// + ! _acceptable_path_to_delete " //// " + ! _acceptable_path_to_delete /var + ! _acceptable_path_to_delete /var/www + ! _acceptable_path_to_delete /var/cache + ! _acceptable_path_to_delete /usr + ! _acceptable_path_to_delete /usr/bin + ! _acceptable_path_to_delete /home + ! _acceptable_path_to_delete /home/yunohost.backup + ! _acceptable_path_to_delete /home/yunohost.app + ! _acceptable_path_to_delete /home/yunohost.app/ + ! _acceptable_path_to_delete ///home///yunohost.app/// + ! _acceptable_path_to_delete /home/yunohost.app/$app/.. + ! _acceptable_path_to_delete ///home///yunohost.app///$app///..// + ! _acceptable_path_to_delete /home/yunohost.app/../$app/.. + ! _acceptable_path_to_delete /home/someuser + ! _acceptable_path_to_delete /home/yunohost.app//../../$app + ! _acceptable_path_to_delete " /home/yunohost.app/// " + ! _acceptable_path_to_delete /etc/cron.d/ + ! _acceptable_path_to_delete /etc/yunohost/ + + _acceptable_path_to_delete /home/yunohost.app/$app + _acceptable_path_to_delete /home/yunohost.app/$app/bar + _acceptable_path_to_delete /etc/cron.d/$app + _acceptable_path_to_delete /var/www/$app/bar + _acceptable_path_to_delete /var/www/$app + + rm /var/www/$app/bar + rm /etc/cron.d/$app + rmdir /home/yunohost.app/$app + rmdir /home/$app + rmdir /home/someuser + rmdir /var/www/$app +} + +ynhtest_safe_rm() { + + mkdir -p /home/someuser + mkdir -p /home/yunohost.app/$app + mkdir -p /var/www/$app + mkdir -p /var/whatever + touch /var/www/$app/bar + touch /etc/cron.d/$app + + ! ynh_safe_rm "/home/someuser" + ! ynh_safe_rm "/home/yunohost.app/" + ! ynh_safe_rm "/var/whatever" + ynh_safe_rm "/home/yunohost.app/$app" + ynh_safe_rm "/var/www/$app" + ynh_safe_rm "/etc/cron.d/$app" + + test -e /home/someuser + test -e /home/yunohost.app + test -e /var/whatever + ! test -e /home/yunohost.app/$app + ! test -e /var/www/$app + ! test -e /etc/cron.d/$app + + rmdir /home/someuser + rmdir /var/whatever +} diff --git a/tests/test_helpers.v2.1.d/ynhtest_settings.sh b/tests/test_helpers.v2.1.d/ynhtest_settings.sh new file mode 100644 index 000000000..be765be82 --- /dev/null +++ b/tests/test_helpers.v2.1.d/ynhtest_settings.sh @@ -0,0 +1,63 @@ +ynhtest_settings() { + + test -n "$app" + + mkdir -p "/etc/yunohost/apps/$app" + echo "label: $app" > "/etc/yunohost/apps/$app/settings.yml" + + test -z "$(ynh_app_setting_get --key="foo")" + test -z "$(ynh_app_setting_get --key="bar")" + test -z "$(ynh_app_setting_get --app="$app" --key="baz")" + + ynh_app_setting_set --key="foo" --value="foovalue" + ynh_app_setting_set --app="$app" --key="bar" --value="barvalue" + ynh_app_setting_set "$app" baz bazvalue + + test "$(ynh_app_setting_get --key="foo")" == "foovalue" + test "$(ynh_app_setting_get --key="bar")" == "barvalue" + test "$(ynh_app_setting_get --app="$app" --key="baz")" == "bazvalue" + + ynh_app_setting_delete --key="foo" + ynh_app_setting_delete --app="$app" --key="bar" + ynh_app_setting_delete "$app" baz + + test -z "$(ynh_app_setting_get --key="foo")" + test -z "$(ynh_app_setting_get --key="bar")" + test -z "$(ynh_app_setting_get --app="$app" --key="baz")" + + rm -rf "/etc/yunohost/apps/$app" +} + +ynhtest_setting_set_default() { + + test -n "$app" + + mkdir -p "/etc/yunohost/apps/$app" + echo "label: $app" > "/etc/yunohost/apps/$app/settings.yml" + + test -z "$(ynh_app_setting_get --key="foo")" + test -z "${foo:-}" + + ynh_app_setting_set_default --key="foo" --value="foovalue" + + test "${foo:-}" == "foovalue" + test "$(ynh_app_setting_get --key="foo")" == "foovalue" + + ynh_app_setting_set_default --key="foo" --value="bar" + + test "${foo:-}" == "foovalue" + test "$(ynh_app_setting_get --key="foo")" == "foovalue" + + ynh_app_setting_delete --key="foo" + + test "${foo:-}" == "foovalue" + test -z "$(ynh_app_setting_get --key="foo")" + + ynh_app_setting_set_default --key="foo" --value="bar" + + # Hmmm debatable ? But that's how it works right now because the var still exists + test "${foo:-}" == "foovalue" + test -z "$(ynh_app_setting_get --key="foo")" + + rm -rf "/etc/yunohost/apps/$app" +} diff --git a/tests/test_helpers.v2.1.d/ynhtest_setup_source.sh b/tests/test_helpers.v2.1.d/ynhtest_setup_source.sh new file mode 100644 index 000000000..323b74796 --- /dev/null +++ b/tests/test_helpers.v2.1.d/ynhtest_setup_source.sh @@ -0,0 +1,111 @@ +_make_dummy_manifest() { + if [ ! -e $HTTPSERVER_DIR/dummy.tar.gz ] + then + pushd "$HTTPSERVER_DIR" + mkdir dummy + pushd dummy + echo "Lorem Ipsum" > index.html + echo '{"foo": "bar"}' > conf.json + mkdir assets + echo '.some.css { }' > assets/main.css + echo 'var some="js";' > assets/main.js + popd + tar -czf dummy.tar.gz dummy + popd + fi + + cat << EOF +packaging_format = 2 +id = "helloworld" +version = "0.1~ynh2" + +[resources] + [resources.sources.dummy] + url = "http://127.0.0.1:$HTTPSERVER_PORT/dummy.tar.gz" + sha256 = "$(sha256sum $HTTPSERVER_DIR/dummy.tar.gz | awk '{print $1}')" + + [resources.install_dir] + group = "www-data:r-x" +EOF + +} + +ynhtest_setup_source_nominal() { + install_dir="$(mktemp -d -p $VAR_WWW)" + _make_dummy_manifest > ../manifest.toml + + ynh_setup_source --dest_dir="$install_dir" --source_id="dummy" + + test -e "$install_dir" + test -e "$install_dir/index.html" + + ls -ld "$install_dir" | grep -q "drwxr-x--- . $app www-data" + ls -l "$install_dir/index.html" | grep -q "\-rw-r----- . $app www-data" +} + +ynhtest_setup_source_no_group_in_manifest() { + install_dir="$(mktemp -d -p $VAR_WWW)" + _make_dummy_manifest > ../manifest.toml + sed '/www-data/d' -i ../manifest.toml + + ynh_setup_source --dest_dir="$install_dir" --source_id="dummy" + + test -e "$install_dir" + test -e "$install_dir/index.html" + + ls -ld "$install_dir" | grep -q "drwxr-x--- . $app $app" + ls -l "$install_dir/index.html" | grep -q "\-rw-r----- . $app $app" +} + + +ynhtest_setup_source_nominal_upgrade() { + install_dir="$(mktemp -d -p $VAR_WWW)" + _make_dummy_manifest > ../manifest.toml + + ynh_setup_source --dest_dir="$install_dir" --source_id="dummy" + + test "$(cat $install_dir/index.html)" == "Lorem Ipsum" + + # Except index.html to get overwritten during next ynh_setup_source + echo "IEditedYou!" > $install_dir/index.html + test "$(cat $install_dir/index.html)" == "IEditedYou!" + + ynh_setup_source --dest_dir="$install_dir" --source_id="dummy" + + test "$(cat $install_dir/index.html)" == "Lorem Ipsum" +} + + +ynhtest_setup_source_with_keep() { + install_dir="$(mktemp -d -p $VAR_WWW)" + _make_dummy_manifest > ../manifest.toml + + echo "IEditedYou!" > $install_dir/index.html + echo "IEditedYou!" > $install_dir/test.txt + + ynh_setup_source --dest_dir="$install_dir" --source_id="dummy" --keep="index.html test.txt" + + test -e "$install_dir" + test -e "$install_dir/index.html" + test -e "$install_dir/test.txt" + test "$(cat $install_dir/index.html)" == "IEditedYou!" + test "$(cat $install_dir/test.txt)" == "IEditedYou!" +} + +ynhtest_setup_source_with_patch() { + install_dir="$(mktemp -d -p $VAR_WWW)" + _make_dummy_manifest > ../manifest.toml + + mkdir -p ../patches/dummy/ + cat > ../patches/dummy/index.html.patch << EOF +--- a/index.html ++++ b/index.html +@@ -1 +1,1 @@ +-Lorem Ipsum ++Lorem Ipsum dolor sit amet +EOF + + ynh_setup_source --dest_dir="$install_dir" --source_id="dummy" + + test "$(cat $install_dir/index.html)" == "Lorem Ipsum dolor sit amet" +} diff --git a/tests/test_helpers.v2.1.d/ynhtest_templating.sh b/tests/test_helpers.v2.1.d/ynhtest_templating.sh new file mode 100644 index 000000000..c8015093a --- /dev/null +++ b/tests/test_helpers.v2.1.d/ynhtest_templating.sh @@ -0,0 +1,62 @@ +ynhtest_simple_template_app_config() { + + mkdir -p /etc/yunohost/apps/$app/ + echo "id: $app" > /etc/yunohost/apps/$app/settings.yml + + template="$(mktemp -d -p $VAR_WWW)/template.txt" + cat << EOF > $template +app=__APP__ +foo=__FOO__ +EOF + + foo="bar" + + ynh_config_add --template="$template" --destination="$VAR_WWW/config.txt" + + test "$(cat $VAR_WWW/config.txt)" == "$(echo -ne 'app=ynhtest\nfoo=bar')" + test "$(ls -l $VAR_WWW/config.txt | cut -d' ' -f1-4)" == "-rw-r----- 1 ynhtest ynhtest" +} + +ynhtest_simple_template_system_config() { + + mkdir -p /etc/yunohost/apps/$app/ + echo "id: $app" > /etc/yunohost/apps/$app/settings.yml + + rm -f /etc/cron.d/ynhtest_config + + template="$(mktemp -d -p $VAR_WWW)/template.txt" + cat << EOF > $template +app=__APP__ +foo=__FOO__ +EOF + + foo="bar" + + ynh_config_add --template="$template" --destination="/etc/cron.d/ynhtest_config" + + test "$(cat $VAR_WWW/config.txt)" == "$(echo -ne 'app=ynhtest\nfoo=bar')" + test "$(ls -l /etc/cron.d/ynhtest_config | cut -d' ' -f1-4)" == "-r-------- 1 root root" + + rm -f /etc/cron.d/ynhtest_config +} + +ynhtest_jinja_template_app_config() { + + mkdir -p /etc/yunohost/apps/$app/ + echo "id: $app" > /etc/yunohost/apps/$app/settings.yml + + template="$(mktemp -d -p $VAR_WWW)/template.txt" + cat << EOF > $template +app={{ app }} +{% if foo == "bar" %}foo=true{% endif %} +EOF + + foo="bar" + + ynh_config_add --template="$template" --destination="$VAR_WWW/config.txt" --jinja + + test "$(cat $VAR_WWW/config.txt)" == "$(echo -ne 'app=ynhtest\nfoo=true')" + test "$(ls -l $VAR_WWW/config.txt | cut -d' ' -f1-4)" == "-rw-r----- 1 ynhtest ynhtest" +} + + diff --git a/tests/test_helpers.d/ynhtest_user.sh b/tests/test_helpers.v2.1.d/ynhtest_user.sh similarity index 100% rename from tests/test_helpers.d/ynhtest_user.sh rename to tests/test_helpers.v2.1.d/ynhtest_user.sh diff --git a/tests/test_helpers.d/ynhtest_apt.sh b/tests/test_helpers.v2.d/ynhtest_apt.sh similarity index 100% rename from tests/test_helpers.d/ynhtest_apt.sh rename to tests/test_helpers.v2.d/ynhtest_apt.sh diff --git a/tests/test_helpers.v2.d/ynhtest_config.sh b/tests/test_helpers.v2.d/ynhtest_config.sh new file mode 100644 index 000000000..b64943a48 --- /dev/null +++ b/tests/test_helpers.v2.d/ynhtest_config.sh @@ -0,0 +1,662 @@ + +################# +# _ __ _ _ # +# | '_ \| | | | # +# | |_) | |_| | # +# | .__/ \__, | # +# | | __/ | # +# |_| |___/ # +# # +################# + +_read_py() { + local file="$1" + local key="$2" + python3 -c "exec(open('$file').read()); print($key)" +} + +ynhtest_config_read_py() { + + local dummy_dir="$(mktemp -d -p $VAR_WWW)" + file="$dummy_dir/dummy.py" + + cat << EOF > $dummy_dir/dummy.py +# Some comment +FOO = None +ENABLED = False +# TITLE = "Old title" +TITLE = "Lorem Ipsum" +THEME = "colib'ris" +EMAIL = "root@example.com" # This is a comment without quotes +PORT = 1234 # This is a comment without quotes +URL = 'https://yunohost.org' +DICT = {} +DICT['ldap_base'] = "ou=users,dc=yunohost,dc=org" +DICT['ldap_conf'] = {} +DICT['ldap_conf']['user'] = "camille" +# YNH_ICI +DICT['TITLE'] = "Hello world" +EOF + + test "$(_read_py "$file" "FOO")" == "None" + test "$(ynh_read_var_in_file "$file" "FOO")" == "None" + + test "$(_read_py "$file" "ENABLED")" == "False" + test "$(ynh_read_var_in_file "$file" "ENABLED")" == "False" + + test "$(_read_py "$file" "TITLE")" == "Lorem Ipsum" + test "$(ynh_read_var_in_file "$file" "TITLE")" == "Lorem Ipsum" + + test "$(_read_py "$file" "THEME")" == "colib'ris" + test "$(ynh_read_var_in_file "$file" "THEME")" == "colib'ris" + + test "$(_read_py "$file" "EMAIL")" == "root@example.com" + test "$(ynh_read_var_in_file "$file" "EMAIL")" == "root@example.com" + + test "$(_read_py "$file" "PORT")" == "1234" + test "$(ynh_read_var_in_file "$file" "PORT")" == "1234" + + test "$(_read_py "$file" "URL")" == "https://yunohost.org" + test "$(ynh_read_var_in_file "$file" "URL")" == "https://yunohost.org" + + test "$(ynh_read_var_in_file "$file" "ldap_base")" == "ou=users,dc=yunohost,dc=org" + + test "$(ynh_read_var_in_file "$file" "user")" == "camille" + + test "$(ynh_read_var_in_file "$file" "TITLE" "YNH_ICI")" == "Hello world" + + ! _read_py "$file" "NONEXISTENT" + test "$(ynh_read_var_in_file "$file" "NONEXISTENT")" == "YNH_NULL" + + ! _read_py "$file" "ENABLE" + test "$(ynh_read_var_in_file "$file" "ENABLE")" == "YNH_NULL" +} + +ynhtest_config_write_py() { + local dummy_dir="$(mktemp -d -p $VAR_WWW)" + file="$dummy_dir/dummy.py" + + cat << EOF > $dummy_dir/dummy.py +# Some comment +FOO = None +ENABLED = False +# TITLE = "Old title" +TITLE = "Lorem Ipsum" +THEME = "colib'ris" +EMAIL = "root@example.com" # This is a comment without quotes +PORT = 1234 # This is a comment without quotes +URL = 'https://yunohost.org' +DICT = {} +DICT['ldap_base'] = "ou=users,dc=yunohost,dc=org" +# YNH_ICI +DICT['TITLE'] = "Hello world" +EOF + + ynh_write_var_in_file "$file" "FOO" "bar" + test "$(_read_py "$file" "FOO")" == "bar" + test "$(ynh_read_var_in_file "$file" "FOO")" == "bar" + + ynh_write_var_in_file "$file" "ENABLED" "True" + test "$(_read_py "$file" "ENABLED")" == "True" + test "$(ynh_read_var_in_file "$file" "ENABLED")" == "True" + + ynh_write_var_in_file "$file" "TITLE" "Foo Bar" + test "$(_read_py "$file" "TITLE")" == "Foo Bar" + test "$(ynh_read_var_in_file "$file" "TITLE")" == "Foo Bar" + + ynh_write_var_in_file "$file" "THEME" "super-awesome-theme" + test "$(_read_py "$file" "THEME")" == "super-awesome-theme" + test "$(ynh_read_var_in_file "$file" "THEME")" == "super-awesome-theme" + + ynh_write_var_in_file "$file" "EMAIL" "sam@domain.tld" + test "$(_read_py "$file" "EMAIL")" == "sam@domain.tld" + test "$(ynh_read_var_in_file "$file" "EMAIL")" == "sam@domain.tld" + + ynh_write_var_in_file "$file" "PORT" "5678" + test "$(_read_py "$file" "PORT")" == "5678" + test "$(ynh_read_var_in_file "$file" "PORT")" == "5678" + + ynh_write_var_in_file "$file" "URL" "https://domain.tld/foobar" + test "$(_read_py "$file" "URL")" == "https://domain.tld/foobar" + test "$(ynh_read_var_in_file "$file" "URL")" == "https://domain.tld/foobar" + + ynh_write_var_in_file "$file" "ldap_base" "ou=users,dc=yunohost,dc=org" + test "$(ynh_read_var_in_file "$file" "ldap_base")" == "ou=users,dc=yunohost,dc=org" + + ynh_write_var_in_file "$file" "TITLE" "YOLO" "YNH_ICI" + test "$(ynh_read_var_in_file "$file" "TITLE" "YNH_ICI")" == "YOLO" + + ! ynh_write_var_in_file "$file" "NONEXISTENT" "foobar" + ! _read_py "$file" "NONEXISTENT" + test "$(ynh_read_var_in_file "$file" "NONEXISTENT")" == "YNH_NULL" + + ! ynh_write_var_in_file "$file" "ENABLE" "foobar" + ! _read_py "$file" "ENABLE" + test "$(ynh_read_var_in_file "$file" "ENABLE")" == "YNH_NULL" + +} + +############### +# _ _ # +# (_) (_) # +# _ _ __ _ # +# | | '_ \| | # +# | | | | | | # +# |_|_| |_|_| # +# # +############### + +_read_ini() { + local file="$1" + local key="$2" + python3 -c "import configparser; c = configparser.ConfigParser(); c.read('$file'); print(c['main']['$key'])" +} + +ynhtest_config_read_ini() { + local dummy_dir="$(mktemp -d -p $VAR_WWW)" + file="$dummy_dir/dummy.ini" + + cat << EOF > $file +# Some comment +; Another comment +[main] +foo = null +enabled = False +# title = Old title +title = Lorem Ipsum +theme = colib'ris +email = root@example.com ; This is a comment without quotes +port = 1234 ; This is a comment without quotes +url = https://yunohost.org +[dict] + ldap_base = ou=users,dc=yunohost,dc=org +EOF + + test "$(_read_ini "$file" "foo")" == "null" + test "$(ynh_read_var_in_file "$file" "foo")" == "null" + + test "$(_read_ini "$file" "enabled")" == "False" + test "$(ynh_read_var_in_file "$file" "enabled")" == "False" + + test "$(_read_ini "$file" "title")" == "Lorem Ipsum" + test "$(ynh_read_var_in_file "$file" "title")" == "Lorem Ipsum" + + test "$(_read_ini "$file" "theme")" == "colib'ris" + test "$(ynh_read_var_in_file "$file" "theme")" == "colib'ris" + + #test "$(_read_ini "$file" "email")" == "root@example.com" + test "$(ynh_read_var_in_file "$file" "email")" == "root@example.com" + + #test "$(_read_ini "$file" "port")" == "1234" + test "$(ynh_read_var_in_file "$file" "port")" == "1234" + + test "$(_read_ini "$file" "url")" == "https://yunohost.org" + test "$(ynh_read_var_in_file "$file" "url")" == "https://yunohost.org" + + test "$(ynh_read_var_in_file "$file" "ldap_base")" == "ou=users,dc=yunohost,dc=org" + + ! _read_ini "$file" "nonexistent" + test "$(ynh_read_var_in_file "$file" "nonexistent")" == "YNH_NULL" + + ! _read_ini "$file" "enable" + test "$(ynh_read_var_in_file "$file" "enable")" == "YNH_NULL" + +} + +ynhtest_config_write_ini() { + local dummy_dir="$(mktemp -d -p $VAR_WWW)" + file="$dummy_dir/dummy.ini" + + cat << EOF > $file +# Some comment +; Another comment +[main] +foo = null +enabled = False +# title = Old title +title = Lorem Ipsum +theme = colib'ris +email = root@example.com # This is a comment without quotes +port = 1234 # This is a comment without quotes +url = https://yunohost.org +[dict] + ldap_base = ou=users,dc=yunohost,dc=org +EOF + + ynh_write_var_in_file "$file" "foo" "bar" + test "$(_read_ini "$file" "foo")" == "bar" + test "$(ynh_read_var_in_file "$file" "foo")" == "bar" + + ynh_write_var_in_file "$file" "enabled" "True" + test "$(_read_ini "$file" "enabled")" == "True" + test "$(ynh_read_var_in_file "$file" "enabled")" == "True" + + ynh_write_var_in_file "$file" "title" "Foo Bar" + test "$(_read_ini "$file" "title")" == "Foo Bar" + test "$(ynh_read_var_in_file "$file" "title")" == "Foo Bar" + + ynh_write_var_in_file "$file" "theme" "super-awesome-theme" + test "$(_read_ini "$file" "theme")" == "super-awesome-theme" + test "$(ynh_read_var_in_file "$file" "theme")" == "super-awesome-theme" + + ynh_write_var_in_file "$file" "email" "sam@domain.tld" + test "$(_read_ini "$file" "email")" == "sam@domain.tld # This is a comment without quotes" + test "$(ynh_read_var_in_file "$file" "email")" == "sam@domain.tld" + + ynh_write_var_in_file "$file" "port" "5678" + test "$(_read_ini "$file" "port")" == "5678 # This is a comment without quotes" + test "$(ynh_read_var_in_file "$file" "port")" == "5678" + + ynh_write_var_in_file "$file" "url" "https://domain.tld/foobar" + test "$(_read_ini "$file" "url")" == "https://domain.tld/foobar" + test "$(ynh_read_var_in_file "$file" "url")" == "https://domain.tld/foobar" + + ynh_write_var_in_file "$file" "ldap_base" "ou=users,dc=yunohost,dc=org" + test "$(ynh_read_var_in_file "$file" "ldap_base")" == "ou=users,dc=yunohost,dc=org" + + ! ynh_write_var_in_file "$file" "nonexistent" "foobar" + ! _read_ini "$file" "nonexistent" + test "$(ynh_read_var_in_file "$file" "nonexistent")" == "YNH_NULL" + + ! ynh_write_var_in_file "$file" "enable" "foobar" + ! _read_ini "$file" "enable" + test "$(ynh_read_var_in_file "$file" "enable")" == "YNH_NULL" + +} + +############################# +# _ # +# | | # +# _ _ __ _ _ __ ___ | | # +# | | | |/ _` | '_ ` _ \| | # +# | |_| | (_| | | | | | | | # +# \__, |\__,_|_| |_| |_|_| # +# __/ | # +# |___/ # +# # +############################# + +_read_yaml() { + local file="$1" + local key="$2" + python3 -c "import yaml; print(yaml.safe_load(open('$file'))['$key'])" +} + +ynhtest_config_read_yaml() { + local dummy_dir="$(mktemp -d -p $VAR_WWW)" + file="$dummy_dir/dummy.yml" + + cat << EOF > $file +# Some comment +foo: +enabled: false +# title: old title +title: Lorem Ipsum +theme: colib'ris +email: root@example.com # This is a comment without quotes +port: 1234 # This is a comment without quotes +url: https://yunohost.org +dict: + ldap_base: ou=users,dc=yunohost,dc=org +EOF + + test "$(_read_yaml "$file" "foo")" == "None" + test "$(ynh_read_var_in_file "$file" "foo")" == "" + + test "$(_read_yaml "$file" "enabled")" == "False" + test "$(ynh_read_var_in_file "$file" "enabled")" == "false" + + test "$(_read_yaml "$file" "title")" == "Lorem Ipsum" + test "$(ynh_read_var_in_file "$file" "title")" == "Lorem Ipsum" + + test "$(_read_yaml "$file" "theme")" == "colib'ris" + test "$(ynh_read_var_in_file "$file" "theme")" == "colib'ris" + + test "$(_read_yaml "$file" "email")" == "root@example.com" + test "$(ynh_read_var_in_file "$file" "email")" == "root@example.com" + + test "$(_read_yaml "$file" "port")" == "1234" + test "$(ynh_read_var_in_file "$file" "port")" == "1234" + + test "$(_read_yaml "$file" "url")" == "https://yunohost.org" + test "$(ynh_read_var_in_file "$file" "url")" == "https://yunohost.org" + + test "$(ynh_read_var_in_file "$file" "ldap_base")" == "ou=users,dc=yunohost,dc=org" + + ! _read_yaml "$file" "nonexistent" + test "$(ynh_read_var_in_file "$file" "nonexistent")" == "YNH_NULL" + + ! _read_yaml "$file" "enable" + test "$(ynh_read_var_in_file "$file" "enable")" == "YNH_NULL" +} + + +ynhtest_config_write_yaml() { + local dummy_dir="$(mktemp -d -p $VAR_WWW)" + file="$dummy_dir/dummy.yml" + + cat << EOF > $file +# Some comment +foo: +enabled: false +# title: old title +title: Lorem Ipsum +theme: colib'ris +email: root@example.com # This is a comment without quotes +port: 1234 # This is a comment without quotes +url: https://yunohost.org +dict: + ldap_base: ou=users,dc=yunohost,dc=org +EOF + + ynh_write_var_in_file "$file" "foo" "bar" + # cat $dummy_dir/dummy.yml # to debug + ! test "$(_read_yaml "$file" "foo")" == "bar" # writing broke the yaml syntax... "foo:bar" (no space aftr :) + test "$(ynh_read_var_in_file "$file" "foo")" == "bar" + + ynh_write_var_in_file "$file" "enabled" "true" + test "$(_read_yaml "$file" "enabled")" == "True" + test "$(ynh_read_var_in_file "$file" "enabled")" == "true" + + ynh_write_var_in_file "$file" "title" "Foo Bar" + test "$(_read_yaml "$file" "title")" == "Foo Bar" + test "$(ynh_read_var_in_file "$file" "title")" == "Foo Bar" + + ynh_write_var_in_file "$file" "theme" "super-awesome-theme" + test "$(_read_yaml "$file" "theme")" == "super-awesome-theme" + test "$(ynh_read_var_in_file "$file" "theme")" == "super-awesome-theme" + + ynh_write_var_in_file "$file" "email" "sam@domain.tld" + test "$(_read_yaml "$file" "email")" == "sam@domain.tld" + test "$(ynh_read_var_in_file "$file" "email")" == "sam@domain.tld" + + ynh_write_var_in_file "$file" "port" "5678" + test "$(_read_yaml "$file" "port")" == "5678" + test "$(ynh_read_var_in_file "$file" "port")" == "5678" + + ynh_write_var_in_file "$file" "url" "https://domain.tld/foobar" + test "$(_read_yaml "$file" "url")" == "https://domain.tld/foobar" + test "$(ynh_read_var_in_file "$file" "url")" == "https://domain.tld/foobar" + + ynh_write_var_in_file "$file" "ldap_base" "ou=foobar,dc=domain,dc=tld" + test "$(ynh_read_var_in_file "$file" "ldap_base")" == "ou=foobar,dc=domain,dc=tld" + + ! ynh_write_var_in_file "$file" "nonexistent" "foobar" + test "$(ynh_read_var_in_file "$file" "nonexistent")" == "YNH_NULL" + + ! ynh_write_var_in_file "$file" "enable" "foobar" + test "$(ynh_read_var_in_file "$file" "enable")" == "YNH_NULL" + test "$(ynh_read_var_in_file "$file" "enabled")" == "true" +} + +######################### +# _ # +# (_) # +# _ ___ ___ _ __ # +# | / __|/ _ \| '_ \ # +# | \__ \ (_) | | | | # +# | |___/\___/|_| |_| # +# _/ | # +# |__/ # +# # +######################### + +_read_json() { + local file="$1" + local key="$2" + python3 -c "import json; print(json.load(open('$file'))['$key'])" +} + +ynhtest_config_read_json() { + local dummy_dir="$(mktemp -d -p $VAR_WWW)" + file="$dummy_dir/dummy.json" + + cat << EOF > $file +{ + "foo": null, + "enabled": false, + "title": "Lorem Ipsum", + "theme": "colib'ris", + "email": "root@example.com", + "port": 1234, + "url": "https://yunohost.org", + "dict": { + "ldap_base": "ou=users,dc=yunohost,dc=org" + } +} +EOF + + + test "$(_read_json "$file" "foo")" == "None" + test "$(ynh_read_var_in_file "$file" "foo")" == "null" + + test "$(_read_json "$file" "enabled")" == "False" + test "$(ynh_read_var_in_file "$file" "enabled")" == "false" + + test "$(_read_json "$file" "title")" == "Lorem Ipsum" + test "$(ynh_read_var_in_file "$file" "title")" == "Lorem Ipsum" + + test "$(_read_json "$file" "theme")" == "colib'ris" + test "$(ynh_read_var_in_file "$file" "theme")" == "colib'ris" + + test "$(_read_json "$file" "email")" == "root@example.com" + test "$(ynh_read_var_in_file "$file" "email")" == "root@example.com" + + test "$(_read_json "$file" "port")" == "1234" + test "$(ynh_read_var_in_file "$file" "port")" == "1234" + + test "$(_read_json "$file" "url")" == "https://yunohost.org" + test "$(ynh_read_var_in_file "$file" "url")" == "https://yunohost.org" + + test "$(ynh_read_var_in_file "$file" "ldap_base")" == "ou=users,dc=yunohost,dc=org" + + ! _read_json "$file" "nonexistent" + test "$(ynh_read_var_in_file "$file" "nonexistent")" == "YNH_NULL" + + ! _read_json "$file" "enable" + test "$(ynh_read_var_in_file "$file" "enable")" == "YNH_NULL" +} + + +ynhtest_config_write_json() { + local dummy_dir="$(mktemp -d -p $VAR_WWW)" + file="$dummy_dir/dummy.json" + + cat << EOF > $file +{ + "foo": null, + "enabled": false, + "title": "Lorem Ipsum", + "theme": "colib'ris", + "email": "root@example.com", + "port": 1234, + "url": "https://yunohost.org", + "dict": { + "ldap_base": "ou=users,dc=yunohost,dc=org" + } +} +EOF + + ynh_write_var_in_file "$file" "foo" "bar" + cat $file + test "$(_read_json "$file" "foo")" == "bar" + test "$(ynh_read_var_in_file "$file" "foo")" == "bar" + + ynh_write_var_in_file "$file" "enabled" "true" + cat $file + test "$(_read_json "$file" "enabled")" == "true" + test "$(ynh_read_var_in_file "$file" "enabled")" == "true" + + ynh_write_var_in_file "$file" "title" "Foo Bar" + cat $file + test "$(_read_json "$file" "title")" == "Foo Bar" + test "$(ynh_read_var_in_file "$file" "title")" == "Foo Bar" + + ynh_write_var_in_file "$file" "theme" "super-awesome-theme" + cat $file + test "$(_read_json "$file" "theme")" == "super-awesome-theme" + test "$(ynh_read_var_in_file "$file" "theme")" == "super-awesome-theme" + + ynh_write_var_in_file "$file" "email" "sam@domain.tld" + cat $file + test "$(_read_json "$file" "email")" == "sam@domain.tld" + test "$(ynh_read_var_in_file "$file" "email")" == "sam@domain.tld" + + ynh_write_var_in_file "$file" "port" "5678" + test "$(_read_json "$file" "port")" == "5678" + test "$(ynh_read_var_in_file "$file" "port")" == "5678" + + ynh_write_var_in_file "$file" "url" "https://domain.tld/foobar" + test "$(_read_json "$file" "url")" == "https://domain.tld/foobar" + test "$(ynh_read_var_in_file "$file" "url")" == "https://domain.tld/foobar" + + ynh_write_var_in_file "$file" "ldap_base" "ou=foobar,dc=domain,dc=tld" + test "$(ynh_read_var_in_file "$file" "ldap_base")" == "ou=foobar,dc=domain,dc=tld" + + ! ynh_write_var_in_file "$file" "nonexistent" "foobar" + test "$(ynh_read_var_in_file "$file" "nonexistent")" == "YNH_NULL" + + ! ynh_write_var_in_file "$file" "enable" "foobar" + test "$(ynh_read_var_in_file "$file" "enable")" == "YNH_NULL" + test "$(ynh_read_var_in_file "$file" "enabled")" == "true" +} + +####################### +# _ # +# | | # +# _ __ | |__ _ __ # +# | '_ \| '_ \| '_ \ # +# | |_) | | | | |_) | # +# | .__/|_| |_| .__/ # +# | | | | # +# |_| |_| # +# # +####################### + +_read_php() { + local file="$1" + local key="$2" + php -r "include '$file'; echo var_export(\$$key);" | sed "s/^'//g" | sed "s/'$//g" +} + +ynhtest_config_read_php() { + local dummy_dir="$(mktemp -d -p $VAR_WWW)" + file="$dummy_dir/dummy.php" + + cat << EOF > $file + "ou=users,dc=yunohost,dc=org", + 'ldap_conf' => [] + ]; + \$dict['ldap_conf']['user'] = 'camille'; + const DB_HOST = 'localhost'; +?> +EOF + + test "$(_read_php "$file" "foo")" == "NULL" + test "$(ynh_read_var_in_file "$file" "foo")" == "NULL" + + test "$(_read_php "$file" "enabled")" == "false" + test "$(ynh_read_var_in_file "$file" "enabled")" == "false" + + test "$(_read_php "$file" "title")" == "Lorem Ipsum" + test "$(ynh_read_var_in_file "$file" "title")" == "Lorem Ipsum" + + test "$(_read_php "$file" "theme")" == "colib\\'ris" + test "$(ynh_read_var_in_file "$file" "theme")" == "colib'ris" + + test "$(_read_php "$file" "email")" == "root@example.com" + test "$(ynh_read_var_in_file "$file" "email")" == "root@example.com" + + test "$(_read_php "$file" "port")" == "1234" + test "$(ynh_read_var_in_file "$file" "port")" == "1234" + + test "$(_read_php "$file" "url")" == "https://yunohost.org" + test "$(ynh_read_var_in_file "$file" "url")" == "https://yunohost.org" + + test "$(ynh_read_var_in_file "$file" "ldap_base")" == "ou=users,dc=yunohost,dc=org" + + test "$(ynh_read_var_in_file "$file" "user")" == "camille" + + test "$(ynh_read_var_in_file "$file" "DB_HOST")" == "localhost" + + ! _read_php "$file" "nonexistent" + test "$(ynh_read_var_in_file "$file" "nonexistent")" == "YNH_NULL" + + ! _read_php "$file" "enable" + test "$(ynh_read_var_in_file "$file" "enable")" == "YNH_NULL" +} + + +ynhtest_config_write_php() { + local dummy_dir="$(mktemp -d -p $VAR_WWW)" + file="$dummy_dir/dummy.php" + + cat << EOF > $file + "ou=users,dc=yunohost,dc=org", + ]; +?> +EOF + + ynh_write_var_in_file "$file" "foo" "bar" + test "$(_read_php "$file" "foo")" == "bar" + test "$(ynh_read_var_in_file "$file" "foo")" == "bar" + + ynh_write_var_in_file "$file" "enabled" "true" + test "$(_read_php "$file" "enabled")" == "true" + test "$(ynh_read_var_in_file "$file" "enabled")" == "true" + + ynh_write_var_in_file "$file" "title" "Foo Bar" + cat $file + test "$(_read_php "$file" "title")" == "Foo Bar" + test "$(ynh_read_var_in_file "$file" "title")" == "Foo Bar" + + ynh_write_var_in_file "$file" "theme" "super-awesome-theme" + cat $file + test "$(_read_php "$file" "theme")" == "super-awesome-theme" + test "$(ynh_read_var_in_file "$file" "theme")" == "super-awesome-theme" + + ynh_write_var_in_file "$file" "email" "sam@domain.tld" + cat $file + test "$(_read_php "$file" "email")" == "sam@domain.tld" + test "$(ynh_read_var_in_file "$file" "email")" == "sam@domain.tld" + + ynh_write_var_in_file "$file" "port" "5678" + test "$(_read_php "$file" "port")" == "5678" + test "$(ynh_read_var_in_file "$file" "port")" == "5678" + + ynh_write_var_in_file "$file" "url" "https://domain.tld/foobar" + test "$(_read_php "$file" "url")" == "https://domain.tld/foobar" + test "$(ynh_read_var_in_file "$file" "url")" == "https://domain.tld/foobar" + + ynh_write_var_in_file "$file" "ldap_base" "ou=foobar,dc=domain,dc=tld" + test "$(ynh_read_var_in_file "$file" "ldap_base")" == "ou=foobar,dc=domain,dc=tld" + + ! ynh_write_var_in_file "$file" "nonexistent" "foobar" + test "$(ynh_read_var_in_file "$file" "nonexistent")" == "YNH_NULL" + + ! ynh_write_var_in_file "$file" "enable" "foobar" + test "$(ynh_read_var_in_file "$file" "enable")" == "YNH_NULL" + test "$(ynh_read_var_in_file "$file" "enabled")" == "true" +} diff --git a/tests/test_helpers.d/ynhtest_logging.sh b/tests/test_helpers.v2.d/ynhtest_logging.sh similarity index 100% rename from tests/test_helpers.d/ynhtest_logging.sh rename to tests/test_helpers.v2.d/ynhtest_logging.sh diff --git a/tests/test_helpers.d/ynhtest_network.sh b/tests/test_helpers.v2.d/ynhtest_network.sh similarity index 100% rename from tests/test_helpers.d/ynhtest_network.sh rename to tests/test_helpers.v2.d/ynhtest_network.sh diff --git a/tests/test_helpers.d/ynhtest_secure_remove.sh b/tests/test_helpers.v2.d/ynhtest_secure_remove.sh similarity index 100% rename from tests/test_helpers.d/ynhtest_secure_remove.sh rename to tests/test_helpers.v2.d/ynhtest_secure_remove.sh diff --git a/tests/test_helpers.d/ynhtest_settings.sh b/tests/test_helpers.v2.d/ynhtest_settings.sh similarity index 100% rename from tests/test_helpers.d/ynhtest_settings.sh rename to tests/test_helpers.v2.d/ynhtest_settings.sh diff --git a/tests/test_helpers.d/ynhtest_setup_source.sh b/tests/test_helpers.v2.d/ynhtest_setup_source.sh similarity index 100% rename from tests/test_helpers.d/ynhtest_setup_source.sh rename to tests/test_helpers.v2.d/ynhtest_setup_source.sh diff --git a/tests/test_helpers.d/ynhtest_templating.sh b/tests/test_helpers.v2.d/ynhtest_templating.sh similarity index 100% rename from tests/test_helpers.d/ynhtest_templating.sh rename to tests/test_helpers.v2.d/ynhtest_templating.sh diff --git a/tests/test_helpers.v2.d/ynhtest_user.sh b/tests/test_helpers.v2.d/ynhtest_user.sh new file mode 100644 index 000000000..46f2a0cd6 --- /dev/null +++ b/tests/test_helpers.v2.d/ynhtest_user.sh @@ -0,0 +1,25 @@ + +ynhtest_system_user_create() { + username=$(head -c 12 /dev/urandom | md5sum | head -c 12) + + ! ynh_system_user_exists --username="$username" + + ynh_system_user_create --username="$username" + + ynh_system_user_exists --username="$username" + + ynh_system_user_delete --username="$username" + + ! ynh_system_user_exists --username="$username" +} + +ynhtest_system_user_with_group() { + username=$(head -c 12 /dev/urandom | md5sum | head -c 12) + + ynh_system_user_create --username="$username" --groups="ssl-cert,ssh.app" + + grep -q "^ssl-cert:.*$username" /etc/group + grep -q "^ssh.app:.*$username" /etc/group + + ynh_system_user_delete --username="$username" +} From bc3e36abb3394cead6ff868a48a8c6f4018aec2c Mon Sep 17 00:00:00 2001 From: Alexandre Aubin Date: Mon, 1 Jul 2024 21:39:59 +0200 Subject: [PATCH 21/28] friskies --- helpers/helpers.v2.1.d/logging | 5 +- tests/test_helpers.v2.1.d/ynhtest_apt.sh | 6 + tests/test_helpers.v2.1.d/ynhtest_config.sh | 486 +++++++++--------- tests/test_helpers.v2.1.d/ynhtest_logging.sh | 45 +- tests/test_helpers.v2.1.d/ynhtest_settings.sh | 5 - .../ynhtest_setup_source.sh | 3 +- .../test_helpers.v2.1.d/ynhtest_templating.sh | 1 + 7 files changed, 258 insertions(+), 293 deletions(-) diff --git a/helpers/helpers.v2.1.d/logging b/helpers/helpers.v2.1.d/logging index 1d729178a..a2471cd2d 100644 --- a/helpers/helpers.v2.1.d/logging +++ b/helpers/helpers.v2.1.d/logging @@ -7,7 +7,10 @@ ynh_die() { set +o xtrace # set +x if [[ -n "${1:-}" ]] then - python3 -c 'import yaml, sys; print(yaml.dump({"error": sys.stdin.read()}))' <<< "${1:-}" >>"$YNH_STDRETURN" + if [[ -n "${YNH_STDRETURN:-}" ]] + then + python3 -c 'import yaml, sys; print(yaml.dump({"error": sys.stdin.read()}))' <<< "${1:-}" >>"$YNH_STDRETURN" + fi echo "${1:-}" 1>&2 fi exit 1 diff --git a/tests/test_helpers.v2.1.d/ynhtest_apt.sh b/tests/test_helpers.v2.1.d/ynhtest_apt.sh index e415c8135..1fcf3b185 100644 --- a/tests/test_helpers.v2.1.d/ynhtest_apt.sh +++ b/tests/test_helpers.v2.1.d/ynhtest_apt.sh @@ -1,5 +1,11 @@ ynhtest_apt_install_apt_deps_regular() { + cat << EOF > ../manifest.toml +packaging_format = 2 +id = "$app" +version = "0.1~ynh2" +EOF + dpkg --list | grep -q "ii *$app-ynh-deps" && apt remove $app-ynh-deps --assume-yes || true dpkg --list | grep -q 'ii *nyancat' && apt remove nyancat --assume-yes || true dpkg --list | grep -q 'ii *sl' && apt remove sl --assume-yes || true diff --git a/tests/test_helpers.v2.1.d/ynhtest_config.sh b/tests/test_helpers.v2.1.d/ynhtest_config.sh index b64943a48..51fd44cfe 100644 --- a/tests/test_helpers.v2.1.d/ynhtest_config.sh +++ b/tests/test_helpers.v2.1.d/ynhtest_config.sh @@ -38,38 +38,38 @@ DICT['ldap_conf']['user'] = "camille" DICT['TITLE'] = "Hello world" EOF - test "$(_read_py "$file" "FOO")" == "None" - test "$(ynh_read_var_in_file "$file" "FOO")" == "None" + test "$(_read_py "$file" "FOO")" == "None" + test "$(ynh_read_var_in_file --file="$file" --key="FOO")" == "None" - test "$(_read_py "$file" "ENABLED")" == "False" - test "$(ynh_read_var_in_file "$file" "ENABLED")" == "False" + test "$(_read_py "$file" "ENABLED")" == "False" + test "$(ynh_read_var_in_file --file="$file" --key="ENABLED")" == "False" - test "$(_read_py "$file" "TITLE")" == "Lorem Ipsum" - test "$(ynh_read_var_in_file "$file" "TITLE")" == "Lorem Ipsum" + test "$(_read_py "$file" "TITLE")" == "Lorem Ipsum" + test "$(ynh_read_var_in_file --file="$file" --key="TITLE")" == "Lorem Ipsum" - test "$(_read_py "$file" "THEME")" == "colib'ris" - test "$(ynh_read_var_in_file "$file" "THEME")" == "colib'ris" + test "$(_read_py "$file" "THEME")" == "colib'ris" + test "$(ynh_read_var_in_file --file="$file" --key="THEME")" == "colib'ris" - test "$(_read_py "$file" "EMAIL")" == "root@example.com" - test "$(ynh_read_var_in_file "$file" "EMAIL")" == "root@example.com" + test "$(_read_py "$file" "EMAIL")" == "root@example.com" + test "$(ynh_read_var_in_file --file="$file" --key="EMAIL")" == "root@example.com" - test "$(_read_py "$file" "PORT")" == "1234" - test "$(ynh_read_var_in_file "$file" "PORT")" == "1234" + test "$(_read_py "$file" "PORT")" == "1234" + test "$(ynh_read_var_in_file --file="$file" --key="PORT")" == "1234" - test "$(_read_py "$file" "URL")" == "https://yunohost.org" - test "$(ynh_read_var_in_file "$file" "URL")" == "https://yunohost.org" + test "$(_read_py "$file" "URL")" == "https://yunohost.org" + test "$(ynh_read_var_in_file --file="$file" --key="URL")" == "https://yunohost.org" - test "$(ynh_read_var_in_file "$file" "ldap_base")" == "ou=users,dc=yunohost,dc=org" + test "$(ynh_read_var_in_file --file="$file" --key="ldap_base")" == "ou=users,dc=yunohost,dc=org" - test "$(ynh_read_var_in_file "$file" "user")" == "camille" + test "$(ynh_read_var_in_file --file="$file" --key="user")" == "camille" - test "$(ynh_read_var_in_file "$file" "TITLE" "YNH_ICI")" == "Hello world" + test "$(ynh_read_var_in_file --file="$file" --key="TITLE" --after"YNH_ICI")" == "Hello world" - ! _read_py "$file" "NONEXISTENT" - test "$(ynh_read_var_in_file "$file" "NONEXISTENT")" == "YNH_NULL" + ! _read_py "$file" "NONEXISTENT" + test "$(ynh_read_var_in_file --file="$file" --key="NONEXISTENT")" == "YNH_NULL" - ! _read_py "$file" "ENABLE" - test "$(ynh_read_var_in_file "$file" "ENABLE")" == "YNH_NULL" + ! _read_py "$file" "ENABLE" + test "$(ynh_read_var_in_file --file="$file" --key="ENABLE")" == "YNH_NULL" } ynhtest_config_write_py() { @@ -92,47 +92,47 @@ DICT['ldap_base'] = "ou=users,dc=yunohost,dc=org" DICT['TITLE'] = "Hello world" EOF - ynh_write_var_in_file "$file" "FOO" "bar" - test "$(_read_py "$file" "FOO")" == "bar" - test "$(ynh_read_var_in_file "$file" "FOO")" == "bar" + ynh_write_var_in_file --file="$file" --key="FOO" --value="bar" + test "$(_read_py "$file" "FOO")" == "bar" + test "$(ynh_read_var_in_file --file="$file" --key="FOO")" == "bar" - ynh_write_var_in_file "$file" "ENABLED" "True" - test "$(_read_py "$file" "ENABLED")" == "True" - test "$(ynh_read_var_in_file "$file" "ENABLED")" == "True" + ynh_write_var_in_file --file="$file" --key="ENABLED" --value="True" + test "$(_read_py "$file" "ENABLED")" == "True" + test "$(ynh_read_var_in_file --file="$file" --key="ENABLED")" == "True" - ynh_write_var_in_file "$file" "TITLE" "Foo Bar" - test "$(_read_py "$file" "TITLE")" == "Foo Bar" - test "$(ynh_read_var_in_file "$file" "TITLE")" == "Foo Bar" + ynh_write_var_in_file --file="$file" --key="TITLE" --value="Foo Bar" + test "$(_read_py "$file" "TITLE")" == "Foo Bar" + test "$(ynh_read_var_in_file --file="$file" --key="TITLE")" == "Foo Bar" - ynh_write_var_in_file "$file" "THEME" "super-awesome-theme" - test "$(_read_py "$file" "THEME")" == "super-awesome-theme" - test "$(ynh_read_var_in_file "$file" "THEME")" == "super-awesome-theme" + ynh_write_var_in_file --file="$file" --key="THEME" --value="super-awesome-theme" + test "$(_read_py "$file" "THEME")" == "super-awesome-theme" + test "$(ynh_read_var_in_file --file="$file" --key="THEME")" == "super-awesome-theme" - ynh_write_var_in_file "$file" "EMAIL" "sam@domain.tld" - test "$(_read_py "$file" "EMAIL")" == "sam@domain.tld" - test "$(ynh_read_var_in_file "$file" "EMAIL")" == "sam@domain.tld" + ynh_write_var_in_file --file="$file" --key="EMAIL" --value="sam@domain.tld" + test "$(_read_py "$file" "EMAIL")" == "sam@domain.tld" + test "$(ynh_read_var_in_file --file="$file" --key="EMAIL")" == "sam@domain.tld" - ynh_write_var_in_file "$file" "PORT" "5678" - test "$(_read_py "$file" "PORT")" == "5678" - test "$(ynh_read_var_in_file "$file" "PORT")" == "5678" + ynh_write_var_in_file --file="$file" --key="PORT" --value="5678" + test "$(_read_py "$file" "PORT")" == "5678" + test "$(ynh_read_var_in_file --file="$file" --key="PORT")" == "5678" - ynh_write_var_in_file "$file" "URL" "https://domain.tld/foobar" - test "$(_read_py "$file" "URL")" == "https://domain.tld/foobar" - test "$(ynh_read_var_in_file "$file" "URL")" == "https://domain.tld/foobar" + ynh_write_var_in_file --file="$file" --key="URL" --value="https://domain.tld/foobar" + test "$(_read_py "$file" "URL")" == "https://domain.tld/foobar" + test "$(ynh_read_var_in_file --file="$file" --key="URL")" == "https://domain.tld/foobar" - ynh_write_var_in_file "$file" "ldap_base" "ou=users,dc=yunohost,dc=org" - test "$(ynh_read_var_in_file "$file" "ldap_base")" == "ou=users,dc=yunohost,dc=org" + ynh_write_var_in_file --file="$file" --key="ldap_base" --value="ou=users,dc=yunohost,dc=org" + test "$(ynh_read_var_in_file --file="$file" --key="ldap_base")" == "ou=users,dc=yunohost,dc=org" - ynh_write_var_in_file "$file" "TITLE" "YOLO" "YNH_ICI" - test "$(ynh_read_var_in_file "$file" "TITLE" "YNH_ICI")" == "YOLO" + ynh_write_var_in_file --file="$file" --key="TITLE" --value="YOLO" --after"YNH_ICI" + test "$(ynh_read_var_in_file --file="$file" --key="TITLE" --after"YNH_ICI")" == "YOLO" - ! ynh_write_var_in_file "$file" "NONEXISTENT" "foobar" - ! _read_py "$file" "NONEXISTENT" - test "$(ynh_read_var_in_file "$file" "NONEXISTENT")" == "YNH_NULL" + ! ynh_write_var_in_file --file="$file" --key="NONEXISTENT" --value="foobar" + ! _read_py "$file" "NONEXISTENT" + test "$(ynh_read_var_in_file --file="$file" --key="NONEXISTENT")" == "YNH_NULL" - ! ynh_write_var_in_file "$file" "ENABLE" "foobar" - ! _read_py "$file" "ENABLE" - test "$(ynh_read_var_in_file "$file" "ENABLE")" == "YNH_NULL" + ! ynh_write_var_in_file --file="$file" --key="ENABLE" -value="foobar" + ! _read_py "$file" "ENABLE" + test "$(ynh_read_var_in_file --file="$file" --key="ENABLE")" == "YNH_NULL" } @@ -172,34 +172,34 @@ url = https://yunohost.org ldap_base = ou=users,dc=yunohost,dc=org EOF - test "$(_read_ini "$file" "foo")" == "null" - test "$(ynh_read_var_in_file "$file" "foo")" == "null" + test "$(_read_ini "$file" "foo")" == "null" + test "$(ynh_read_var_in_file --file="$file" --key="foo")" == "null" - test "$(_read_ini "$file" "enabled")" == "False" - test "$(ynh_read_var_in_file "$file" "enabled")" == "False" + test "$(_read_ini "$file" "enabled")" == "False" + test "$(ynh_read_var_in_file --file="$file" --key="enabled")" == "False" - test "$(_read_ini "$file" "title")" == "Lorem Ipsum" - test "$(ynh_read_var_in_file "$file" "title")" == "Lorem Ipsum" + test "$(_read_ini "$file" "title")" == "Lorem Ipsum" + test "$(ynh_read_var_in_file --file="$file" --key="title")" == "Lorem Ipsum" - test "$(_read_ini "$file" "theme")" == "colib'ris" - test "$(ynh_read_var_in_file "$file" "theme")" == "colib'ris" + test "$(_read_ini "$file" "theme")" == "colib'ris" + test "$(ynh_read_var_in_file --file="$file" --key="theme")" == "colib'ris" - #test "$(_read_ini "$file" "email")" == "root@example.com" - test "$(ynh_read_var_in_file "$file" "email")" == "root@example.com" + #test "$(_read_ini "$file" "email")" == "root@example.com" + test "$(ynh_read_var_in_file --file="$file" --key="email")" == "root@example.com" - #test "$(_read_ini "$file" "port")" == "1234" - test "$(ynh_read_var_in_file "$file" "port")" == "1234" + #test "$(_read_ini "$file" "port")" == "1234" + test "$(ynh_read_var_in_file --file="$file" --key="port")" == "1234" - test "$(_read_ini "$file" "url")" == "https://yunohost.org" - test "$(ynh_read_var_in_file "$file" "url")" == "https://yunohost.org" + test "$(_read_ini "$file" "url")" == "https://yunohost.org" + test "$(ynh_read_var_in_file --file="$file" --key="url")" == "https://yunohost.org" - test "$(ynh_read_var_in_file "$file" "ldap_base")" == "ou=users,dc=yunohost,dc=org" + test "$(ynh_read_var_in_file --file="$file" --key="ldap_base")" == "ou=users,dc=yunohost,dc=org" - ! _read_ini "$file" "nonexistent" - test "$(ynh_read_var_in_file "$file" "nonexistent")" == "YNH_NULL" + ! _read_ini "$file" "nonexistent" + test "$(ynh_read_var_in_file --file="$file" --key="nonexistent")" == "YNH_NULL" - ! _read_ini "$file" "enable" - test "$(ynh_read_var_in_file "$file" "enable")" == "YNH_NULL" + ! _read_ini "$file" "enable" + test "$(ynh_read_var_in_file --file="$file" --key="enable")" == "YNH_NULL" } @@ -223,44 +223,44 @@ url = https://yunohost.org ldap_base = ou=users,dc=yunohost,dc=org EOF - ynh_write_var_in_file "$file" "foo" "bar" - test "$(_read_ini "$file" "foo")" == "bar" - test "$(ynh_read_var_in_file "$file" "foo")" == "bar" + ynh_write_var_in_file --file="$file" --key="foo" --value="bar" + test "$(_read_ini "$file" "foo")" == "bar" + test "$(ynh_read_var_in_file --file="$file" --key="foo")" == "bar" - ynh_write_var_in_file "$file" "enabled" "True" - test "$(_read_ini "$file" "enabled")" == "True" - test "$(ynh_read_var_in_file "$file" "enabled")" == "True" + ynh_write_var_in_file --file="$file" --key="enabled" --value="True" + test "$(_read_ini "$file" "enabled")" == "True" + test "$(ynh_read_var_in_file --file="$file" --key="enabled")" == "True" - ynh_write_var_in_file "$file" "title" "Foo Bar" - test "$(_read_ini "$file" "title")" == "Foo Bar" - test "$(ynh_read_var_in_file "$file" "title")" == "Foo Bar" + ynh_write_var_in_file --file="$file" --key="title" --value="Foo Bar" + test "$(_read_ini "$file" "title")" == "Foo Bar" + test "$(ynh_read_var_in_file --file="$file" --key="title")" == "Foo Bar" - ynh_write_var_in_file "$file" "theme" "super-awesome-theme" - test "$(_read_ini "$file" "theme")" == "super-awesome-theme" - test "$(ynh_read_var_in_file "$file" "theme")" == "super-awesome-theme" + ynh_write_var_in_file --file="$file" --key="theme" --value="super-awesome-theme" + test "$(_read_ini "$file" "theme")" == "super-awesome-theme" + test "$(ynh_read_var_in_file --file="$file" --key="theme")" == "super-awesome-theme" - ynh_write_var_in_file "$file" "email" "sam@domain.tld" - test "$(_read_ini "$file" "email")" == "sam@domain.tld # This is a comment without quotes" - test "$(ynh_read_var_in_file "$file" "email")" == "sam@domain.tld" + ynh_write_var_in_file --file="$file" --key="email" --value="sam@domain.tld" + test "$(_read_ini "$file" "email")" == "sam@domain.tld # This is a comment without quotes" + test "$(ynh_read_var_in_file --file="$file" --key="email")" == "sam@domain.tld" - ynh_write_var_in_file "$file" "port" "5678" - test "$(_read_ini "$file" "port")" == "5678 # This is a comment without quotes" - test "$(ynh_read_var_in_file "$file" "port")" == "5678" + ynh_write_var_in_file --file="$file" --key="port" --value="5678" + test "$(_read_ini "$file" "port")" == "5678 # This is a comment without quotes" + test "$(ynh_read_var_in_file --file="$file" --key="port")" == "5678" - ynh_write_var_in_file "$file" "url" "https://domain.tld/foobar" - test "$(_read_ini "$file" "url")" == "https://domain.tld/foobar" - test "$(ynh_read_var_in_file "$file" "url")" == "https://domain.tld/foobar" + ynh_write_var_in_file --file="$file" --key="url" --value="https://domain.tld/foobar" + test "$(_read_ini "$file" "url")" == "https://domain.tld/foobar" + test "$(ynh_read_var_in_file --file="$file" --key="url")" == "https://domain.tld/foobar" - ynh_write_var_in_file "$file" "ldap_base" "ou=users,dc=yunohost,dc=org" - test "$(ynh_read_var_in_file "$file" "ldap_base")" == "ou=users,dc=yunohost,dc=org" + ynh_write_var_in_file "$file" "ldap_base" "ou=users,dc=yunohost,dc=org" + test "$(ynh_read_var_in_file --file="$file" --key="ldap_base")" == "ou=users,dc=yunohost,dc=org" - ! ynh_write_var_in_file "$file" "nonexistent" "foobar" - ! _read_ini "$file" "nonexistent" - test "$(ynh_read_var_in_file "$file" "nonexistent")" == "YNH_NULL" + ! ynh_write_var_in_file --file="$file" --key="nonexistent" "foobar" + ! _read_ini "$file" "nonexistent" + test "$(ynh_read_var_in_file --file="$file" --key="nonexistent")" == "YNH_NULL" - ! ynh_write_var_in_file "$file" "enable" "foobar" - ! _read_ini "$file" "enable" - test "$(ynh_read_var_in_file "$file" "enable")" == "YNH_NULL" + ! ynh_write_var_in_file --file="$file" --key="enable" "foobar" + ! _read_ini "$file" "enable" + test "$(ynh_read_var_in_file --file="$file" --key="enable")" == "YNH_NULL" } @@ -300,34 +300,34 @@ dict: ldap_base: ou=users,dc=yunohost,dc=org EOF - test "$(_read_yaml "$file" "foo")" == "None" - test "$(ynh_read_var_in_file "$file" "foo")" == "" + test "$(_read_yaml "$file" "foo")" == "None" + test "$(ynh_read_var_in_file --file="$file" --key="foo")" == "" - test "$(_read_yaml "$file" "enabled")" == "False" - test "$(ynh_read_var_in_file "$file" "enabled")" == "false" + test "$(_read_yaml "$file" "enabled")" == "False" + test "$(ynh_read_var_in_file --file="$file" --key="enabled")" == "false" - test "$(_read_yaml "$file" "title")" == "Lorem Ipsum" - test "$(ynh_read_var_in_file "$file" "title")" == "Lorem Ipsum" + test "$(_read_yaml "$file" "title")" == "Lorem Ipsum" + test "$(ynh_read_var_in_file --file="$file" --key="title")" == "Lorem Ipsum" - test "$(_read_yaml "$file" "theme")" == "colib'ris" - test "$(ynh_read_var_in_file "$file" "theme")" == "colib'ris" + test "$(_read_yaml "$file" "theme")" == "colib'ris" + test "$(ynh_read_var_in_file --file="$file" --key="theme")" == "colib'ris" - test "$(_read_yaml "$file" "email")" == "root@example.com" - test "$(ynh_read_var_in_file "$file" "email")" == "root@example.com" + test "$(_read_yaml "$file" "email")" == "root@example.com" + test "$(ynh_read_var_in_file --file="$file" --key="email")" == "root@example.com" - test "$(_read_yaml "$file" "port")" == "1234" - test "$(ynh_read_var_in_file "$file" "port")" == "1234" + test "$(_read_yaml "$file" "port")" == "1234" + test "$(ynh_read_var_in_file --file="$file" --key="port")" == "1234" - test "$(_read_yaml "$file" "url")" == "https://yunohost.org" - test "$(ynh_read_var_in_file "$file" "url")" == "https://yunohost.org" + test "$(_read_yaml "$file" "url")" == "https://yunohost.org" + test "$(ynh_read_var_in_file --file="$file" --key="url")" == "https://yunohost.org" - test "$(ynh_read_var_in_file "$file" "ldap_base")" == "ou=users,dc=yunohost,dc=org" + test "$(ynh_read_var_in_file --file="$file" --key="ldap_base")" == "ou=users,dc=yunohost,dc=org" - ! _read_yaml "$file" "nonexistent" - test "$(ynh_read_var_in_file "$file" "nonexistent")" == "YNH_NULL" + ! _read_yaml "$file" "nonexistent" + test "$(ynh_read_var_in_file --file="$file" --key="nonexistent")" == "YNH_NULL" - ! _read_yaml "$file" "enable" - test "$(ynh_read_var_in_file "$file" "enable")" == "YNH_NULL" + ! _read_yaml "$file" "enable" + test "$(ynh_read_var_in_file --file="$file" --key="enable")" == "YNH_NULL" } @@ -349,44 +349,44 @@ dict: ldap_base: ou=users,dc=yunohost,dc=org EOF - ynh_write_var_in_file "$file" "foo" "bar" + ynh_write_var_in_file --file="$file" --key="foo" --value="bar" # cat $dummy_dir/dummy.yml # to debug - ! test "$(_read_yaml "$file" "foo")" == "bar" # writing broke the yaml syntax... "foo:bar" (no space aftr :) - test "$(ynh_read_var_in_file "$file" "foo")" == "bar" + ! test "$(_read_yaml "$file" "foo")" == "bar" # writing broke the yaml syntax... "foo:bar" (no space aftr :) + test "$(ynh_read_var_in_file --file="$file" --key="foo")" == "bar" - ynh_write_var_in_file "$file" "enabled" "true" - test "$(_read_yaml "$file" "enabled")" == "True" - test "$(ynh_read_var_in_file "$file" "enabled")" == "true" + ynh_write_var_in_file --file="$file" --key="enabled" --value="true" + test "$(_read_yaml "$file" "enabled")" == "True" + test "$(ynh_read_var_in_file --file="$file" --key="enabled")" == "true" - ynh_write_var_in_file "$file" "title" "Foo Bar" - test "$(_read_yaml "$file" "title")" == "Foo Bar" - test "$(ynh_read_var_in_file "$file" "title")" == "Foo Bar" + ynh_write_var_in_file --file="$file" --key="title" --value="Foo Bar" + test "$(_read_yaml "$file" "title")" == "Foo Bar" + test "$(ynh_read_var_in_file --file="$file" --key="title")" == "Foo Bar" - ynh_write_var_in_file "$file" "theme" "super-awesome-theme" - test "$(_read_yaml "$file" "theme")" == "super-awesome-theme" - test "$(ynh_read_var_in_file "$file" "theme")" == "super-awesome-theme" + ynh_write_var_in_file --file="$file" --key="theme" --value="super-awesome-theme" + test "$(_read_yaml "$file" "theme")" == "super-awesome-theme" + test "$(ynh_read_var_in_file --file="$file" --key="theme")" == "super-awesome-theme" - ynh_write_var_in_file "$file" "email" "sam@domain.tld" - test "$(_read_yaml "$file" "email")" == "sam@domain.tld" - test "$(ynh_read_var_in_file "$file" "email")" == "sam@domain.tld" + ynh_write_var_in_file --file="$file" --key="email" --value="sam@domain.tld" + test "$(_read_yaml "$file" "email")" == "sam@domain.tld" + test "$(ynh_read_var_in_file --file="$file" --key="email")" == "sam@domain.tld" - ynh_write_var_in_file "$file" "port" "5678" - test "$(_read_yaml "$file" "port")" == "5678" - test "$(ynh_read_var_in_file "$file" "port")" == "5678" + ynh_write_var_in_file --file="$file" --key="port" --value="5678" + test "$(_read_yaml "$file" "port")" == "5678" + test "$(ynh_read_var_in_file --file="$file" --key="port")" == "5678" - ynh_write_var_in_file "$file" "url" "https://domain.tld/foobar" - test "$(_read_yaml "$file" "url")" == "https://domain.tld/foobar" - test "$(ynh_read_var_in_file "$file" "url")" == "https://domain.tld/foobar" + ynh_write_var_in_file --file="$file" --key="url" --value="https://domain.tld/foobar" + test "$(_read_yaml "$file" "url")" == "https://domain.tld/foobar" + test "$(ynh_read_var_in_file --file="$file" --key="url")" == "https://domain.tld/foobar" - ynh_write_var_in_file "$file" "ldap_base" "ou=foobar,dc=domain,dc=tld" - test "$(ynh_read_var_in_file "$file" "ldap_base")" == "ou=foobar,dc=domain,dc=tld" + ynh_write_var_in_file --file="$file" --key="ldap_base" --value="ou=foobar,dc=domain,dc=tld" + test "$(ynh_read_var_in_file --file="$file" --key="ldap_base")" == "ou=foobar,dc=domain,dc=tld" - ! ynh_write_var_in_file "$file" "nonexistent" "foobar" - test "$(ynh_read_var_in_file "$file" "nonexistent")" == "YNH_NULL" + ! ynh_write_var_in_file --file="$file" --key="nonexistent" --value="foobar" + test "$(ynh_read_var_in_file --file="$file" --key="nonexistent")" == "YNH_NULL" - ! ynh_write_var_in_file "$file" "enable" "foobar" - test "$(ynh_read_var_in_file "$file" "enable")" == "YNH_NULL" - test "$(ynh_read_var_in_file "$file" "enabled")" == "true" + ! ynh_write_var_in_file --file="$file" --key="enable" --value="foobar" + test "$(ynh_read_var_in_file --file="$file" --key="enable")" == "YNH_NULL" + test "$(ynh_read_var_in_file --file="$file" --key="enabled")" == "true" } ######################### @@ -427,34 +427,34 @@ ynhtest_config_read_json() { EOF - test "$(_read_json "$file" "foo")" == "None" - test "$(ynh_read_var_in_file "$file" "foo")" == "null" + test "$(_read_json "$file" "foo")" == "None" + test "$(ynh_read_var_in_file --file="$file" --key="foo")" == "null" - test "$(_read_json "$file" "enabled")" == "False" - test "$(ynh_read_var_in_file "$file" "enabled")" == "false" + test "$(_read_json "$file" "enabled")" == "False" + test "$(ynh_read_var_in_file --file="$file" --key="enabled")" == "false" - test "$(_read_json "$file" "title")" == "Lorem Ipsum" - test "$(ynh_read_var_in_file "$file" "title")" == "Lorem Ipsum" + test "$(_read_json "$file" "title")" == "Lorem Ipsum" + test "$(ynh_read_var_in_file --file="$file" --key="title")" == "Lorem Ipsum" - test "$(_read_json "$file" "theme")" == "colib'ris" - test "$(ynh_read_var_in_file "$file" "theme")" == "colib'ris" + test "$(_read_json "$file" "theme")" == "colib'ris" + test "$(ynh_read_var_in_file --file="$file" --key="theme")" == "colib'ris" - test "$(_read_json "$file" "email")" == "root@example.com" - test "$(ynh_read_var_in_file "$file" "email")" == "root@example.com" + test "$(_read_json "$file" "email")" == "root@example.com" + test "$(ynh_read_var_in_file --file="$file" --key="email")" == "root@example.com" - test "$(_read_json "$file" "port")" == "1234" - test "$(ynh_read_var_in_file "$file" "port")" == "1234" + test "$(_read_json "$file" "port")" == "1234" + test "$(ynh_read_var_in_file --file="$file" --key="port")" == "1234" - test "$(_read_json "$file" "url")" == "https://yunohost.org" - test "$(ynh_read_var_in_file "$file" "url")" == "https://yunohost.org" + test "$(_read_json "$file" "url")" == "https://yunohost.org" + test "$(ynh_read_var_in_file --file="$file" --key="url")" == "https://yunohost.org" - test "$(ynh_read_var_in_file "$file" "ldap_base")" == "ou=users,dc=yunohost,dc=org" + test "$(ynh_read_var_in_file --file="$file" --key="ldap_base")" == "ou=users,dc=yunohost,dc=org" - ! _read_json "$file" "nonexistent" - test "$(ynh_read_var_in_file "$file" "nonexistent")" == "YNH_NULL" + ! _read_json "$file" "nonexistent" + test "$(ynh_read_var_in_file --file="$file" --key="nonexistent")" == "YNH_NULL" - ! _read_json "$file" "enable" - test "$(ynh_read_var_in_file "$file" "enable")" == "YNH_NULL" + ! _read_json "$file" "enable" + test "$(ynh_read_var_in_file --file="$file" --key="enable")" == "YNH_NULL" } @@ -477,48 +477,48 @@ ynhtest_config_write_json() { } EOF - ynh_write_var_in_file "$file" "foo" "bar" + ynh_write_var_in_file --file="$file" --key="foo" --value="bar" cat $file - test "$(_read_json "$file" "foo")" == "bar" - test "$(ynh_read_var_in_file "$file" "foo")" == "bar" + test "$(_read_json "$file" "foo")" == "bar" + test "$(ynh_read_var_in_file --file="$file" --key="foo")" == "bar" - ynh_write_var_in_file "$file" "enabled" "true" + ynh_write_var_in_file --file="$file" --key="enabled" --value="true" cat $file - test "$(_read_json "$file" "enabled")" == "true" - test "$(ynh_read_var_in_file "$file" "enabled")" == "true" + test "$(_read_json "$file" "enabled")" == "true" + test "$(ynh_read_var_in_file --file="$file" --key="enabled")" == "true" - ynh_write_var_in_file "$file" "title" "Foo Bar" + ynh_write_var_in_file --file="$file" --key="title" --value="Foo Bar" cat $file - test "$(_read_json "$file" "title")" == "Foo Bar" - test "$(ynh_read_var_in_file "$file" "title")" == "Foo Bar" + test "$(_read_json "$file" "title")" == "Foo Bar" + test "$(ynh_read_var_in_file --file="$file" --key="title")" == "Foo Bar" - ynh_write_var_in_file "$file" "theme" "super-awesome-theme" + ynh_write_var_in_file --file="$file" --key="theme" --value="super-awesome-theme" cat $file - test "$(_read_json "$file" "theme")" == "super-awesome-theme" - test "$(ynh_read_var_in_file "$file" "theme")" == "super-awesome-theme" + test "$(_read_json "$file" "theme")" == "super-awesome-theme" + test "$(ynh_read_var_in_file --file="$file" --key="theme")" == "super-awesome-theme" - ynh_write_var_in_file "$file" "email" "sam@domain.tld" + ynh_write_var_in_file --file="$file" --key="email" --value="sam@domain.tld" cat $file - test "$(_read_json "$file" "email")" == "sam@domain.tld" - test "$(ynh_read_var_in_file "$file" "email")" == "sam@domain.tld" + test "$(_read_json "$file" "email")" == "sam@domain.tld" + test "$(ynh_read_var_in_file --file="$file" --key="email")" == "sam@domain.tld" - ynh_write_var_in_file "$file" "port" "5678" - test "$(_read_json "$file" "port")" == "5678" - test "$(ynh_read_var_in_file "$file" "port")" == "5678" + ynh_write_var_in_file --file="$file" --key="port" --value="5678" + test "$(_read_json "$file" "port")" == "5678" + test "$(ynh_read_var_in_file --file="$file" --key="port")" == "5678" - ynh_write_var_in_file "$file" "url" "https://domain.tld/foobar" - test "$(_read_json "$file" "url")" == "https://domain.tld/foobar" - test "$(ynh_read_var_in_file "$file" "url")" == "https://domain.tld/foobar" + ynh_write_var_in_file --file="$file" --key="url" --value="https://domain.tld/foobar" + test "$(_read_json "$file" "url")" == "https://domain.tld/foobar" + test "$(ynh_read_var_in_file --file="$file" --key="url")" == "https://domain.tld/foobar" - ynh_write_var_in_file "$file" "ldap_base" "ou=foobar,dc=domain,dc=tld" - test "$(ynh_read_var_in_file "$file" "ldap_base")" == "ou=foobar,dc=domain,dc=tld" + ynh_write_var_in_file --file="$file" --key="ldap_base" --value="ou=foobar,dc=domain,dc=tld" + test "$(ynh_read_var_in_file --file="$file" --key="ldap_base")" == "ou=foobar,dc=domain,dc=tld" - ! ynh_write_var_in_file "$file" "nonexistent" "foobar" - test "$(ynh_read_var_in_file "$file" "nonexistent")" == "YNH_NULL" + ! ynh_write_var_in_file --file="$file" --key="nonexistent" --value="foobar" + test "$(ynh_read_var_in_file --file="$file" --key="nonexistent")" == "YNH_NULL" - ! ynh_write_var_in_file "$file" "enable" "foobar" - test "$(ynh_read_var_in_file "$file" "enable")" == "YNH_NULL" - test "$(ynh_read_var_in_file "$file" "enabled")" == "true" + ! ynh_write_var_in_file --file="$file" --key="enable" --value="foobar" + test "$(ynh_read_var_in_file --file="$file" --key="enable")" == "YNH_NULL" + test "$(ynh_read_var_in_file --file="$file" --key="enabled")" == "true" } ####################### @@ -563,38 +563,38 @@ ynhtest_config_read_php() { ?> EOF - test "$(_read_php "$file" "foo")" == "NULL" - test "$(ynh_read_var_in_file "$file" "foo")" == "NULL" + test "$(_read_php "$file" "foo")" == "NULL" + test "$(ynh_read_var_in_file --file="$file" --key="foo")" == "NULL" - test "$(_read_php "$file" "enabled")" == "false" - test "$(ynh_read_var_in_file "$file" "enabled")" == "false" + test "$(_read_php "$file" "enabled")" == "false" + test "$(ynh_read_var_in_file --file="$file" --key="enabled")" == "false" - test "$(_read_php "$file" "title")" == "Lorem Ipsum" - test "$(ynh_read_var_in_file "$file" "title")" == "Lorem Ipsum" + test "$(_read_php "$file" "title")" == "Lorem Ipsum" + test "$(ynh_read_var_in_file --file="$file" --key="title")" == "Lorem Ipsum" - test "$(_read_php "$file" "theme")" == "colib\\'ris" - test "$(ynh_read_var_in_file "$file" "theme")" == "colib'ris" + test "$(_read_php "$file" "theme")" == "colib\\'ris" + test "$(ynh_read_var_in_file --file="$file" --key="theme")" == "colib'ris" - test "$(_read_php "$file" "email")" == "root@example.com" - test "$(ynh_read_var_in_file "$file" "email")" == "root@example.com" + test "$(_read_php "$file" "email")" == "root@example.com" + test "$(ynh_read_var_in_file --file="$file" --key="email")" == "root@example.com" - test "$(_read_php "$file" "port")" == "1234" - test "$(ynh_read_var_in_file "$file" "port")" == "1234" + test "$(_read_php "$file" "port")" == "1234" + test "$(ynh_read_var_in_file --file="$file" --key="port")" == "1234" - test "$(_read_php "$file" "url")" == "https://yunohost.org" - test "$(ynh_read_var_in_file "$file" "url")" == "https://yunohost.org" + test "$(_read_php "$file" "url")" == "https://yunohost.org" + test "$(ynh_read_var_in_file --file="$file" --key="url")" == "https://yunohost.org" - test "$(ynh_read_var_in_file "$file" "ldap_base")" == "ou=users,dc=yunohost,dc=org" + test "$(ynh_read_var_in_file --file="$file" --key="ldap_base")" == "ou=users,dc=yunohost,dc=org" - test "$(ynh_read_var_in_file "$file" "user")" == "camille" + test "$(ynh_read_var_in_file --file="$file" --key="user")" == "camille" - test "$(ynh_read_var_in_file "$file" "DB_HOST")" == "localhost" + test "$(ynh_read_var_in_file --file="$file" --key="DB_HOST")" == "localhost" - ! _read_php "$file" "nonexistent" - test "$(ynh_read_var_in_file "$file" "nonexistent")" == "YNH_NULL" + ! _read_php "$file" "nonexistent" + test "$(ynh_read_var_in_file --file="$file" --key="nonexistent")" == "YNH_NULL" - ! _read_php "$file" "enable" - test "$(ynh_read_var_in_file "$file" "enable")" == "YNH_NULL" + ! _read_php "$file" "enable" + test "$(ynh_read_var_in_file --file="$file" --key="enable")" == "YNH_NULL" } @@ -619,44 +619,44 @@ ynhtest_config_write_php() { ?> EOF - ynh_write_var_in_file "$file" "foo" "bar" - test "$(_read_php "$file" "foo")" == "bar" - test "$(ynh_read_var_in_file "$file" "foo")" == "bar" + ynh_write_var_in_file --file="$file" --key="foo" --value="bar" + test "$(_read_php "$file" "foo")" == "bar" + test "$(ynh_read_var_in_file --file="$file" --key="foo")" == "bar" - ynh_write_var_in_file "$file" "enabled" "true" - test "$(_read_php "$file" "enabled")" == "true" - test "$(ynh_read_var_in_file "$file" "enabled")" == "true" + ynh_write_var_in_file --file="$file" --key="enabled" --value="true" + test "$(_read_php "$file" "enabled")" == "true" + test "$(ynh_read_var_in_file --file="$file" --key="enabled")" == "true" - ynh_write_var_in_file "$file" "title" "Foo Bar" + ynh_write_var_in_file --file="$file" --key="title" --value="Foo Bar" cat $file - test "$(_read_php "$file" "title")" == "Foo Bar" - test "$(ynh_read_var_in_file "$file" "title")" == "Foo Bar" + test "$(_read_php "$file" "title")" == "Foo Bar" + test "$(ynh_read_var_in_file --file="$file" --key="title")" == "Foo Bar" - ynh_write_var_in_file "$file" "theme" "super-awesome-theme" + ynh_write_var_in_file --file="$file" --key="theme" --value="super-awesome-theme" cat $file - test "$(_read_php "$file" "theme")" == "super-awesome-theme" - test "$(ynh_read_var_in_file "$file" "theme")" == "super-awesome-theme" + test "$(_read_php "$file" "theme")" == "super-awesome-theme" + test "$(ynh_read_var_in_file --file="$file" --key="theme")" == "super-awesome-theme" - ynh_write_var_in_file "$file" "email" "sam@domain.tld" + ynh_write_var_in_file --file="$file" --key="email" --value="sam@domain.tld" cat $file - test "$(_read_php "$file" "email")" == "sam@domain.tld" - test "$(ynh_read_var_in_file "$file" "email")" == "sam@domain.tld" + test "$(_read_php "$file" "email")" == "sam@domain.tld" + test "$(ynh_read_var_in_file --file="$file" --key="email")" == "sam@domain.tld" - ynh_write_var_in_file "$file" "port" "5678" - test "$(_read_php "$file" "port")" == "5678" - test "$(ynh_read_var_in_file "$file" "port")" == "5678" + ynh_write_var_in_file --file="$file" --key="port" --value="5678" + test "$(_read_php "$file" "port")" == "5678" + test "$(ynh_read_var_in_file --file="$file" --key="port")" == "5678" - ynh_write_var_in_file "$file" "url" "https://domain.tld/foobar" - test "$(_read_php "$file" "url")" == "https://domain.tld/foobar" - test "$(ynh_read_var_in_file "$file" "url")" == "https://domain.tld/foobar" + ynh_write_var_in_file --file="$file" --key="url" --value="https://domain.tld/foobar" + test "$(_read_php "$file" "url")" == "https://domain.tld/foobar" + test "$(ynh_read_var_in_file --file="$file" --key="url")" == "https://domain.tld/foobar" - ynh_write_var_in_file "$file" "ldap_base" "ou=foobar,dc=domain,dc=tld" - test "$(ynh_read_var_in_file "$file" "ldap_base")" == "ou=foobar,dc=domain,dc=tld" + ynh_write_var_in_file --file="$file" --key="ldap_base" --value="ou=foobar,dc=domain,dc=tld" + test "$(ynh_read_var_in_file --file="$file" --key="ldap_base")" == "ou=foobar,dc=domain,dc=tld" - ! ynh_write_var_in_file "$file" "nonexistent" "foobar" - test "$(ynh_read_var_in_file "$file" "nonexistent")" == "YNH_NULL" + ! ynh_write_var_in_file --file="$file" --key="nonexistent" --value="foobar" + test "$(ynh_read_var_in_file --file="$file" --key="nonexistent")" == "YNH_NULL" - ! ynh_write_var_in_file "$file" "enable" "foobar" - test "$(ynh_read_var_in_file "$file" "enable")" == "YNH_NULL" - test "$(ynh_read_var_in_file "$file" "enabled")" == "true" + ! ynh_write_var_in_file --file="$file" --key="enable" --value="foobar" + test "$(ynh_read_var_in_file --file="$file" --key="enable")" == "YNH_NULL" + test "$(ynh_read_var_in_file --file="$file" --key="enabled")" == "true" } diff --git a/tests/test_helpers.v2.1.d/ynhtest_logging.sh b/tests/test_helpers.v2.1.d/ynhtest_logging.sh index 1b2452bc4..2ad9607ae 100644 --- a/tests/test_helpers.v2.1.d/ynhtest_logging.sh +++ b/tests/test_helpers.v2.1.d/ynhtest_logging.sh @@ -45,48 +45,7 @@ ynhtest_exec_warn_less() { test -e "$FOOANDBAR" rm "$FOOANDBAR" - ########################### - # Legacy stuff using eval # - ########################### - test ! -e $FOO - ynh_hide_warnings "touch $FOO" - test -e $FOO - rm $FOO - - test ! -e $FOO1QUOTEBAR - ynh_hide_warnings "touch \"$FOO1QUOTEBAR\"" - # (this works but expliciy *double* quotes have to be provided) - test -e $FOO1QUOTEBAR - rm $FOO1QUOTEBAR - - #test ! -e $FOO2QUOTEBAR - #ynh_hide_warnings "touch \'$FOO2QUOTEBAR\'" - ## (this doesn't work with simple or double quotes) - #test -e $FOO2QUOTEBAR - #rm $FOO2QUOTEBAR - - test ! -e $BAR - ynh_hide_warnings 'touch $BAR' - # That one works because $BAR is only interpreted during eval - test -e $BAR - rm $BAR - - #test ! -e $BAR - #ynh_hide_warnings "touch $BAR" - # That one doesn't work because $bar gets interpreted as empty var by eval... - #test -e $BAR - #rm $BAR - - test ! -e "$FOOBAR" - ynh_hide_warnings "touch \"$FOOBAR\"" - # (works but requires explicit double quotes otherwise eval would interpret 'foo bar' as two separate args..) - test -e "$FOOBAR" - rm "$FOOBAR" - - test ! -e "$FOOANDBAR" - ynh_hide_warnings "touch \"$FOOANDBAR\"" - # (works but requires explicit double quotes otherwise eval would interpret '&' as a "run command in background" and also bar is not a valid command) - test -e "$FOOANDBAR" - rm "$FOOANDBAR" + ! ynh_hide_warnings "touch $FOO" + ! test -e $FOO } diff --git a/tests/test_helpers.v2.1.d/ynhtest_settings.sh b/tests/test_helpers.v2.1.d/ynhtest_settings.sh index be765be82..308b45f6b 100644 --- a/tests/test_helpers.v2.1.d/ynhtest_settings.sh +++ b/tests/test_helpers.v2.1.d/ynhtest_settings.sh @@ -7,23 +7,18 @@ ynhtest_settings() { test -z "$(ynh_app_setting_get --key="foo")" test -z "$(ynh_app_setting_get --key="bar")" - test -z "$(ynh_app_setting_get --app="$app" --key="baz")" ynh_app_setting_set --key="foo" --value="foovalue" ynh_app_setting_set --app="$app" --key="bar" --value="barvalue" - ynh_app_setting_set "$app" baz bazvalue test "$(ynh_app_setting_get --key="foo")" == "foovalue" test "$(ynh_app_setting_get --key="bar")" == "barvalue" - test "$(ynh_app_setting_get --app="$app" --key="baz")" == "bazvalue" ynh_app_setting_delete --key="foo" ynh_app_setting_delete --app="$app" --key="bar" - ynh_app_setting_delete "$app" baz test -z "$(ynh_app_setting_get --key="foo")" test -z "$(ynh_app_setting_get --key="bar")" - test -z "$(ynh_app_setting_get --app="$app" --key="baz")" rm -rf "/etc/yunohost/apps/$app" } diff --git a/tests/test_helpers.v2.1.d/ynhtest_setup_source.sh b/tests/test_helpers.v2.1.d/ynhtest_setup_source.sh index 323b74796..9953df406 100644 --- a/tests/test_helpers.v2.1.d/ynhtest_setup_source.sh +++ b/tests/test_helpers.v2.1.d/ynhtest_setup_source.sh @@ -16,7 +16,7 @@ _make_dummy_manifest() { cat << EOF packaging_format = 2 -id = "helloworld" +id = "$app" version = "0.1~ynh2" [resources] @@ -33,6 +33,7 @@ EOF ynhtest_setup_source_nominal() { install_dir="$(mktemp -d -p $VAR_WWW)" _make_dummy_manifest > ../manifest.toml + cat ../manifest.toml # debug ynh_setup_source --dest_dir="$install_dir" --source_id="dummy" diff --git a/tests/test_helpers.v2.1.d/ynhtest_templating.sh b/tests/test_helpers.v2.1.d/ynhtest_templating.sh index c8015093a..703c915d2 100644 --- a/tests/test_helpers.v2.1.d/ynhtest_templating.sh +++ b/tests/test_helpers.v2.1.d/ynhtest_templating.sh @@ -10,6 +10,7 @@ foo=__FOO__ EOF foo="bar" + install_dir="$VAR_WWW" ynh_config_add --template="$template" --destination="$VAR_WWW/config.txt" From 4e3f30ef8243243105721c57ed1514fb9f0d3c1d Mon Sep 17 00:00:00 2001 From: OniriCorpe Date: Mon, 1 Jul 2024 21:51:43 +0200 Subject: [PATCH 22/28] better help message for 'diagnosis unignore' --- share/actionsmap.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/share/actionsmap.yml b/share/actionsmap.yml index eb328dbc6..9d5c76b01 100755 --- a/share/actionsmap.yml +++ b/share/actionsmap.yml @@ -2079,6 +2079,6 @@ diagnosis: api: PUT /diagnosis/unignore arguments: --filter: - help: Remove a filter (it should be an existing filter as listed with --list) + help: Remove a filter (it should be an existing filter as listed with "ignore --list") nargs: "*" metavar: CRITERIA From 2640dd31718a6af802d4e26351d5cce20cc16026 Mon Sep 17 00:00:00 2001 From: Alexandre Aubin Date: Mon, 1 Jul 2024 21:59:45 +0200 Subject: [PATCH 23/28] =?UTF-8?q?friskies=C2=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/test_helpers.v2.1.d/ynhtest_config.sh | 10 +++++----- tests/test_helpers.v2.1.d/ynhtest_setup_source.sh | 2 +- tests/test_helpers.v2.1.d/ynhtest_templating.sh | 7 ++++--- 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/tests/test_helpers.v2.1.d/ynhtest_config.sh b/tests/test_helpers.v2.1.d/ynhtest_config.sh index 51fd44cfe..ac7c2f853 100644 --- a/tests/test_helpers.v2.1.d/ynhtest_config.sh +++ b/tests/test_helpers.v2.1.d/ynhtest_config.sh @@ -63,7 +63,7 @@ EOF test "$(ynh_read_var_in_file --file="$file" --key="user")" == "camille" - test "$(ynh_read_var_in_file --file="$file" --key="TITLE" --after"YNH_ICI")" == "Hello world" + test "$(ynh_read_var_in_file --file="$file" --key="TITLE" --after="YNH_ICI")" == "Hello world" ! _read_py "$file" "NONEXISTENT" test "$(ynh_read_var_in_file --file="$file" --key="NONEXISTENT")" == "YNH_NULL" @@ -123,8 +123,8 @@ EOF ynh_write_var_in_file --file="$file" --key="ldap_base" --value="ou=users,dc=yunohost,dc=org" test "$(ynh_read_var_in_file --file="$file" --key="ldap_base")" == "ou=users,dc=yunohost,dc=org" - ynh_write_var_in_file --file="$file" --key="TITLE" --value="YOLO" --after"YNH_ICI" - test "$(ynh_read_var_in_file --file="$file" --key="TITLE" --after"YNH_ICI")" == "YOLO" + ynh_write_var_in_file --file="$file" --key="TITLE" --value="YOLO" --after="YNH_ICI" + test "$(ynh_read_var_in_file --file="$file" --key="TITLE" --after="YNH_ICI")" == "YOLO" ! ynh_write_var_in_file --file="$file" --key="NONEXISTENT" --value="foobar" ! _read_py "$file" "NONEXISTENT" @@ -251,8 +251,8 @@ EOF test "$(_read_ini "$file" "url")" == "https://domain.tld/foobar" test "$(ynh_read_var_in_file --file="$file" --key="url")" == "https://domain.tld/foobar" - ynh_write_var_in_file "$file" "ldap_base" "ou=users,dc=yunohost,dc=org" - test "$(ynh_read_var_in_file --file="$file" --key="ldap_base")" == "ou=users,dc=yunohost,dc=org" + ynh_write_var_in_file --file="$file" --key="ldap_base" --value="ou=users,dc=yunohost,dc=org" + test "$(ynh_read_var_in_file --file="$file" --key="ldap_base")" == "ou=users,dc=yunohost,dc=org" ! ynh_write_var_in_file --file="$file" --key="nonexistent" "foobar" ! _read_ini "$file" "nonexistent" diff --git a/tests/test_helpers.v2.1.d/ynhtest_setup_source.sh b/tests/test_helpers.v2.1.d/ynhtest_setup_source.sh index 9953df406..0b9d2e665 100644 --- a/tests/test_helpers.v2.1.d/ynhtest_setup_source.sh +++ b/tests/test_helpers.v2.1.d/ynhtest_setup_source.sh @@ -33,7 +33,6 @@ EOF ynhtest_setup_source_nominal() { install_dir="$(mktemp -d -p $VAR_WWW)" _make_dummy_manifest > ../manifest.toml - cat ../manifest.toml # debug ynh_setup_source --dest_dir="$install_dir" --source_id="dummy" @@ -48,6 +47,7 @@ ynhtest_setup_source_no_group_in_manifest() { install_dir="$(mktemp -d -p $VAR_WWW)" _make_dummy_manifest > ../manifest.toml sed '/www-data/d' -i ../manifest.toml + cat ../manifest.toml # debug ynh_setup_source --dest_dir="$install_dir" --source_id="dummy" diff --git a/tests/test_helpers.v2.1.d/ynhtest_templating.sh b/tests/test_helpers.v2.1.d/ynhtest_templating.sh index 703c915d2..b8cea0770 100644 --- a/tests/test_helpers.v2.1.d/ynhtest_templating.sh +++ b/tests/test_helpers.v2.1.d/ynhtest_templating.sh @@ -15,7 +15,7 @@ EOF ynh_config_add --template="$template" --destination="$VAR_WWW/config.txt" test "$(cat $VAR_WWW/config.txt)" == "$(echo -ne 'app=ynhtest\nfoo=bar')" - test "$(ls -l $VAR_WWW/config.txt | cut -d' ' -f1-4)" == "-rw-r----- 1 ynhtest ynhtest" + test "$(ls -l $VAR_WWW/config.txt | cut -d' ' -f1-4)" == "-rw------- 1 ynhtest ynhtest" } ynhtest_simple_template_system_config() { @@ -35,7 +35,7 @@ EOF ynh_config_add --template="$template" --destination="/etc/cron.d/ynhtest_config" - test "$(cat $VAR_WWW/config.txt)" == "$(echo -ne 'app=ynhtest\nfoo=bar')" + test "$(cat /etc/cron.d/ynhtest_config)" == "$(echo -ne 'app=ynhtest\nfoo=bar')" test "$(ls -l /etc/cron.d/ynhtest_config | cut -d' ' -f1-4)" == "-r-------- 1 root root" rm -f /etc/cron.d/ynhtest_config @@ -53,11 +53,12 @@ app={{ app }} EOF foo="bar" + install_dir="$VAR_WWW" ynh_config_add --template="$template" --destination="$VAR_WWW/config.txt" --jinja test "$(cat $VAR_WWW/config.txt)" == "$(echo -ne 'app=ynhtest\nfoo=true')" - test "$(ls -l $VAR_WWW/config.txt | cut -d' ' -f1-4)" == "-rw-r----- 1 ynhtest ynhtest" + test "$(ls -l $VAR_WWW/config.txt | cut -d' ' -f1-4)" == "-rw------- 1 ynhtest ynhtest" } From 131760e30c8221ded5187af8ec440eeaaa503791 Mon Sep 17 00:00:00 2001 From: OniriCorpe Date: Mon, 1 Jul 2024 22:04:28 +0200 Subject: [PATCH 24/28] trying to fix #1886 --- src/service.py | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/src/service.py b/src/service.py index db96a099a..6bc325f49 100644 --- a/src/service.py +++ b/src/service.py @@ -26,7 +26,7 @@ from glob import glob from datetime import datetime from moulinette import m18n -from yunohost.diagnosis import diagnosis_ignore, diagnosis_unignore +from yunohost.diagnosis import _diagnosis_ignore from yunohost.utils.error import YunohostError, YunohostValidationError from moulinette.utils.process import check_output from moulinette.utils.log import getActionLogger @@ -297,9 +297,7 @@ def service_enable(names): names = [names] for name in names: if _run_service_command("enable", name): - services = _get_services() - if name in services: - diagnosis_unignore({"services": [{"service": name}]}) + _diagnosis_ignore(remove_filter="services", list=f"service={name}") logger.success(m18n.n("service_enabled", service=name)) else: raise YunohostError( @@ -319,9 +317,7 @@ def service_disable(names): names = [names] for name in names: if _run_service_command("disable", name): - services = _get_services() - if name in services: - diagnosis_ignore({"services": [{"service": name}]}) + _diagnosis_ignore(add_filter="services", list=f"service={name}") logger.success(m18n.n("service_disabled", service=name)) else: raise YunohostError( From 0f85ddbcffff2b2bccc081d26d061b4601859720 Mon Sep 17 00:00:00 2001 From: Alexandre Aubin Date: Mon, 1 Jul 2024 22:22:46 +0200 Subject: [PATCH 25/28] =?UTF-8?q?friskies=C2=B3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/test_helpers.v2.1.d/ynhtest_config.sh | 2 +- tests/test_helpers.v2.1.d/ynhtest_setup_source.sh | 14 ++++++++------ 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/tests/test_helpers.v2.1.d/ynhtest_config.sh b/tests/test_helpers.v2.1.d/ynhtest_config.sh index ac7c2f853..5448d41c3 100644 --- a/tests/test_helpers.v2.1.d/ynhtest_config.sh +++ b/tests/test_helpers.v2.1.d/ynhtest_config.sh @@ -130,7 +130,7 @@ EOF ! _read_py "$file" "NONEXISTENT" test "$(ynh_read_var_in_file --file="$file" --key="NONEXISTENT")" == "YNH_NULL" - ! ynh_write_var_in_file --file="$file" --key="ENABLE" -value="foobar" + ! ynh_write_var_in_file --file="$file" --key="ENABLE" --value="foobar" ! _read_py "$file" "ENABLE" test "$(ynh_read_var_in_file --file="$file" --key="ENABLE")" == "YNH_NULL" diff --git a/tests/test_helpers.v2.1.d/ynhtest_setup_source.sh b/tests/test_helpers.v2.1.d/ynhtest_setup_source.sh index 0b9d2e665..a8e0a5947 100644 --- a/tests/test_helpers.v2.1.d/ynhtest_setup_source.sh +++ b/tests/test_helpers.v2.1.d/ynhtest_setup_source.sh @@ -1,17 +1,17 @@ _make_dummy_manifest() { if [ ! -e $HTTPSERVER_DIR/dummy.tar.gz ] then - pushd "$HTTPSERVER_DIR" + pushd "$HTTPSERVER_DIR" >/dev/null mkdir dummy - pushd dummy + pushd dummy >/dev/null echo "Lorem Ipsum" > index.html echo '{"foo": "bar"}' > conf.json mkdir assets echo '.some.css { }' > assets/main.css echo 'var some="js";' > assets/main.js - popd - tar -czf dummy.tar.gz dummy - popd + popd >/dev/null + tar -czf dummy.tar.gz dummy >/dev/null + popd >/dev/null fi cat << EOF @@ -38,16 +38,17 @@ ynhtest_setup_source_nominal() { test -e "$install_dir" test -e "$install_dir/index.html" + test -e "$install_dir/assets" ls -ld "$install_dir" | grep -q "drwxr-x--- . $app www-data" ls -l "$install_dir/index.html" | grep -q "\-rw-r----- . $app www-data" + ls -ld "$install_dir/assets" | grep -q "drwxr-x--- . $app www-data" } ynhtest_setup_source_no_group_in_manifest() { install_dir="$(mktemp -d -p $VAR_WWW)" _make_dummy_manifest > ../manifest.toml sed '/www-data/d' -i ../manifest.toml - cat ../manifest.toml # debug ynh_setup_source --dest_dir="$install_dir" --source_id="dummy" @@ -56,6 +57,7 @@ ynhtest_setup_source_no_group_in_manifest() { ls -ld "$install_dir" | grep -q "drwxr-x--- . $app $app" ls -l "$install_dir/index.html" | grep -q "\-rw-r----- . $app $app" + ls -ld "$install_dir/assets" | grep -q "drwxr-x--- . $app $app" } From 7c7e763a74b470f48c2c257a5bd8367a1175302b Mon Sep 17 00:00:00 2001 From: Alexandre Aubin Date: Mon, 1 Jul 2024 23:39:34 +0200 Subject: [PATCH 26/28] Update changelog for 11.2.20.1 --- debian/changelog | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/debian/changelog b/debian/changelog index 21ddd5311..02d2cbab7 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,10 @@ +yunohost (11.2.20.1) stable; urgency=low + + - helpers2.1: typo (1ed56952e) + - helpers2.1: add unit tests (92807afb1) + + -- Alexandre Aubin Mon, 01 Jul 2024 23:38:29 +0200 + yunohost (11.2.20) stable; urgency=low - helpers2.1: fix automigration of phpversion to php_version (3f973669) From e55c91497414a4d453ad14432b0ec0f8ad69bb78 Mon Sep 17 00:00:00 2001 From: OniriCorpe Date: Tue, 2 Jul 2024 21:44:24 +0200 Subject: [PATCH 27/28] real working fix --- src/service.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/service.py b/src/service.py index 6bc325f49..6e17cfbee 100644 --- a/src/service.py +++ b/src/service.py @@ -297,7 +297,7 @@ def service_enable(names): names = [names] for name in names: if _run_service_command("enable", name): - _diagnosis_ignore(remove_filter="services", list=f"service={name}") + _diagnosis_ignore(remove_filter=["services", f"service={name}"]) logger.success(m18n.n("service_enabled", service=name)) else: raise YunohostError( @@ -317,7 +317,7 @@ def service_disable(names): names = [names] for name in names: if _run_service_command("disable", name): - _diagnosis_ignore(add_filter="services", list=f"service={name}") + _diagnosis_ignore(add_filter=["services", f"service={name}"]) logger.success(m18n.n("service_disabled", service=name)) else: raise YunohostError( From 41ca4222109f07796bc25b29ab3c1a093df5954d Mon Sep 17 00:00:00 2001 From: OniriCorpe Date: Tue, 2 Jul 2024 21:47:54 +0200 Subject: [PATCH 28/28] use of the intermediate functions with a more eloquent name for clarity --- src/service.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/service.py b/src/service.py index 6e17cfbee..97a5f4d65 100644 --- a/src/service.py +++ b/src/service.py @@ -26,7 +26,7 @@ from glob import glob from datetime import datetime from moulinette import m18n -from yunohost.diagnosis import _diagnosis_ignore +from yunohost.diagnosis import diagnosis_ignore, diagnosis_unignore from yunohost.utils.error import YunohostError, YunohostValidationError from moulinette.utils.process import check_output from moulinette.utils.log import getActionLogger @@ -297,7 +297,7 @@ def service_enable(names): names = [names] for name in names: if _run_service_command("enable", name): - _diagnosis_ignore(remove_filter=["services", f"service={name}"]) + diagnosis_unignore(["services", f"service={name}"]) logger.success(m18n.n("service_enabled", service=name)) else: raise YunohostError( @@ -317,7 +317,7 @@ def service_disable(names): names = [names] for name in names: if _run_service_command("disable", name): - _diagnosis_ignore(add_filter=["services", f"service={name}"]) + diagnosis_ignore(["services", f"service={name}"]) logger.success(m18n.n("service_disabled", service=name)) else: raise YunohostError(