🍽 Fork YunoHost — snapshot mangé par la machine à tsoins
Some checks failed
Check for new n releases / updater (push) Has been cancelled
CodeQL / Analyze (python) (push) Has been cancelled

Upstream: https://github.com/YunoHost/yunohost @ 3a5f8bac8301c450897b96cbd43a4c7d3ba750fb
But (José) : transformer tout le code en bions + ploxions du xerboxion.
La carte de digestion vit au labo : /yunohost-digest.json
This commit is contained in:
machine-a-tsoins
2026-07-03 17:20:06 +00:00
commit edb4c397df
395 changed files with 105504 additions and 0 deletions

View File

@@ -0,0 +1,36 @@
#!/usr/bin/env bash
ynhtest_apt_install_apt_deps_regular() {
cat << EOF > ../manifest.toml
packaging_format = 2
id = "${app:?}"
version = "0.1~ynh2"
EOF
if dpkg --list | grep -q "ii *$app-ynh-deps "; then
apt remove "$app-ynh-deps" --assume-yes
fi
if dpkg --list | grep -q 'ii *nyancat '; then
apt remove nyancat --assume-yes
fi
if dpkg --list | grep -q 'ii *sl '; then
apt remove sl --assume-yes
fi
! _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"
}

View File

@@ -0,0 +1,665 @@
#!/usr/bin/env bash
#################
# _ __ _ _ #
# | '_ \| | | | #
# | |_) | |_| | #
# | .__/ \__, | #
# | | __/ | #
# |_| |___/ #
# #
#################
_read_py() {
local file="$1"
local key="$2"
python3 -c "exec(open('$file').read()); print(repr($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="$file" --key="FOO")" == "None"
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="$file" --key="TITLE")" == "Lorem Ipsum"
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="$file" --key="EMAIL")" == "root@example.com"
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="$file" --key="URL")" == "https://yunohost.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="$file" --key="user")" == "camille"
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"
! _read_py "$file" "ENABLE"
test "$(ynh_read_var_in_file --file="$file" --key="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="$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="$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="$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="$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="$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="$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="$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="$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="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="$file" --key="ENABLE" --value="foobar"
! _read_py "$file" "ENABLE"
test "$(ynh_read_var_in_file --file="$file" --key="ENABLE")" == "YNH_NULL"
}
###############
# _ _ #
# (_) (_) #
# _ _ __ _ #
# | | '_ \| | #
# | | | | | | #
# |_|_| |_|_| #
# #
###############
_read_ini() {
local file="$1"
local key="$2"
python3 -c "import configparser; c = configparser.ConfigParser(); c.read('$file'); print(repr(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="$file" --key="foo")" == "null"
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="$file" --key="title")" == "Lorem Ipsum"
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 ; This is a comment without quotes'"
test "$(ynh_read_var_in_file --file="$file" --key="email")" == "root@example.com"
# test "$(_read_ini "$file" "port")" == "1234 ; This is a comment without quotes"
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="$file" --key="url")" == "https://yunohost.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="$file" --key="nonexistent")" == "YNH_NULL"
! _read_ini "$file" "enable"
test "$(ynh_read_var_in_file --file="$file" --key="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="$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="$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="$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="$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="$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="$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="$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="$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"
test "$(ynh_read_var_in_file --file="$file" --key="nonexistent")" == "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"
}
#############################
# _ #
# | | #
# _ _ __ _ _ __ ___ | | #
# | | | |/ _` | '_ ` _ \| | #
# | |_| | (_| | | | | | | | #
# \__, |\__,_|_| |_| |_|_| #
# __/ | #
# |___/ #
# #
#############################
_read_yaml() {
local file="$1"
local key="$2"
python3 -c "import yaml; print(repr(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="$file" --key="foo")" == ""
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="$file" --key="title")" == "Lorem Ipsum"
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="$file" --key="email")" == "root@example.com"
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="$file" --key="url")" == "https://yunohost.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="$file" --key="nonexistent")" == "YNH_NULL"
! _read_yaml "$file" "enable"
test "$(ynh_read_var_in_file --file="$file" --key="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="$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="$file" --key="foo")" == "bar"
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="$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="$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="$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="$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="$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="$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="$file" --key="nonexistent" --value="foobar"
test "$(ynh_read_var_in_file --file="$file" --key="nonexistent")" == "YNH_NULL"
! 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"
}
#########################
# _ #
# (_) #
# _ ___ ___ _ __ #
# | / __|/ _ \| '_ \ #
# | \__ \ (_) | | | | #
# | |___/\___/|_| |_| #
# _/ | #
# |__/ #
# #
#########################
_read_json() {
local file="$1"
local key="$2"
python3 -c "import json; print(repr(json.load(open('$file'))['$key']))"
}
ynhtest_config_read_json() {
local dummy_dir="$(mktemp -d -p "$VAR_WWW")"
file="$dummy_dir/dummy.json"
# The space after `"url": "https://yunohost.org", ` is a test not a mistake...
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="$file" --key="foo")" == "null"
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="$file" --key="title")" == "Lorem Ipsum"
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="$file" --key="email")" == "root@example.com"
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="$file" --key="url")" == "https://yunohost.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="$file" --key="nonexistent")" == "YNH_NULL"
! _read_json "$file" "enable"
test "$(ynh_read_var_in_file --file="$file" --key="enable")" == "YNH_NULL"
}
ynhtest_config_write_json() {
local dummy_dir="$(mktemp -d -p "$VAR_WWW")"
file="$dummy_dir/dummy.json"
# The space after `"url": "https://yunohost.org", ` is a test not a mistake...
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="$file" --key="foo" --value="bar"
cat "$file"
test "$(_read_json "$file" "foo")" == "'bar'"
test "$(ynh_read_var_in_file --file="$file" --key="foo")" == "bar"
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="$file" --key="enabled")" == "true"
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="$file" --key="title")" == "Foo Bar"
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="$file" --key="theme")" == "super-awesome-theme"
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="$file" --key="email")" == "sam@domain.tld"
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="$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="$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="$file" --key="nonexistent" --value="foobar"
test "$(ynh_read_var_in_file --file="$file" --key="nonexistent")" == "YNH_NULL"
! 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"
}
#######################
# _ #
# | | #
# _ __ | |__ _ __ #
# | '_ \| '_ \| '_ \ #
# | |_) | | | | |_) | #
# | .__/|_| |_| .__/ #
# | | | | #
# |_| |_| #
# #
#######################
_read_php() {
local file="$1"
local key="$2"
php -r "include '$file'; echo var_export(\$$key);"
}
ynhtest_config_read_php() {
local dummy_dir="$(mktemp -d -p "$VAR_WWW")"
file="$dummy_dir/dummy.php"
cat << EOF > "$file"
<?php
// Some comment
\$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 second comment without quotes
\$url = "https://yunohost.org";
\$dict = [
'ldap_base' => "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="$file" --key="foo")" == "NULL"
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="$file" --key="title")" == "Lorem Ipsum"
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="$file" --key="email")" == "root@example.com"
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="$file" --key="url")" == "https://yunohost.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="$file" --key="user")" == "camille"
test "$(ynh_read_var_in_file --file="$file" --key="DB_HOST")" == "localhost"
! _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="$file" --key="enable")" == "YNH_NULL"
}
ynhtest_config_write_php() {
local dummy_dir="$(mktemp -d -p "$VAR_WWW")"
file="$dummy_dir/dummy.php"
cat << EOF > "$file"
<?php
// Some comment
\$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="$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="$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="$file" --key="title" --value="Foo Bar"
cat "$file"
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="$file" --key="theme" --value="super-awesome-theme"
cat "$file"
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="$file" --key="email" --value="sam@domain.tld"
cat "$file"
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="$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="$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="$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="$file" --key="nonexistent" --value="foobar"
test "$(ynh_read_var_in_file --file="$file" --key="nonexistent")" == "YNH_NULL"
! 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"
}

View File

@@ -0,0 +1,54 @@
#!/usr/bin/env bash
# shellcheck disable=SC2016,SC2034,SC2089,SC2090
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"
test ! -e $FOO
! ynh_hide_warnings "touch $FOO"
! test -e $FOO
}

View File

@@ -0,0 +1,86 @@
#!/usr/bin/env bash
ynhtest_nodejs_install() {
local install_dir="$(mktemp -d -p "$VAR_WWW")"
nodejs_version=20
ynh_nodejs_install
node --version | grep -q '^v20\.'
pushd "$install_dir"
# Install a random simple package to validate npm is in the path and working
npm install ansi-styles
# FIXME: should test installing as non-root with ynh_exec_as_app to validate PATH propagation ?
test -d ./node_modules
popd
}
ynhtest_ruby_install() {
local install_dir="$(mktemp -d -p "$VAR_WWW")"
cat << EOF > ../manifest.toml
packaging_format = 2
id = "${app:?}"
version = "0.1~ynh2"
EOF
ynh_apt_install_dependencies "gcc make libjemalloc-dev libffi-dev libyaml-dev zlib1g-dev"
ruby_version=3.3.5
ynh_ruby_install
ruby --version
ruby --version | grep '^ruby 3\.3\.5'
pushd "$install_dir"
# FIXME: should test installing as non-root with ynh_exec_as_app to validate PATH propagation ?
gem install bundler passenger --no-document
bundle config set --local without 'development test'
popd
}
ynhtest_go_install() {
local install_dir="$(mktemp -d -p "$VAR_WWW")"
go_version=1.22
ynh_go_install
go version
go version | grep 'go1.22.12 linux'
pushd "$install_dir"
# FIXME: should test building as non-root with ynh_exec_as_app to validate PATH propagation ?
cat << EOF > helloworld.go
package main
import "fmt"
func main() { fmt.Println("hello world") }
EOF
go build helloworld.go
test -e helloworld
./helloworld | grep "hello world"
popd
}
ynhtest_composer_install() {
local install_dir="$(mktemp -d -p "$VAR_WWW")"
chown "${app:?}" -R "$install_dir"
cat << EOF > ../manifest.toml
packaging_format = 2
id = "${app:?}"
version = "0.1~ynh2"
EOF
php_version=8.2
ynh_apt_install_dependencies php$php_version-fpm
composer_version="2.8.3"
pushd "$install_dir"
ynh_composer_install
# FIXME: should test installing as non-root with ynh_exec_as_app to validate PATH propagation ?
# Install a random simple package to validate composer is working
ynh_composer_exec require symfony/polyfill-mbstring 1.31.0
popd
}

View File

@@ -0,0 +1,73 @@
#!/usr/bin/env bash
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
}

View File

@@ -0,0 +1,60 @@
#!/usr/bin/env bash
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")"
ynh_app_setting_set --key="foo" --value="foovalue"
ynh_app_setting_set --app="$app" --key="bar" --value="barvalue"
test "$(ynh_app_setting_get --key="foo")" == "foovalue"
test "$(ynh_app_setting_get --key="bar")" == "barvalue"
ynh_app_setting_delete --key="foo"
ynh_app_setting_delete --app="$app" --key="bar"
test -z "$(ynh_app_setting_get --key="foo")"
test -z "$(ynh_app_setting_get --key="bar")"
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"
}

View File

@@ -0,0 +1,116 @@
#!/usr/bin/env bash
# shellcheck disable=SC2164,SC2010
_make_dummy_manifest() {
if [ ! -e "$HTTPSERVER_DIR/dummy.tar.gz" ]; then
pushd "$HTTPSERVER_DIR" >/dev/null
mkdir 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 >/dev/null
tar -czf dummy.tar.gz dummy >/dev/null
popd >/dev/null
fi
cat << EOF
packaging_format = 2
id = "${app:?}"
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"
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
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"
ls -ld "$install_dir/assets" | grep -q "drwxr-x--- . $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"
}

View File

@@ -0,0 +1,12 @@
#!/usr/bin/env bash
ynhtest_string_random() {
declare -A results
for _ in $(seq 1 1000); do
local result="$(ynh_string_random --length=64 --filter='a-f0-9')"
test -n "${result:-}"
echo "result=$result"
test -z "${results["$result"]:-}"
results["$result"]="1"
done
}

View File

@@ -0,0 +1,74 @@
#!/usr/bin/env bash
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__
passwd=__WITH_SPECIAL_CHARS__
EOF
foo="bar"
with_special_chars="hello&world"
install_dir="$VAR_WWW"
ynh_config_add --template="$template" --destination="$VAR_WWW/config.txt"
test "$(cat "$VAR_WWW/config.txt")" == "$(echo -ne 'app=ynhtest\nfoo=bar\npasswd=hello&world')"
# shellcheck disable=SC2012
test "$(ls -l "$VAR_WWW/config.txt" | cut -d' ' -f1-4)" == "-rw------- 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 /etc/cron.d/ynhtest_config)" == "$(echo -ne 'app=ynhtest\nfoo=bar')"
# shellcheck disable=SC2012
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"
my_json='{"hello": "toto"}'
template="$(mktemp -d -p "$VAR_WWW")/template.txt"
cat << EOF > "$template"
app={{ app }}
{% if foo == "bar" %}foo=true{% endif %}
{% set mydict = my_json | from_json -%}
text_from_json={{ mydict.hello }}
EOF
# shellcheck disable=SC2034
foo="bar"
# shellcheck disable=SC2034
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\ntext_from_json=toto')"
# shellcheck disable=SC2012
test "$(ls -l "$VAR_WWW/config.txt" | cut -d' ' -f1-4)" == "-rw------- 1 ynhtest ynhtest"
}

View File

@@ -0,0 +1,26 @@
#!/usr/bin/env bash
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"
}