mirror of
https://github.com/YunoHost/yunohost.git
synced 2024-09-03 20:06:10 +02:00
Add backup/restore test for permission app, and fix a small related bug
This commit is contained in:
parent
ec5069b71c
commit
ccc7583ec4
2 changed files with 50 additions and 11 deletions
|
@ -1367,8 +1367,10 @@ class RestoreManager():
|
|||
if "allowed" not in permission_infos:
|
||||
logger.warning("'allowed' key corresponding to allowed groups for permission %s not found when restoring app %s ... You might need to reconfigure permissions yourself!" % (permission_name, app_instance_name))
|
||||
else:
|
||||
groups = [g for g in permission_infos["allowed"] if g in existing_groups]
|
||||
user_permission_update(permission_name, remove="all_users", add=groups)
|
||||
should_be_allowed = [g for g in permission_infos["allowed"] if g in existing_groups]
|
||||
current_allowed = user_permission_list()["permissions"][permission_name]["allowed"]
|
||||
if should_be_allowed != current_allowed:
|
||||
user_permission_update(permission_name, remove=current_allowed, add=should_be_allowed)
|
||||
|
||||
os.remove('%s/permissions.yml' % app_settings_new_path)
|
||||
else:
|
||||
|
|
|
@ -10,7 +10,7 @@ from yunohost.app import _is_installed
|
|||
from yunohost.backup import backup_create, backup_restore, backup_list, backup_info, backup_delete, _recursive_umount
|
||||
from yunohost.domain import _get_maindomain
|
||||
from yunohost.utils.error import YunohostError
|
||||
from yunohost.user import user_permission_list
|
||||
from yunohost.user import user_permission_list, user_create, user_list, user_delete
|
||||
from yunohost.tests.test_permission import check_LDAP_db_integrity, check_permission_for_apps
|
||||
|
||||
# Get main domain
|
||||
|
@ -59,6 +59,13 @@ def setup_function(function):
|
|||
add_archive_system_from_2p4()
|
||||
assert len(backup_list()["archives"]) == 1
|
||||
|
||||
if "with_permission_app_installed" in markers:
|
||||
assert not app_is_installed("permissions_app")
|
||||
user_create("alice", "Alice", "White", "alice@" + maindomain, "test123Ynh")
|
||||
install_app("permissions_app_ynh", "/urlpermissionapp"
|
||||
"&admin=alice")
|
||||
assert app_is_installed("permissions_app")
|
||||
|
||||
|
||||
def teardown_function(function):
|
||||
|
||||
|
@ -73,6 +80,9 @@ def teardown_function(function):
|
|||
if "clean_opt_dir" in markers:
|
||||
shutil.rmtree("/opt/test_backup_output_directory")
|
||||
|
||||
if "alice" in user_list()["users"]:
|
||||
user_delete("alice")
|
||||
|
||||
|
||||
@pytest.fixture(autouse=True)
|
||||
def check_LDAP_db_integrity_call():
|
||||
|
@ -92,6 +102,9 @@ def check_permission_for_apps_call():
|
|||
|
||||
def app_is_installed(app):
|
||||
|
||||
if app == "permissions_app":
|
||||
return _is_installed(app)
|
||||
|
||||
# These are files we know should be installed by the app
|
||||
app_files = []
|
||||
app_files.append("/etc/nginx/conf.d/%s.d/%s.conf" % (maindomain, app))
|
||||
|
@ -155,14 +168,9 @@ def delete_all_backups():
|
|||
|
||||
def uninstall_test_apps_if_needed():
|
||||
|
||||
if _is_installed("legacy_app"):
|
||||
app_remove("legacy_app")
|
||||
|
||||
if _is_installed("backup_recommended_app"):
|
||||
app_remove("backup_recommended_app")
|
||||
|
||||
if _is_installed("wordpress"):
|
||||
app_remove("wordpress")
|
||||
for app in ["legacy_app", "backup_recommended_app", "wordpress", "permissions_app"]:
|
||||
if _is_installed(app):
|
||||
app_remove(app)
|
||||
|
||||
|
||||
def install_app(app, path, additionnal_args=""):
|
||||
|
@ -514,6 +522,35 @@ def test_backup_and_restore_with_ynh_restore():
|
|||
|
||||
_test_backup_and_restore_app("backup_recommended_app")
|
||||
|
||||
@pytest.mark.with_permission_app_installed
|
||||
def test_backup_and_restore_permission_app():
|
||||
|
||||
res = user_permission_list(full=True)['permissions']
|
||||
assert "permissions_app.main" in res
|
||||
assert "permissions_app.admin" in res
|
||||
assert "permissions_app.dev" in res
|
||||
assert res['permissions_app.main']['urls'] == [maindomain + "/urlpermissionapp"]
|
||||
assert res['permissions_app.admin']['urls'] == [maindomain + "/urlpermissionapp/admin"]
|
||||
assert res['permissions_app.dev']['urls'] == [maindomain + "/urlpermissionapp/dev"]
|
||||
|
||||
assert res['permissions_app.main']['allowed'] == ["all_users"]
|
||||
assert res['permissions_app.admin']['allowed'] == ["alice"]
|
||||
assert res['permissions_app.dev']['allowed'] == []
|
||||
|
||||
_test_backup_and_restore_app("permissions_app")
|
||||
|
||||
res = user_permission_list(full=True)['permissions']
|
||||
assert "permissions_app.main" in res
|
||||
assert "permissions_app.admin" in res
|
||||
assert "permissions_app.dev" in res
|
||||
assert res['permissions_app.main']['urls'] == [maindomain + "/urlpermissionapp"]
|
||||
assert res['permissions_app.admin']['urls'] == [maindomain + "/urlpermissionapp/admin"]
|
||||
assert res['permissions_app.dev']['urls'] == [maindomain + "/urlpermissionapp/dev"]
|
||||
|
||||
assert res['permissions_app.main']['allowed'] == ["all_users"]
|
||||
assert res['permissions_app.admin']['allowed'] == ["alice"]
|
||||
assert res['permissions_app.dev']['allowed'] == []
|
||||
|
||||
|
||||
def _test_backup_and_restore_app(app):
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue