From df56cf90aa18235ee5103681dc76ff5dece841e0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Josu=C3=A9=20Tille?= Date: Fri, 7 Dec 2018 18:28:30 +0100 Subject: [PATCH 1/7] Ignore test directory --- .gitignore | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.gitignore b/.gitignore index 6dd427aba..75f4ae6ea 100644 --- a/.gitignore +++ b/.gitignore @@ -32,3 +32,6 @@ pip-log.txt # moulinette lib src/yunohost/locales + +# Test +src/yunohost/tests/apps From 03b1a2867ce4f8c0cce772c951c2f8f89acfa635 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Josu=C3=A9=20Tille?= Date: Fri, 7 Dec 2018 16:35:01 +0100 Subject: [PATCH 2/7] Fix tests --- locales/en.json | 2 + src/yunohost/settings.py | 7 ++- src/yunohost/tests/test_backuprestore.py | 68 ++++++++++-------------- 3 files changed, 35 insertions(+), 42 deletions(-) diff --git a/locales/en.json b/locales/en.json index 6ce22ca80..980dfb071 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 d2526316e..ee2f35785 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 1071c1642..c60dcb517 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 test_backup_script_failure_handling(monkeypatch, mocker): mocker.spy(m18n, "n") with pytest.raises(MoulinetteError): - backup_create(ignore_system=True, ignore_apps=False, apps=["backup_recommended_app"]) + backup_create(system=None, apps=["backup_recommended_app"]) m18n.n.assert_any_call('backup_app_failed', app='backup_recommended_app') @@ -313,7 +311,7 @@ def test_backup_not_enough_free_space(monkeypatch, mocker): mocker.spy(m18n, "n") with pytest.raises(MoulinetteError): - backup_create(ignore_system=True, ignore_apps=False, apps=["backup_recommended_app"]) + backup_create(system=None, 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(system=None, 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(system=None, 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(system=None, 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 test_restore_app_script_failure_handling(monkeypatch, mocker): 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 test_restore_app_not_enough_free_space(monkeypatch, mocker): 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(system=None, 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, system=None, 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') @@ -565,9 +550,10 @@ def test_backup_binds_are_readonly(monkeypatch): self.manager = backup_manager self._organize_files() + confssh = os.path.join(self.work_dir, "conf/ssh") output = subprocess.check_output("touch %s/test 2>&1 || true" % confssh, - shell=True) + shell=True, env={'LANG' : 'en_US.UTF-8'}) assert "Read-only file system" in output @@ -580,4 +566,4 @@ def test_backup_binds_are_readonly(monkeypatch): custom_mount_and_backup) # Create the backup - backup_create(ignore_system=False, ignore_apps=True) + backup_create(system=[]) From 1f13676d06717dbaa38530df0e4430d476be6f8f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Josu=C3=A9=20Tille?= Date: Fri, 7 Dec 2018 23:14:57 +0100 Subject: [PATCH 3/7] Fix LDAP authenticator after backup --- src/yunohost/tests/test_changeurl.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/yunohost/tests/test_changeurl.py b/src/yunohost/tests/test_changeurl.py index 737b68a6d..36d8028c9 100644 --- a/src/yunohost/tests/test_changeurl.py +++ b/src/yunohost/tests/test_changeurl.py @@ -19,8 +19,10 @@ maindomain = _get_maindomain() def setup_function(function): - pass - + # For some reason the nginx reload can take some time to propagate + time.sleep(1) + global auth + auth = init_authenticator(AUTH_IDENTIFIER, AUTH_PARAMETERS) def teardown_function(function): app_remove(auth, "change_url_app") From f93aa40c2e2ed2a071ce2556bfac08ea5712c959 Mon Sep 17 00:00:00 2001 From: Alexandre Aubin Date: Sat, 8 Dec 2018 00:18:02 +0100 Subject: [PATCH 4/7] Use 127.0.0.1 + domain header for local HTTP requests --- src/yunohost/tests/test_changeurl.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/yunohost/tests/test_changeurl.py b/src/yunohost/tests/test_changeurl.py index 36d8028c9..13f8aca5d 100644 --- a/src/yunohost/tests/test_changeurl.py +++ b/src/yunohost/tests/test_changeurl.py @@ -40,7 +40,7 @@ def check_changeurl_app(path): assert appmap[maindomain][path + "/"]["id"] == "change_url_app" - r = requests.get("https://%s%s/" % (maindomain, path), verify=False) + r = requests.get("https://127.0.0.1%s/" % path, headers={"domain": maindomain}, verify=False) assert r.status_code == 200 From 96a6e370a37b0c44d46df430dd740aac67cac2b4 Mon Sep 17 00:00:00 2001 From: Alexandre Aubin Date: Mon, 10 Dec 2018 02:53:27 +0100 Subject: [PATCH 5/7] [tests] Fix some issues with maindomain changing sometimes --- src/yunohost/tests/test_backuprestore.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/yunohost/tests/test_backuprestore.py b/src/yunohost/tests/test_backuprestore.py index c60dcb517..6dfbff9b7 100644 --- a/src/yunohost/tests/test_backuprestore.py +++ b/src/yunohost/tests/test_backuprestore.py @@ -15,7 +15,7 @@ from yunohost.domain import _get_maindomain from moulinette.core import MoulinetteError # Get main domain -maindomain = _get_maindomain() +maindomain = "" # Instantiate LDAP Authenticator AUTH_IDENTIFIER = ('ldap', 'ldap-anonymous') @@ -24,6 +24,9 @@ auth = None def setup_function(function): + global maindomain + maindomain = _get_maindomain() + print "" global auth From d06d1cdee4b5cb62c1ec9906c972fab89b16e802 Mon Sep 17 00:00:00 2001 From: Alexandre Aubin Date: Mon, 10 Dec 2018 03:33:40 +0100 Subject: [PATCH 6/7] Explicit that we don't backup/restore apps --- src/yunohost/tests/test_backuprestore.py | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/yunohost/tests/test_backuprestore.py b/src/yunohost/tests/test_backuprestore.py index 6dfbff9b7..c9d4c6b15 100644 --- a/src/yunohost/tests/test_backuprestore.py +++ b/src/yunohost/tests/test_backuprestore.py @@ -198,7 +198,7 @@ def add_archive_system_from_2p4(): def test_backup_only_ldap(): # Create the backup - backup_create(system=["conf_ldap"]) + backup_create(system=["conf_ldap"], apps=None) archives = backup_list()["archives"] assert len(archives) == 1 @@ -215,7 +215,7 @@ def test_backup_system_part_that_does_not_exists(mocker): # Create the backup with pytest.raises(MoulinetteError): - backup_create(system=["yolol"]) + backup_create(system=["yolol"], apps=None) m18n.n.assert_any_call('backup_hook_unknown', hook="yolol") m18n.n.assert_any_call('backup_nothings_done') @@ -227,7 +227,7 @@ def test_backup_system_part_that_does_not_exists(mocker): def test_backup_and_restore_all_sys(): # Create the backup - backup_create(system=[]) + backup_create(system=[], apps=None) archives = backup_list()["archives"] assert len(archives) == 1 @@ -244,7 +244,7 @@ def test_backup_and_restore_all_sys(): # Restore the backup backup_restore(auth, name=archives[0], force=True, - system=[]) + system=[], apps=None) # Check ssowat conf is back assert os.path.exists("/etc/ssowat/conf.json") @@ -258,7 +258,7 @@ def test_backup_and_restore_all_sys(): def test_restore_system_from_Ynh2p4(monkeypatch, mocker): # Backup current system - backup_create(system=[]) + backup_create(system=[], apps=None) archives = backup_list()["archives"] assert len(archives) == 2 @@ -266,11 +266,13 @@ def test_restore_system_from_Ynh2p4(monkeypatch, mocker): try: backup_restore(auth, name=backup_list()["archives"][1], system=[], + apps=None, force=True) finally: # Restore system as it was backup_restore(auth, name=backup_list()["archives"][0], system=[], + apps=None, force=True) ############################################################################### @@ -369,7 +371,7 @@ def test_backup_app_with_no_restore_script(mocker): def test_backup_with_different_output_directory(): # Create the backup - backup_create(system=["conf_ssh"], + backup_create(system=["conf_ssh"], apps=None, output_directory="/opt/test_backup_output_directory", name="backup") @@ -386,7 +388,7 @@ def test_backup_with_different_output_directory(): @pytest.mark.clean_opt_dir def test_backup_with_no_compress(): # Create the backup - backup_create(system=["conf_nginx"], + backup_create(system=["conf_nginx"], apps=None, output_directory="/opt/test_backup_output_directory", no_compress=True, name="backup") From d7f25bec2ab05faa6f69a9a37f75b570eb7430f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Josu=C3=A9=20Tille?= Date: Tue, 11 Dec 2018 20:18:23 +0100 Subject: [PATCH 7/7] Remove hack for authenticator It's solved in the moulinette with #185 --- src/yunohost/tests/test_changeurl.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/yunohost/tests/test_changeurl.py b/src/yunohost/tests/test_changeurl.py index 13f8aca5d..eb10cd604 100644 --- a/src/yunohost/tests/test_changeurl.py +++ b/src/yunohost/tests/test_changeurl.py @@ -19,10 +19,8 @@ maindomain = _get_maindomain() def setup_function(function): - # For some reason the nginx reload can take some time to propagate - time.sleep(1) - global auth - auth = init_authenticator(AUTH_IDENTIFIER, AUTH_PARAMETERS) + pass + def teardown_function(function): app_remove(auth, "change_url_app")