Moar tests for apps breaking the system

This commit is contained in:
Alexandre Aubin 2019-08-24 00:15:42 +02:00
parent 3eb089ffc0
commit 799c68f1a8

View file

@ -13,9 +13,6 @@ from yunohost.utils.error import YunohostError
from yunohost.tests.test_permission import check_LDAP_db_integrity, check_permission_for_apps
MAIN_DOMAIN = _get_maindomain()
def setup_function(function):
clean()
@ -33,17 +30,24 @@ def clean():
if _is_installed("legacy_app"):
app_remove("legacy_app")
if _is_installed("break_yo_system"):
app_remove("break_yo_system")
to_remove = []
to_remove += glob.glob("/etc/nginx/conf.d/*.d/*legacy*")
to_remove += glob.glob("/etc/nginx/conf.d/*.d/*break_yo_system*")
for filepath in to_remove:
os.remove(filepath)
to_remove = []
to_remove += glob.glob("/etc/yunohost/apps/*legacy_app*")
to_remove += glob.glob("/etc/yunohost/apps/*break_yo_system*")
to_remove += glob.glob("/var/www/*legacy*")
for folderpath in to_remove:
shutil.rmtree(folderpath, ignore_errors=True)
os.system("systemctl start nginx")
@pytest.fixture(autouse=True)
def check_LDAP_db_integrity_call():
@ -78,13 +82,12 @@ def secondary_domain(request):
def app_expected_files(domain, app):
yield "/etc/nginx/conf.d/%s.d/%s.conf" % (domain, app)
yield "/var/www/%s/index.html" % app
if app.startswith("legacy_app"):
yield "/var/www/%s/index.html" % app
yield "/etc/yunohost/apps/%s/settings.yml" % app
yield "/etc/yunohost/apps/%s/manifest.json" % app
yield "/etc/yunohost/apps/%s/scripts/install" % app
yield "/etc/yunohost/apps/%s/scripts/remove" % app
yield "/etc/yunohost/apps/%s/scripts/backup" % app
yield "/etc/yunohost/apps/%s/scripts/restore" % app
def app_is_installed(domain, app):
@ -113,16 +116,25 @@ def install_legacy_app(domain, path):
force=True)
def install_break_yo_system(domain, breakwhat):
app_install("./tests/apps/break_yo_system_ynh",
args="domain=%s&breakwhat=%s" % (domain, breakwhat),
force=True)
def test_legacy_app_install_main_domain():
install_legacy_app(MAIN_DOMAIN, "/legacy")
main_domain = _get_maindomain()
assert app_is_installed(MAIN_DOMAIN, "legacy_app")
assert app_is_exposed_on_http(MAIN_DOMAIN, "/legacy", "This is a dummy app")
install_legacy_app(main_domain, "/legacy")
assert app_is_installed(main_domain, "legacy_app")
assert app_is_exposed_on_http(main_domain, "/legacy", "This is a dummy app")
app_remove("legacy_app")
assert app_is_not_installed(MAIN_DOMAIN, "legacy_app")
assert app_is_not_installed(main_domain, "legacy_app")
def test_legacy_app_install_secondary_domain(secondary_domain):
@ -211,15 +223,10 @@ def test_legacy_app_install_path_unavailable(secondary_domain):
assert app_is_not_installed(secondary_domain, "legacy_app__2")
def test_legacy_app_failed_install(secondary_domain):
mkdir("/var/www/legacy_app/", 0o750)
def test_legacy_app_install_bad_args():
with pytest.raises(YunohostError):
install_legacy_app(secondary_domain, "/legacy")
# TODO check error message
assert app_is_not_installed(secondary_domain, "legacy_app")
install_legacy_app("this.domain.does.not.exists", "/legacy")
def test_legacy_app_install_with_nginx_down(secondary_domain):
@ -229,20 +236,82 @@ def test_legacy_app_install_with_nginx_down(secondary_domain):
with pytest.raises(YunohostError):
install_legacy_app(secondary_domain, "/legacy")
os.system("systemctl start nginx")
def test_legacy_app_failed_install(secondary_domain):
# This will conflict with the folder that the app
# attempts to create, making the install fail
mkdir("/var/www/legacy_app/", 0o750)
with pytest.raises(YunohostError):
install_legacy_app(secondary_domain, "/legacy")
# TODO check error message
assert app_is_not_installed(secondary_domain, "legacy_app")
def test_legacy_app_failed_remove():
def test_legacy_app_failed_remove(secondary_domain):
# FIXME What's supposed to happen lol
raise NotImplementedError
install_legacy_app(secondary_domain, "/legacy")
# The remove script runs with set -eu and attempt to remove this
# file without -f, so will fail if it's not there ;)
os.remove("/etc/nginx/conf.d/%s.d/%s.conf" % (secondary_domain, "legacy_app"))
with pytest.raises(YunohostError):
app_remove("legacy")
#
# Well here, we hit the classical issue where if an app removal script
# fails, so far there's no obvious way to make sure that all files related
# to this app got removed ...
#
assert app_is_not_installed(secondary_domain, "legacy")
def test_legacy_app_install_fucksup_nginx():
def test_systemfuckedup_during_app_install(secondary_domain):
# FIXME What's supposed to happen lol
raise NotImplementedError
with pytest.raises(YunohostError):
install_break_yo_system(secondary_domain, breakwhat="install")
os.system("nginx -t")
os.system("systemctl status nginx")
def test_legacy_app_install_with_dpkg_fuckedup():
assert app_is_not_installed(secondary_domain, "break_yo_system")
def test_systemfuckedup_during_app_remove(secondary_domain):
install_break_yo_system(secondary_domain, breakwhat="remove")
with pytest.raises(YunohostError):
app_remove("break_yo_system")
os.system("nginx -t")
os.system("systemctl status nginx")
assert app_is_not_installed(secondary_domain, "break_yo_system")
def test_systemfuckedup_during_app_install_and_remove(secondary_domain):
with pytest.raises(YunohostError):
install_break_yo_system(secondary_domain, breakwhat="everything")
assert app_is_not_installed(secondary_domain, "break_yo_system")
def test_systemfuckedup_during_app_upgrade(secondary_domain):
raise NotImplementedError
install_break_yo_system(secondary_domain, breakwhat="upgrade")
#app_upgrade("break_yo_system", ...)
def test_failed_multiple_app_upgrade(secondary_domain):
raise NotImplementedError
install_legacy_app(secondary_domain, "/legacy")
install_break_yo_system(secondary_domain, breakwhat="upgrade")
app_upgrade(["break_yo_system", "legacy"])