diff --git a/conf/nginx-redirect.conf b/conf/nginx-redirect.conf index 731c42d..1ee1b6a 100644 --- a/conf/nginx-redirect.conf +++ b/conf/nginx-redirect.conf @@ -1,3 +1,3 @@ location __PATH__ { - return 302 __TARGET__$request_uri; + return 302 __TARGET__; } diff --git a/scripts/_common.sh b/scripts/_common.sh index dee0ea0..ebc643a 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -1,13 +1,5 @@ #!/bin/bash -#================================================= -# COMMON VARIABLES -#================================================= - -#================================================= -# PERSONAL HELPERS -#================================================= - URL_REGEX_VALID='(https?|ftp|file)://[-A-Za-z0-9\+&@#/%?=~_|!:,.;]*[-A-Za-z0-9\+&@#/%=~_|]' URL_REGEX_SECURE='^(http://(127\.[0-9]+\.[0-9]+\.[0-9]+|localhost)|https://.*)(:[0-9]+)?(/.*)?$' @@ -23,10 +15,26 @@ _validate_redirect_uri() { fi } -#================================================= -# EXPERIMENTAL HELPERS -#================================================= +_add_dummy_service() { + cat << EOF > /etc/systemd/system/whatever.service +[Unit] +Description=Whatever +After=network.target -#================================================= -# FUTURE OFFICIAL HELPERS -#================================================= +[Service] +WorkingDirectory=/redirect/ +ExecStart=python3 -m http.server -b 127.0.0.1 1234 +PrivateTmp=true + +[Install] +WantedBy=multi-user.target +EOF + + mkdir -p /redirect + echo "helloworld" > /redirect/index.html + systemctl daemon-reload + ynh_systemd_action --service_name=whatever --action=enable + ynh_systemd_action --service_name=whatever --action=restart + + true +} diff --git a/scripts/install b/scripts/install index 351e62d..d44668d 100644 --- a/scripts/install +++ b/scripts/install @@ -11,6 +11,12 @@ source /usr/share/yunohost/helpers _validate_redirect_uri +# When testing on the CI, we need a service to test the reverse-proxying +if [[ ${PACKAGE_CHECK_EXEC} == "1" ]] && [[ "$redirect_type" == "reverseproxy" ]] +then + _add_dummy_service +fi + #================================================= # CONFIGURE NGINX #================================================= @@ -19,6 +25,14 @@ ynh_script_progression --message="Configuring NGINX web server..." --weight=1 mv ../conf/{"nginx-$redirect_type.conf",nginx.conf} ynh_add_nginx_config + +if [[ ${PACKAGE_CHECK_EXEC} == "1" ]] && [[ "$redirect_type" == "reverseproxy" ]] +then + systemctl status whatever >&2 + sleep 3 +fi + + #================================================= # END OF SCRIPT #================================================= diff --git a/scripts/restore b/scripts/restore index f8838c7..de715e2 100644 --- a/scripts/restore +++ b/scripts/restore @@ -1,5 +1,6 @@ #!/bin/bash +source ../settings/scripts/_common.sh source /usr/share/yunohost/helpers ynh_restore_file "/etc/nginx/conf.d/${domain}.d/${app}.conf" @@ -7,6 +8,12 @@ ynh_restore_file "/etc/nginx/conf.d/${domain}.d/${app}.conf" ynh_script_progression --message="Reloading NGINX web server..." --weight=1 ynh_systemd_action --service_name=nginx --action=reload +# When testing on the CI, we need a service to test the reverse-proxying +if [[ ${PACKAGE_CHECK_EXEC} == "1" ]] && [[ "$redirect_type" == "reverseproxy" ]] +then + _add_dummy_service +fi + #================================================= # END OF SCRIPT #================================================= diff --git a/scripts/upgrade b/scripts/upgrade index f317e68..8f8a22c 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -20,6 +20,12 @@ if [[ -z "${target:-}" ]] && [[ -n "${redirect_path:-}" ]]; then ynh_app_setting_set --app=$app --key=target --value="$redirect_path" fi +# When testing on the CI, we need a service to test the reverse-proxying +if [[ ${PACKAGE_CHECK_EXEC} == "1" ]] && [[ "$redirect_type" == "reverseproxy" ]] +then + _add_dummy_service +fi + #================================================= # CONFIGURE NGINX #================================================= diff --git a/tests.toml b/tests.toml index 288a9dd..44f0e46 100644 --- a/tests.toml +++ b/tests.toml @@ -4,25 +4,34 @@ test_format = 1.0 [default] - args.redirect_type = "redirect" - args.target = "http://127.0.0.1" + args.redirect_type = "reverseproxy" + args.target = "http://127.0.0.1:1234/" + + exclude = ["install.private", "install.multi", "backup_restore", "change_url"] [default.test_upgrade_from.09cf1c6b] name = "v1 era" args.domain = "domain.tld" - args.redirect_type = "visible_302" - args.redirect_path = "http://127.0.0.1" + args.path = "/" + args.redirect_type = "proxy" + args.redirect_path = "http://127.0.0.1:1234/" + args.is_public = true -[reverseproxy] +[redirect] - args.redirect_type = "reverseproxy" - args.target = "http://127.0.0.1" + args.redirect_type = "redirect" + args.target = "https://127.0.0.1" - exclude = ["install.private", "install.multi", "backup_restore"] + # Turns out 302 redirects cant be made private because they are interpreted before going through the sso ... + exclude = ["install.private"] - [reverseproxy.test_upgrade_from.09cf1c6b] + [redirect.test_upgrade_from.09cf1c6b] name = "v1 era" args.domain = "domain.tld" - args.redirect_type = "proxy" - args.redirect_path = "http://127.0.0.1" + args.path = "/" + args.redirect_type = "visible_302" + args.redirect_path = "https://127.0.0.1" + args.is_public = true + +