diff --git a/locales/en.json b/locales/en.json index 6ce22ca80b..980dfb0715 100644 --- a/locales/en.json +++ b/locales/en.json @@ -194,6 +194,8 @@ "global_settings_setting_example_enum": "Example enum option", "global_settings_setting_example_int": "Example int option", "global_settings_setting_example_string": "Example string option", + "global_settings_setting_security_password_admin_strength": "Admin password strength", + "global_settings_setting_security_password_user_strength": "User password strength", "global_settings_unknown_setting_from_settings_file": "Unknown key in settings: '{setting_key:s}', discarding it and save it in /etc/yunohost/unkown_settings.json", "global_settings_unknown_type": "Unexpected situation, the setting {setting:s} appears to have the type {unknown_type:s} but it's not a type supported by the system.", "good_practices_about_admin_password": "You are now about to define a new administration password. The password should be at least 8 characters - though it is good practice to use longer password (i.e. a passphrase) and/or to use various kind of characters (uppercase, lowercase, digits and special characters).", diff --git a/src/yunohost/settings.py b/src/yunohost/settings.py index d2526316ef..ee2f357857 100644 --- a/src/yunohost/settings.py +++ b/src/yunohost/settings.py @@ -95,7 +95,12 @@ def settings_set(key, value): elif key_type == "int": if not isinstance(value, int) or isinstance(value, bool): if isinstance(value, str): - value=int(value) + try: + value=int(value) + except: + raise MoulinetteError(errno.EINVAL, m18n.n( + 'global_settings_bad_type_for_setting', setting=key, + received_type=type(value).__name__, expected_type=key_type)) else: raise MoulinetteError(errno.EINVAL, m18n.n( 'global_settings_bad_type_for_setting', setting=key, diff --git a/src/yunohost/tests/test_backuprestore.py b/src/yunohost/tests/test_backuprestore.py index 1071c1642c..9721d59a78 100644 --- a/src/yunohost/tests/test_backuprestore.py +++ b/src/yunohost/tests/test_backuprestore.py @@ -195,7 +195,7 @@ def add_archive_system_from_2p4(): def test_backup_only_ldap(): # Create the backup - backup_create(ignore_system=False, ignore_apps=True, system=["conf_ldap"]) + backup_create(system=["conf_ldap"]) archives = backup_list()["archives"] assert len(archives) == 1 @@ -212,7 +212,7 @@ def test_backup_system_part_that_does_not_exists(mocker): # Create the backup with pytest.raises(MoulinetteError): - backup_create(ignore_system=False, ignore_apps=True, system=["yolol"]) + backup_create(system=["yolol"]) m18n.n.assert_any_call('backup_hook_unknown', hook="yolol") m18n.n.assert_any_call('backup_nothings_done') @@ -224,7 +224,7 @@ def test_backup_system_part_that_does_not_exists(mocker): def test_backup_and_restore_all_sys(): # Create the backup - backup_create(ignore_system=False, ignore_apps=True) + backup_create(system=[]) archives = backup_list()["archives"] assert len(archives) == 1 @@ -241,7 +241,7 @@ def test_backup_and_restore_all_sys(): # Restore the backup backup_restore(auth, name=archives[0], force=True, - ignore_system=False, ignore_apps=True) + system=[]) # Check ssowat conf is back assert os.path.exists("/etc/ssowat/conf.json") @@ -255,21 +255,19 @@ def test_backup_and_restore_all_sys(): def test_restore_system_from_Ynh2p4(monkeypatch, mocker): # Backup current system - backup_create(ignore_system=False, ignore_apps=True) + backup_create(system=[]) archives = backup_list()["archives"] assert len(archives) == 2 # Restore system archive from 2.4 try: backup_restore(auth, name=backup_list()["archives"][1], - ignore_system=False, - ignore_apps=True, + system=[], force=True) finally: # Restore system as it was backup_restore(auth, name=backup_list()["archives"][0], - ignore_system=False, - ignore_apps=True, + system=[], force=True) ############################################################################### @@ -293,7 +291,7 @@ def custom_hook_exec(name, *args, **kwargs): mocker.spy(m18n, "n") with pytest.raises(MoulinetteError): - backup_create(ignore_system=True, ignore_apps=False, apps=["backup_recommended_app"]) + backup_create(apps=["backup_recommended_app"]) m18n.n.assert_any_call('backup_app_failed', app='backup_recommended_app') @@ -313,7 +311,7 @@ def custom_free_space_in_directory(dirpath): mocker.spy(m18n, "n") with pytest.raises(MoulinetteError): - backup_create(ignore_system=True, ignore_apps=False, apps=["backup_recommended_app"]) + backup_create(apps=["backup_recommended_app"]) m18n.n.assert_any_call('not_enough_disk_space', path=ANY) @@ -325,7 +323,7 @@ def test_backup_app_not_installed(mocker): mocker.spy(m18n, "n") with pytest.raises(MoulinetteError): - backup_create(ignore_system=True, ignore_apps=False, apps=["wordpress"]) + backup_create(apps=["wordpress"]) m18n.n.assert_any_call("unbackup_app", app="wordpress") m18n.n.assert_any_call('backup_nothings_done') @@ -341,7 +339,7 @@ def test_backup_app_with_no_backup_script(mocker): mocker.spy(m18n, "n") with pytest.raises(MoulinetteError): - backup_create(ignore_system=True, ignore_apps=False, apps=["backup_recommended_app"]) + backup_create(apps=["backup_recommended_app"]) m18n.n.assert_any_call("backup_with_no_backup_script_for_app", app="backup_recommended_app") m18n.n.assert_any_call('backup_nothings_done') @@ -359,7 +357,7 @@ def test_backup_app_with_no_restore_script(mocker): # Backuping an app with no restore script will only display a warning to the # user... - backup_create(ignore_system=True, ignore_apps=False, apps=["backup_recommended_app"]) + backup_create(apps=["backup_recommended_app"]) m18n.n.assert_any_call("backup_with_no_restore_script_for_app", app="backup_recommended_app") @@ -368,7 +366,7 @@ def test_backup_app_with_no_restore_script(mocker): def test_backup_with_different_output_directory(): # Create the backup - backup_create(ignore_system=False, ignore_apps=True, system=["conf_ssh"], + backup_create(system=["conf_ssh"], output_directory="/opt/test_backup_output_directory", name="backup") @@ -385,7 +383,7 @@ def test_backup_with_different_output_directory(): @pytest.mark.clean_opt_dir def test_backup_with_no_compress(): # Create the backup - backup_create(ignore_system=False, ignore_apps=True, system=["conf_nginx"], + backup_create(system=["conf_nginx"], output_directory="/opt/test_backup_output_directory", no_compress=True, name="backup") @@ -400,9 +398,7 @@ def test_backup_with_no_compress(): @pytest.mark.with_wordpress_archive_from_2p4 def test_restore_app_wordpress_from_Ynh2p4(): - backup_restore(auth, name=backup_list()["archives"][0], - ignore_system=True, - ignore_apps=False, + backup_restore(auth, system=None, name=backup_list()["archives"][0], apps=["wordpress"]) @@ -420,9 +416,7 @@ def custom_hook_exec(name, *args, **kwargs): assert not _is_installed("wordpress") with pytest.raises(MoulinetteError): - backup_restore(auth, name=backup_list()["archives"][0], - ignore_system=True, - ignore_apps=False, + backup_restore(auth, system=None, name=backup_list()["archives"][0], apps=["wordpress"]) m18n.n.assert_any_call('restore_app_failed', app='wordpress') @@ -443,9 +437,7 @@ def custom_free_space_in_directory(dirpath): assert not _is_installed("wordpress") with pytest.raises(MoulinetteError): - backup_restore(auth, name=backup_list()["archives"][0], - ignore_system=True, - ignore_apps=False, + backup_restore(auth, system=None, name=backup_list()["archives"][0], apps=["wordpress"]) m18n.n.assert_any_call('restore_not_enough_disk_space', @@ -464,9 +456,7 @@ def test_restore_app_not_in_backup(mocker): mocker.spy(m18n, "n") with pytest.raises(MoulinetteError): - backup_restore(auth, name=backup_list()["archives"][0], - ignore_system=True, - ignore_apps=False, + backup_restore(auth, system=None, name=backup_list()["archives"][0], apps=["yoloswag"]) m18n.n.assert_any_call('backup_archive_app_not_found', app="yoloswag") @@ -479,18 +469,14 @@ def test_restore_app_already_installed(mocker): assert not _is_installed("wordpress") - backup_restore(auth, name=backup_list()["archives"][0], - ignore_system=True, - ignore_apps=False, + backup_restore(auth, system=None, name=backup_list()["archives"][0], apps=["wordpress"]) assert _is_installed("wordpress") mocker.spy(m18n, "n") with pytest.raises(MoulinetteError): - backup_restore(auth, name=backup_list()["archives"][0], - ignore_system=True, - ignore_apps=False, + backup_restore(auth, system=None, name=backup_list()["archives"][0], apps=["wordpress"]) m18n.n.assert_any_call('restore_already_installed_app', app="wordpress") @@ -520,7 +506,7 @@ def test_backup_and_restore_with_ynh_restore(): def _test_backup_and_restore_app(app): # Create a backup of this app - backup_create(ignore_system=True, ignore_apps=False, apps=[app]) + backup_create(apps=[app]) archives = backup_list()["archives"] assert len(archives) == 1 @@ -535,8 +521,8 @@ def _test_backup_and_restore_app(app): assert not app_is_installed(app) # Restore the app - backup_restore(auth, name=archives[0], ignore_system=True, - ignore_apps=False, apps=[app]) + backup_restore(auth, name=archives[0], + apps=[app]) assert app_is_installed(app) @@ -554,8 +540,7 @@ def test_restore_archive_with_no_json(mocker): mocker.spy(m18n, "n") with pytest.raises(MoulinetteError): - backup_restore(auth, name="badbackup", force=True, - ignore_system=False, ignore_apps=False) + backup_restore(auth, name="badbackup", force=True) m18n.n.assert_any_call('backup_invalid_archive') @@ -580,4 +565,4 @@ def custom_mount_and_backup(self, backup_manager): custom_mount_and_backup) # Create the backup - backup_create(ignore_system=False, ignore_apps=True) + backup_create(system=[])