| @@ 2020-2081 (lines=62) @@ | ||
| 2017 | assert not user.validate_password('mynewpassword') |
|
| 2018 | assert not user.validate_password('mynewpassword2') |
|
| 2019 | ||
| 2020 | def test_api__set_account_password__ok_200__nominal(self): |
|
| 2021 | dbsession = get_tm_session(self.session_factory, transaction.manager) |
|
| 2022 | admin = dbsession.query(models.User) \ |
|
| 2023 | .filter(models.User.email == '[email protected]') \ |
|
| 2024 | .one() |
|
| 2025 | uapi = UserApi( |
|
| 2026 | current_user=admin, |
|
| 2027 | session=dbsession, |
|
| 2028 | config=self.app_config, |
|
| 2029 | ) |
|
| 2030 | gapi = GroupApi( |
|
| 2031 | current_user=admin, |
|
| 2032 | session=dbsession, |
|
| 2033 | config=self.app_config, |
|
| 2034 | ) |
|
| 2035 | groups = [gapi.get_one_with_name('users')] |
|
| 2036 | test_user = uapi.create_user( |
|
| 2037 | email='[email protected]', |
|
| 2038 | password='pass', |
|
| 2039 | name='bob', |
|
| 2040 | groups=groups, |
|
| 2041 | timezone='Europe/Paris', |
|
| 2042 | lang='fr', |
|
| 2043 | do_save=True, |
|
| 2044 | do_notify=False, |
|
| 2045 | ) |
|
| 2046 | uapi.save(test_user) |
|
| 2047 | transaction.commit() |
|
| 2048 | user_id = int(test_user.user_id) |
|
| 2049 | ||
| 2050 | self.testapp.authorization = ( |
|
| 2051 | 'Basic', |
|
| 2052 | ( |
|
| 2053 | '[email protected]', |
|
| 2054 | 'pass' |
|
| 2055 | ) |
|
| 2056 | ) |
|
| 2057 | # check before |
|
| 2058 | user = uapi.get_one(user_id) |
|
| 2059 | assert user.validate_password('pass') |
|
| 2060 | assert not user.validate_password('mynewpassword') |
|
| 2061 | # Set password |
|
| 2062 | params = { |
|
| 2063 | 'new_password': 'mynewpassword', |
|
| 2064 | 'new_password2': 'mynewpassword', |
|
| 2065 | 'loggedin_user_password': 'pass', |
|
| 2066 | } |
|
| 2067 | self.testapp.put_json( |
|
| 2068 | '/api/v2/users/me/password', |
|
| 2069 | params=params, |
|
| 2070 | status=204, |
|
| 2071 | ) |
|
| 2072 | # Check After |
|
| 2073 | dbsession = get_tm_session(self.session_factory, transaction.manager) |
|
| 2074 | uapi = UserApi( |
|
| 2075 | current_user=admin, |
|
| 2076 | session=dbsession, |
|
| 2077 | config=self.app_config, |
|
| 2078 | ) |
|
| 2079 | user = uapi.get_one(user_id) |
|
| 2080 | assert not user.validate_password('pass') |
|
| 2081 | assert user.validate_password('mynewpassword') |
|
| 2082 | ||
| 2083 | ||
| 2084 | ||
| @@ 5010-5071 (lines=62) @@ | ||
| 5007 | assert not user.validate_password('mynewpassword') |
|
| 5008 | assert not user.validate_password('mynewpassword2') |
|
| 5009 | ||
| 5010 | def test_api__set_user_password__ok_200__user_itself(self): |
|
| 5011 | dbsession = get_tm_session(self.session_factory, transaction.manager) |
|
| 5012 | admin = dbsession.query(models.User) \ |
|
| 5013 | .filter(models.User.email == '[email protected]') \ |
|
| 5014 | .one() |
|
| 5015 | uapi = UserApi( |
|
| 5016 | current_user=admin, |
|
| 5017 | session=dbsession, |
|
| 5018 | config=self.app_config, |
|
| 5019 | ) |
|
| 5020 | gapi = GroupApi( |
|
| 5021 | current_user=admin, |
|
| 5022 | session=dbsession, |
|
| 5023 | config=self.app_config, |
|
| 5024 | ) |
|
| 5025 | groups = [gapi.get_one_with_name('users')] |
|
| 5026 | test_user = uapi.create_user( |
|
| 5027 | email='[email protected]', |
|
| 5028 | password='pass', |
|
| 5029 | name='bob', |
|
| 5030 | groups=groups, |
|
| 5031 | timezone='Europe/Paris', |
|
| 5032 | lang='fr', |
|
| 5033 | do_save=True, |
|
| 5034 | do_notify=False, |
|
| 5035 | ) |
|
| 5036 | uapi.save(test_user) |
|
| 5037 | transaction.commit() |
|
| 5038 | user_id = int(test_user.user_id) |
|
| 5039 | ||
| 5040 | self.testapp.authorization = ( |
|
| 5041 | 'Basic', |
|
| 5042 | ( |
|
| 5043 | '[email protected]', |
|
| 5044 | 'pass' |
|
| 5045 | ) |
|
| 5046 | ) |
|
| 5047 | # check before |
|
| 5048 | user = uapi.get_one(user_id) |
|
| 5049 | assert user.validate_password('pass') |
|
| 5050 | assert not user.validate_password('mynewpassword') |
|
| 5051 | # Set password |
|
| 5052 | params = { |
|
| 5053 | 'new_password': 'mynewpassword', |
|
| 5054 | 'new_password2': 'mynewpassword', |
|
| 5055 | 'loggedin_user_password': 'pass', |
|
| 5056 | } |
|
| 5057 | self.testapp.put_json( |
|
| 5058 | '/api/v2/users/{}/password'.format(user_id), |
|
| 5059 | params=params, |
|
| 5060 | status=204, |
|
| 5061 | ) |
|
| 5062 | # Check After |
|
| 5063 | dbsession = get_tm_session(self.session_factory, transaction.manager) |
|
| 5064 | uapi = UserApi( |
|
| 5065 | current_user=admin, |
|
| 5066 | session=dbsession, |
|
| 5067 | config=self.app_config, |
|
| 5068 | ) |
|
| 5069 | user = uapi.get_one(user_id) |
|
| 5070 | assert not user.validate_password('pass') |
|
| 5071 | assert user.validate_password('mynewpassword') |
|
| 5072 | ||
| 5073 | def test_api__set_user_email__err_403__other_normal_user(self): |
|
| 5074 | dbsession = get_tm_session(self.session_factory, transaction.manager) |
|
| @@ 4813-4874 (lines=62) @@ | ||
| 4810 | """ |
|
| 4811 | fixtures = [BaseFixture] |
|
| 4812 | ||
| 4813 | def test_api__set_user_password__ok_200__admin(self): |
|
| 4814 | dbsession = get_tm_session(self.session_factory, transaction.manager) |
|
| 4815 | admin = dbsession.query(models.User) \ |
|
| 4816 | .filter(models.User.email == '[email protected]') \ |
|
| 4817 | .one() |
|
| 4818 | uapi = UserApi( |
|
| 4819 | current_user=admin, |
|
| 4820 | session=dbsession, |
|
| 4821 | config=self.app_config, |
|
| 4822 | ) |
|
| 4823 | gapi = GroupApi( |
|
| 4824 | current_user=admin, |
|
| 4825 | session=dbsession, |
|
| 4826 | config=self.app_config, |
|
| 4827 | ) |
|
| 4828 | groups = [gapi.get_one_with_name('users')] |
|
| 4829 | test_user = uapi.create_user( |
|
| 4830 | email='[email protected]', |
|
| 4831 | password='pass', |
|
| 4832 | name='bob', |
|
| 4833 | groups=groups, |
|
| 4834 | timezone='Europe/Paris', |
|
| 4835 | lang='fr', |
|
| 4836 | do_save=True, |
|
| 4837 | do_notify=False, |
|
| 4838 | ) |
|
| 4839 | uapi.save(test_user) |
|
| 4840 | transaction.commit() |
|
| 4841 | user_id = int(test_user.user_id) |
|
| 4842 | ||
| 4843 | self.testapp.authorization = ( |
|
| 4844 | 'Basic', |
|
| 4845 | ( |
|
| 4846 | '[email protected]', |
|
| 4847 | '[email protected]' |
|
| 4848 | ) |
|
| 4849 | ) |
|
| 4850 | # check before |
|
| 4851 | user = uapi.get_one(user_id) |
|
| 4852 | assert user.validate_password('pass') |
|
| 4853 | assert not user.validate_password('mynewpassword') |
|
| 4854 | # Set password |
|
| 4855 | params = { |
|
| 4856 | 'new_password': 'mynewpassword', |
|
| 4857 | 'new_password2': 'mynewpassword', |
|
| 4858 | 'loggedin_user_password': '[email protected]', |
|
| 4859 | } |
|
| 4860 | self.testapp.put_json( |
|
| 4861 | '/api/v2/users/{}/password'.format(user_id), |
|
| 4862 | params=params, |
|
| 4863 | status=204, |
|
| 4864 | ) |
|
| 4865 | # Check After |
|
| 4866 | dbsession = get_tm_session(self.session_factory, transaction.manager) |
|
| 4867 | uapi = UserApi( |
|
| 4868 | current_user=admin, |
|
| 4869 | session=dbsession, |
|
| 4870 | config=self.app_config, |
|
| 4871 | ) |
|
| 4872 | user = uapi.get_one(user_id) |
|
| 4873 | assert not user.validate_password('pass') |
|
| 4874 | assert user.validate_password('mynewpassword') |
|
| 4875 | ||
| 4876 | def test_api__set_user_password__err_403__admin_wrong_password(self): |
|
| 4877 | dbsession = get_tm_session(self.session_factory, transaction.manager) |
|