mirror of
https://github.com/YunoHost/yunohost.git
synced 2024-09-03 20:06:10 +02:00
manifestv2: implement test for permission ressource
This commit is contained in:
parent
dd6c8976f8
commit
ddd10f630c
1 changed files with 26 additions and 2 deletions
|
@ -4,7 +4,9 @@ import pytest
|
||||||
from moulinette.utils.process import check_output
|
from moulinette.utils.process import check_output
|
||||||
|
|
||||||
from yunohost.app import app_setting
|
from yunohost.app import app_setting
|
||||||
|
from yunohost.domain import _get_maindomain
|
||||||
from yunohost.utils.resources import AppResource, AppResourceManager, AppResourceClassesByType
|
from yunohost.utils.resources import AppResource, AppResourceManager, AppResourceClassesByType
|
||||||
|
from yunohost.permission import user_permission_list, permission_delete
|
||||||
|
|
||||||
dummyfile = "/tmp/dummyappresource-testapp"
|
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("apt remove lolcat sl nyancat yarn >/dev/null 2>/dev/null")
|
||||||
os.system("userdel testapp 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():
|
def test_provision_dummy():
|
||||||
|
|
||||||
|
@ -327,17 +333,35 @@ def test_resource_apt():
|
||||||
|
|
||||||
def test_resource_permissions():
|
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"]
|
r = AppResourceClassesByType["permissions"]
|
||||||
conf = {
|
conf = {
|
||||||
"main": {
|
"main": {
|
||||||
"url": "/",
|
"url": "/",
|
||||||
"allowed": "visitors"
|
"allowed": "visitors"
|
||||||
# protected?
|
# 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"
|
||||||
|
|
Loading…
Add table
Reference in a new issue