Beispiel #1
0
 def test__delete__db__err_no_sqlalchemy_url(self):
     """
     Test database deletion
     """
     api = UserApi(
         current_user=None,
         session=self.session,
         config=self.app_config,
     )
     user = api.get_one_by_email('*****@*****.**')
     assert user.email == '*****@*****.**'
     assert user.validate_password('*****@*****.**')
     assert not user.validate_password('new_password')
     self.disconnect_database()
     app = TracimCLI()
     with pytest.raises(InvalidSettingFile):
         app.run([
             'db',
             'delete',
             '-c',
             'tests_configs.ini#command_test_no_sqlalchemy_url',
             '--debug',
         ])
     result = app.run([
         'db',
         'delete',
         '-c',
         'tests_configs.ini#command_test_no_sqlalchemy_url',
     ])
     assert result == 1
Beispiel #2
0
 def test_func__user_update_command__ok__remove_group(self) -> None:
     """
     Test user password update
     """
     api = UserApi(current_user=None, session=self.session, config=self.app_config)
     user = api.get_one_by_email("*****@*****.**")
     assert user.email == "*****@*****.**"
     assert user.validate_password("*****@*****.**")
     assert not user.validate_password("new_password")
     assert user.profile.name == "administrators"
     self.disconnect_database()
     app = TracimCLI()
     result = app.run(
         [
             "user",
             "update",
             "-c",
             "tests_configs.ini#command_test",
             "-l",
             "*****@*****.**",
             "-p",
             "new_password",
             "-rmg",
             "administrators",
             "--debug",
         ]
     )
     assert result == 0
     self.connect_database()
     api = UserApi(current_user=None, session=self.session, config=self.app_config)
     new_user = api.get_one_by_email("*****@*****.**")
     assert new_user.email == "*****@*****.**"
     assert new_user.validate_password("new_password")
     assert not new_user.validate_password("*****@*****.**")
     assert new_user.profile.name == "trusted-users"
Beispiel #3
0
 def test__delete__db__err_no_force_param(self, hapic, session,
                                          user_api_factory):
     """
     Test database deletion
     """
     api = user_api_factory.get()
     user = api.get_one_by_email("*****@*****.**")
     assert user.email == "*****@*****.**"
     assert user.validate_password("*****@*****.**")
     assert not user.validate_password("new_password")
     session.close()
     # NOTE GM 2019-07-21: Unset Depot configuration. Done here and not in fixture because
     # TracimCLI need reseted context when ran.
     DepotManager._clear()
     app = TracimCLI()
     with pytest.raises(ForceArgumentNeeded):
         app.run([
             "db", "delete", "-c",
             "{}#command_test".format(TEST_CONFIG_FILE_PATH), "--debug"
         ])
     result = app.run([
         "db", "delete", "-c",
         "{}#command_test".format(TEST_CONFIG_FILE_PATH)
     ])
     assert result == 1
Beispiel #4
0
 def test_func__user_create_command__ok__in_admin_group(self) -> None:
     """
     Test User creation with admin as group
     """
     api = UserApi(current_user=None,
                   session=self.session,
                   config=self.app_config)
     with pytest.raises(UserDoesNotExist):
         api.get_one_by_email("command_test@user")
     self.disconnect_database()
     app = TracimCLI()
     result = app.run([
         "user",
         "create",
         "-c",
         "{}#command_test".format(TEST_CONFIG_FILE_PATH),
         "-l",
         "command_test@user",
         "-p",
         "new_password",
         "-g",
         "administrators",
         "--debug",
     ])
     assert result == 0
     self.connect_database()
     api = UserApi(current_user=None,
                   session=self.session,
                   config=self.app_config)
     new_user = api.get_one_by_email("command_test@user")
     assert new_user.email == "command_test@user"
     assert new_user.validate_password("new_password")
     assert new_user.profile.name == "administrators"
Beispiel #5
0
 def test_func__user_create_command__ok__nominal_case(
         self, session, user_api_factory) -> None:
     """
     Test User creation
     """
     api = user_api_factory.get()
     with pytest.raises(UserDoesNotExist):
         api.get_one_by_email("command_test@user")
     session.close()
     # NOTE GM 2019-07-21: Unset Depot configuration. Done here and not in fixture because
     # TracimCLI needs the context to be reset when ran.
     DepotManager._clear()
     app = TracimCLI()
     result = app.run([
         "user",
         "create",
         "-c",
         "{}#command_test".format(TEST_CONFIG_FILE_PATH),
         "-e",
         "command_test@user",
         "-p",
         "new_password",
         "--debug",
     ])
     assert result == 0
     api = user_api_factory.get()
     new_user = api.get_one_by_email("command_test@user")
     assert new_user.email == "command_test@user"
     assert new_user.validate_password("new_password")
     assert new_user.profile.slug == "users"
Beispiel #6
0
 def test_func__user_update_command__err_password_modification_failed__external_auth(
         self) -> None:
     """
     Test user password update
     """
     api = UserApi(current_user=None,
                   session=self.session,
                   config=self.app_config)
     user = api.get_one_by_email("*****@*****.**")
     assert user.email == "*****@*****.**"
     assert user.validate_password("*****@*****.**")
     assert not user.validate_password("new_password")
     user.auth_type = AuthType.LDAP
     assert user.auth_type == AuthType.LDAP
     self.session.add(user)
     self.session.flush()
     transaction.commit()
     self.disconnect_database()
     app = TracimCLI()
     with pytest.raises(ExternalAuthUserPasswordModificationDisallowed):
         app.run([
             "user",
             "update",
             "-c",
             "{}#command_test".format(TEST_CONFIG_FILE_PATH),
             "-l",
             "*****@*****.**",
             "-p",
             "new_ldap_password",
             "--debug",
         ])
Beispiel #7
0
 def test_func__user_update_command__ok__nominal_case(
         self, hapic, session, user_api_factory) -> None:
     """
     Test user password update
     """
     api = user_api_factory.get()
     user = api.get_one_by_email("*****@*****.**")
     assert user.email == "*****@*****.**"
     assert user.validate_password("*****@*****.**")
     assert not user.validate_password("new_password")
     session.close()
     # NOTE GM 2019-07-21: Unset Depot configuration. Done here and not in fixture because
     # TracimCLI need reseted context when ran.
     DepotManager._clear()
     app = TracimCLI()
     result = app.run([
         "user",
         "update",
         "-c",
         "{}#command_test".format(TEST_CONFIG_FILE_PATH),
         "-l",
         "*****@*****.**",
         "-p",
         "new_password",
         "--debug",
     ])
     assert result == 0
     api = user_api_factory.get()
     new_user = api.get_one_by_email("*****@*****.**")
     assert new_user.email == "*****@*****.**"
     assert new_user.validate_password("new_password")
     assert not new_user.validate_password("*****@*****.**")
Beispiel #8
0
 def test__init__db__ok_nominal_case(self):
     """
     Test database initialisation
     """
     api = UserApi(
         current_user=None,
         session=self.session,
         config=self.app_config,
     )
     user = api.get_one_by_email('*****@*****.**')
     assert user.email == '*****@*****.**'
     assert user.validate_password('*****@*****.**')
     assert not user.validate_password('new_password')
     self.disconnect_database()
     app = TracimCLI()
     # delete config to be sure command will work
     app.run([
         'db',
         'delete',
         '--force',
         '-c',
         'tests_configs.ini#command_test',
         '--debug',
     ])
     result = app.run([
         'db',
         'init',
         '-c',
         'tests_configs.ini#command_test',
         '--debug',
     ])
     assert result == 0
Beispiel #9
0
 def test_func__user_update_command__ok__nominal_case(self) -> None:
     """
     Test user password update
     """
     api = UserApi(current_user=None,
                   session=self.session,
                   config=self.app_config)
     user = api.get_one_by_email("*****@*****.**")
     assert user.email == "*****@*****.**"
     assert user.validate_password("*****@*****.**")
     assert not user.validate_password("new_password")
     self.disconnect_database()
     app = TracimCLI()
     result = app.run([
         "user",
         "update",
         "-c",
         "{}#command_test".format(TEST_CONFIG_FILE_PATH),
         "-l",
         "*****@*****.**",
         "-p",
         "new_password",
         "--debug",
     ])
     assert result == 0
     self.connect_database()
     api = UserApi(current_user=None,
                   session=self.session,
                   config=self.app_config)
     new_user = api.get_one_by_email("*****@*****.**")
     assert new_user.email == "*****@*****.**"
     assert new_user.validate_password("new_password")
     assert not new_user.validate_password("*****@*****.**")
Beispiel #10
0
 def test__delete__db__err_no_config_file(self):
     """
     Test database deletion
     """
     api = UserApi(
         current_user=None,
         session=self.session,
         config=self.app_config,
     )
     user = api.get_one_by_email('*****@*****.**')
     assert user.email == '*****@*****.**'
     assert user.validate_password('*****@*****.**')
     assert not user.validate_password('new_password')
     self.disconnect_database()
     app = TracimCLI()
     with pytest.raises(FileNotFoundError):
         app.run([
             'db',
             'delete',
             '-c',
             'donotexit.ini#command_test',
             '--debug',
         ])
     result = app.run([
         'db',
         'delete',
         '-c',
         'donotexist.ini#command_test',
     ])
     assert result == 1
Beispiel #11
0
 def test_func__user_create_command__ok__nominal_case(self) -> None:
     """
     Test User creation
     """
     api = UserApi(
         current_user=None,
         session=self.session,
         config=self.app_config,
     )
     with pytest.raises(UserDoesNotExist):
         api.get_one_by_email('command_test@user')
     self.disconnect_database()
     app = TracimCLI()
     result = app.run([
         'user',
         'create',
         '-c',
         'tests_configs.ini#command_test',
         '-l',
         'command_test@user',
         '-p',
         'new_password',
         '--debug',
     ])
     assert result == 0
     self.connect_database()
     api = UserApi(
         current_user=None,
         session=self.session,
         config=self.app_config,
     )
     new_user = api.get_one_by_email('command_test@user')
     assert new_user.email == 'command_test@user'
     assert new_user.validate_password('new_password')
     assert new_user.profile.name == 'users'
Beispiel #12
0
 def test_func__user_create_command__ok__nominal_case(self) -> None:
     """
     Test User creation
     """
     api = UserApi(current_user=None, session=self.session, config=self.app_config)
     with pytest.raises(UserDoesNotExist):
         api.get_one_by_email("command_test@user")
     self.disconnect_database()
     app = TracimCLI()
     result = app.run(
         [
             "user",
             "create",
             "-c",
             "tests_configs.ini#command_test",
             "-l",
             "command_test@user",
             "-p",
             "new_password",
             "--debug",
         ]
     )
     assert result == 0
     self.connect_database()
     api = UserApi(current_user=None, session=self.session, config=self.app_config)
     new_user = api.get_one_by_email("command_test@user")
     assert new_user.email == "command_test@user"
     assert new_user.validate_password("new_password")
     assert new_user.profile.name == "users"
Beispiel #13
0
 def test__init__db__ok_nominal_case(self, hapic, session,
                                     user_api_factory):
     """
     Test database initialisation
     """
     api = user_api_factory.get()
     user = api.get_one_by_email("*****@*****.**")
     assert user.email == "*****@*****.**"
     assert user.validate_password("*****@*****.**")
     assert not user.validate_password("new_password")
     session.close()
     # NOTE GM 2019-07-21: Unset Depot configuration. Done here and not in fixture because
     # TracimCLI need reseted context when ran.
     DepotManager._clear()
     app = TracimCLI()
     # delete config to be sure command will work
     app.run([
         "db",
         "delete",
         "--force",
         "-c",
         "{}#command_test".format(TEST_CONFIG_FILE_PATH),
         "--debug",
     ])
     result = app.run([
         "db", "init", "-c",
         "{}#command_test".format(TEST_CONFIG_FILE_PATH), "--debug"
     ])
     assert result == 0
Beispiel #14
0
 def test__init__db__ok_nominal_case(self):
     """
     Test database initialisation
     """
     api = UserApi(current_user=None,
                   session=self.session,
                   config=self.app_config)
     user = api.get_one_by_email("*****@*****.**")
     assert user.email == "*****@*****.**"
     assert user.validate_password("*****@*****.**")
     assert not user.validate_password("new_password")
     self.disconnect_database()
     app = TracimCLI()
     # delete config to be sure command will work
     app.run([
         "db",
         "delete",
         "--force",
         "-c",
         "{}#command_test".format(TEST_CONFIG_FILE_PATH),
         "--debug",
     ])
     result = app.run([
         "db", "init", "-c",
         "{}#command_test".format(TEST_CONFIG_FILE_PATH), "--debug"
     ])
     assert result == 0
Beispiel #15
0
 def test_func__user_update_command__ok__nominal_case(self) -> None:
     """
     Test user password update
     """
     api = UserApi(
         current_user=None,
         session=self.session,
         config=self.app_config,
     )
     user = api.get_one_by_email('*****@*****.**')
     assert user.email == '*****@*****.**'
     assert user.validate_password('*****@*****.**')
     assert not user.validate_password('new_password')
     self.disconnect_database()
     app = TracimCLI()
     result = app.run([
         'user', 'update',
         '-c', 'tests_configs.ini#command_test',
         '-l', '*****@*****.**',
         '-p', 'new_password',
         '--debug',
     ])
     assert result == 0
     self.connect_database()
     api = UserApi(
         current_user=None,
         session=self.session,
         config=self.app_config,
     )
     new_user = api.get_one_by_email('*****@*****.**')
     assert new_user.email == '*****@*****.**'
     assert new_user.validate_password('new_password')
     assert not new_user.validate_password('*****@*****.**')
Beispiel #16
0
 def test_func__user_update_command__err_password_modification_failed__external_auth(
         self, hapic, session, user_api_factory) -> None:
     """
     Test user password update
     """
     api = user_api_factory.get()
     user = api.get_one_by_email("*****@*****.**")
     assert user.email == "*****@*****.**"
     assert user.validate_password("*****@*****.**")
     assert not user.validate_password("new_password")
     user.auth_type = AuthType.LDAP
     assert user.auth_type == AuthType.LDAP
     session.add(user)
     session.flush()
     transaction.commit()
     session.close()
     # NOTE GM 2019-07-21: Unset Depot configuration. Done here and not in fixture because
     # TracimCLI need reseted context when ran.
     DepotManager._clear()
     app = TracimCLI()
     with pytest.raises(ExternalAuthUserPasswordModificationDisallowed):
         app.run([
             "user",
             "update",
             "-c",
             "{}#command_test".format(TEST_CONFIG_FILE_PATH),
             "-l",
             "*****@*****.**",
             "-p",
             "new_ldap_password",
             "--debug",
         ])
Beispiel #17
0
 def test_func__user_update_command__err_password_modification_failed__external_auth(self) -> None:
     """
     Test user password update
     """
     api = UserApi(
         current_user=None,
         session=self.session,
         config=self.app_config,
     )
     user = api.get_one_by_email('*****@*****.**')
     assert user.email == '*****@*****.**'
     assert user.validate_password('*****@*****.**')
     assert not user.validate_password('new_password')
     user.auth_type = AuthType.LDAP
     assert user.auth_type == AuthType.LDAP
     self.session.add(user)
     self.session.flush()
     transaction.commit()
     self.disconnect_database()
     app = TracimCLI()
     with pytest.raises(ExternalAuthUserPasswordModificationDisallowed):
         result = app.run([
             'user', 'update',
             '-c', 'tests_configs.ini#command_test',
             '-l', '*****@*****.**',
             '-p', 'new_ldap_password',
             '--debug',
         ])
Beispiel #18
0
    def test_func__anonymize_user__ok__specific_display_name(
        self,
        session,
        user_api_factory,
        hapic,
        content_api_factory,
        workspace_api_factory,
        role_api_factory,
        content_type_list,
        admin_user,
    ) -> None:
        """
        Test User anonymization
        """
        uapi = user_api_factory.get()
        test_user = uapi.create_user(
            email="*****@*****.**",
            password="******",
            name="bob",
            profile=Profile.USER,
            timezone="Europe/Paris",
            lang="fr",
            do_save=True,
            do_notify=False,
        )
        user_id = test_user.user_id
        transaction.commit()
        assert session.query(User).filter(User.user_id == user_id).one()
        assert session.query(UserConfig).filter(
            UserConfig.user_id == user_id).one()
        session.close()
        # NOTE GM 2019-07-21: Unset Depot configuration. Done here and not in fixture because
        # TracimCLI need reseted context when ran.
        DepotManager._clear()
        app = TracimCLI()
        result = app.run([
            "user",
            "anonymize",
            "-c",
            "{}#command_test".format(TEST_CONFIG_FILE_PATH),
            "-l",
            "*****@*****.**",
            "--anonymize-name",
            "Custom Name",
        ])
        assert result == 0

        test_user_retrieve = session.query(User).filter(
            User.user_id == user_id).one()
        assert test_user_retrieve.display_name == "Custom Name"
        assert test_user_retrieve.email.endswith("@anonymous.local")
        assert test_user_retrieve.config.fields == {}
Beispiel #19
0
 def test__init__db__ok_db_already_exist(self):
     """
     Test database initialisation
     """
     api = UserApi(current_user=None, session=self.session, config=self.app_config)
     user = api.get_one_by_email("*****@*****.**")
     assert user.email == "*****@*****.**"
     assert user.validate_password("*****@*****.**")
     assert not user.validate_password("new_password")
     self.disconnect_database()
     app = TracimCLI()
     with pytest.raises(DatabaseInitializationFailed):
         app.run(["db", "init", "-c", "tests_configs.ini#command_test", "--debug"])
Beispiel #20
0
 def test_func__user_create_command__err__password_required(self) -> None:
     """
     Test User creation without filling password
     """
     self.disconnect_database()
     app = TracimCLI()
     with pytest.raises(BadCommandError):
         app.run([
             '--debug',
             'user', 'create',
             '-c', 'tests_configs.ini#command_test',
             '-l', '*****@*****.**',
             '--debug',
         ])
Beispiel #21
0
 def test__delete__db__ok_nominal_case(self):
     """
     Test database deletion
     """
     api = UserApi(current_user=None, session=self.session, config=self.app_config)
     user = api.get_one_by_email("*****@*****.**")
     assert user.email == "*****@*****.**"
     assert user.validate_password("*****@*****.**")
     assert not user.validate_password("new_password")
     self.disconnect_database()
     app = TracimCLI()
     result = app.run(
         ["db", "delete", "--force", "-c", "tests_configs.ini#command_test", "--debug"]
     )
     assert result == 0
Beispiel #22
0
 def test_func__user_create_command__err__in_unknown_group(self) -> None:
     """
     Test User creation with an unknown group
     """
     self.disconnect_database()
     app = TracimCLI()
     with pytest.raises(GroupDoesNotExist):
         app.run([
             'user', 'create',
             '-c', 'tests_configs.ini#command_test',
             '-l', 'command_test@user',
             '-p', 'new_password',
             '-g', 'unknown',
             '--debug',
         ])
Beispiel #23
0
 def test_func__user_create_command__err_user_already_exist(self) -> None:
     """
     Test User creation with existing user login
     """
     self.disconnect_database()
     app = TracimCLI()
     with pytest.raises(UserAlreadyExistError):
         app.run([
             '--debug',
             'user', 'create',
             '-c', 'tests_configs.ini#command_test',
             '-l', '*****@*****.**',
             '-p', 'new_password',
             '--debug',
         ])
Beispiel #24
0
 def test__delete__db__err_no_config_file(self):
     """
     Test database deletion
     """
     api = UserApi(current_user=None, session=self.session, config=self.app_config)
     user = api.get_one_by_email("*****@*****.**")
     assert user.email == "*****@*****.**"
     assert user.validate_password("*****@*****.**")
     assert not user.validate_password("new_password")
     self.disconnect_database()
     app = TracimCLI()
     with pytest.raises(FileNotFoundError):
         app.run(["db", "delete", "-c", "donotexit.ini#command_test", "--debug"])
     result = app.run(["db", "delete", "-c", "donotexist.ini#command_test"])
     assert result == 1
Beispiel #25
0
 def test_func__user_create_command__err__with_email_notification_disabled(self) -> None:  # nopep8
     """
     Test User creation with email with notification disable
     """
     self.disconnect_database()
     app = TracimCLI()
     with pytest.raises(NotificationDisabledCantCreateUserWithInvitation):
         app.run([
             '--debug',
             'user', 'create',
             '-c', 'tests_configs.ini#command_test',
             '-l', '*****@*****.**',
             '-p', 'new_password',
             '--send-email',
             '--debug',
         ])
Beispiel #26
0
 def test_func__delete_user__ok__nominal_case(
     self,
     session,
     user_api_factory,
     hapic,
     content_api_factory,
     workspace_api_factory,
     content_type_list,
 ) -> None:
     """
     Test User deletion : nominal case, user has change nothing in other user workspace
     """
     uapi = user_api_factory.get()
     test_user = uapi.create_user(
         email="*****@*****.**",
         password="******",
         name="bob",
         profile=Profile.USER,
         timezone="Europe/Paris",
         lang="fr",
         do_save=True,
         do_notify=False,
     )
     session.add(test_user)
     session.flush()
     transaction.commit()
     user_id = test_user.user_id
     session.close()
     # NOTE GM 2019-07-21: Unset Depot configuration. Done here and not in fixture because
     # TracimCLI need reseted context when ran.
     DepotManager._clear()
     app = TracimCLI()
     result = app.run([
         "user",
         "delete",
         "-c",
         "{}#command_test".format(TEST_CONFIG_FILE_PATH),
         "-l",
         "*****@*****.**",
         "-d",
     ])
     assert result == 0
     with pytest.raises(NoResultFound):
         session.query(User).filter(User.user_id == user_id).one()
     with pytest.raises(NoResultFound):
         session.query(UserConfig).filter(
             UserConfig.user_id == user_id).one()
Beispiel #27
0
 def test_func__user_create_command__err__password_required(self) -> None:
     """
     Test User creation without filling password
     """
     self.disconnect_database()
     app = TracimCLI()
     with pytest.raises(BadCommandError):
         app.run([
             "--debug",
             "user",
             "create",
             "-c",
             "{}#command_test".format(TEST_CONFIG_FILE_PATH),
             "-l",
             "*****@*****.**",
             "--debug",
         ])
Beispiel #28
0
 def test_func__user_create_command__err_user_already_exist(self) -> None:
     """
     Test User creation with existing user login
     """
     self.disconnect_database()
     app = TracimCLI()
     with pytest.raises(UserAlreadyExistError):
         app.run([
             "--debug",
             "user",
             "create",
             "-c",
             "{}#command_test".format(TEST_CONFIG_FILE_PATH),
             "-l",
             "*****@*****.**",
             "-p",
             "new_password",
             "--debug",
         ])
Beispiel #29
0
 def test_func__user_create_command__err__in_unknown_group(self) -> None:
     """
     Test User creation with an unknown group
     """
     self.disconnect_database()
     app = TracimCLI()
     with pytest.raises(GroupDoesNotExist):
         app.run([
             "user",
             "create",
             "-c",
             "{}#command_test".format(TEST_CONFIG_FILE_PATH),
             "-l",
             "command_test@user",
             "-p",
             "new_password",
             "-g",
             "unknown",
             "--debug",
         ])
Beispiel #30
0
 def test__init__db__ok_db_already_exist(self, hapic, session,
                                         user_api_factory):
     """
     Test database initialisation
     """
     api = user_api_factory.get()
     user = api.get_one_by_email("*****@*****.**")
     assert user.email == "*****@*****.**"
     assert user.validate_password("*****@*****.**")
     assert not user.validate_password("new_password")
     session.close()
     # NOTE GM 2019-07-21: Unset Depot configuration. Done here and not in fixture because
     # TracimCLI need reseted context when ran.
     DepotManager._clear()
     app = TracimCLI()
     with pytest.raises(DatabaseInitializationFailed):
         app.run([
             "db", "init", "-c",
             "{}#command_test".format(TEST_CONFIG_FILE_PATH), "--debug"
         ])