From ddd10f630c8a3dc20087f5b2a497e062b808c035 Mon Sep 17 00:00:00 2001 From: Alexandre Aubin Date: Fri, 13 May 2022 22:14:20 +0200 Subject: [PATCH] manifestv2: implement test for permission ressource --- src/tests/test_app_resources.py | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/src/tests/test_app_resources.py b/src/tests/test_app_resources.py index 820ad6cb7..3640adde0 100644 --- a/src/tests/test_app_resources.py +++ b/src/tests/test_app_resources.py @@ -4,7 +4,9 @@ import pytest from moulinette.utils.process import check_output from yunohost.app import app_setting +from yunohost.domain import _get_maindomain from yunohost.utils.resources import AppResource, AppResourceManager, AppResourceClassesByType +from yunohost.permission import user_permission_list, permission_delete dummyfile = "/tmp/dummyappresource-testapp" @@ -57,6 +59,10 @@ def clean(): os.system("apt remove lolcat sl nyancat yarn >/dev/null 2>/dev/null") os.system("userdel testapp 2>/dev/null") + for p in user_permission_list()["permissions"]: + if p.startswith("testapp."): + permission_delete(p, force=True, sync_perm=False) + def test_provision_dummy(): @@ -327,17 +333,35 @@ def test_resource_apt(): def test_resource_permissions(): - raise NotImplementedError() + maindomain = _get_maindomain() + os.system(f"echo 'domain: {maindomain}' >> /etc/yunohost/apps/testapp/settings.yml") + os.system("echo 'path: /testapp' >> /etc/yunohost/apps/testapp/settings.yml") + # A manager object is required to set the label of the app... + manager = AppResourceManager("testapp", current={}, wanted={"name": "Test App"}) r = AppResourceClassesByType["permissions"] conf = { "main": { "url": "/", "allowed": "visitors" # protected? + }, + "admin": { + "url": "/admin", + "allowed": "" } } - pass + res = user_permission_list(full=True)["permissions"] + assert not any(key.startswith("testapp.") for key in res) + r(conf, "testapp", manager).provision_or_update() + res = user_permission_list(full=True)["permissions"] + assert "testapp.main" in res + assert "visitors" in res["testapp.main"]["allowed"] + assert res["testapp.main"]["url"] == "/" + + assert "testapp.admin" in res + assert not res["testapp.admin"]["allowed"] + assert res["testapp.admin"]["url"] == "/admin"