| @@ 1886-1950 (lines=65) @@ | ||
| 1883 | """ |
|
| 1884 | fixtures = [BaseFixture] |
|
| 1885 | ||
| 1886 | def test_api__set_account_password__err_403__admin_wrong_password(self): |
|
| 1887 | dbsession = get_tm_session(self.session_factory, transaction.manager) |
|
| 1888 | admin = dbsession.query(models.User) \ |
|
| 1889 | .filter(models.User.email == '[email protected]') \ |
|
| 1890 | .one() |
|
| 1891 | uapi = UserApi( |
|
| 1892 | current_user=admin, |
|
| 1893 | session=dbsession, |
|
| 1894 | config=self.app_config, |
|
| 1895 | ) |
|
| 1896 | gapi = GroupApi( |
|
| 1897 | current_user=admin, |
|
| 1898 | session=dbsession, |
|
| 1899 | config=self.app_config, |
|
| 1900 | ) |
|
| 1901 | groups = [gapi.get_one_with_name('users')] |
|
| 1902 | test_user = uapi.create_user( |
|
| 1903 | email='[email protected]', |
|
| 1904 | password='pass', |
|
| 1905 | name='bob', |
|
| 1906 | groups=groups, |
|
| 1907 | timezone='Europe/Paris', |
|
| 1908 | lang='fr', |
|
| 1909 | do_save=True, |
|
| 1910 | do_notify=False, |
|
| 1911 | ) |
|
| 1912 | uapi.save(test_user) |
|
| 1913 | transaction.commit() |
|
| 1914 | user_id = int(test_user.user_id) |
|
| 1915 | ||
| 1916 | self.testapp.authorization = ( |
|
| 1917 | 'Basic', |
|
| 1918 | ( |
|
| 1919 | '[email protected]', |
|
| 1920 | '[email protected]' |
|
| 1921 | ) |
|
| 1922 | ) |
|
| 1923 | # check before |
|
| 1924 | user = uapi.get_one(user_id) |
|
| 1925 | assert user.validate_password('pass') |
|
| 1926 | assert not user.validate_password('mynewpassword') |
|
| 1927 | # Set password |
|
| 1928 | params = { |
|
| 1929 | 'new_password': 'mynewpassword', |
|
| 1930 | 'new_password2': 'mynewpassword', |
|
| 1931 | 'loggedin_user_password': 'wrongpassword', |
|
| 1932 | } |
|
| 1933 | res = self.testapp.put_json( |
|
| 1934 | '/api/v2/users/me/password', |
|
| 1935 | params=params, |
|
| 1936 | status=403, |
|
| 1937 | ) |
|
| 1938 | assert res.json_body |
|
| 1939 | assert 'code' in res.json_body |
|
| 1940 | assert res.json_body['code'] == error.WRONG_USER_PASSWORD |
|
| 1941 | dbsession = get_tm_session(self.session_factory, transaction.manager) |
|
| 1942 | uapi = UserApi( |
|
| 1943 | current_user=admin, |
|
| 1944 | session=dbsession, |
|
| 1945 | config=self.app_config, |
|
| 1946 | ) |
|
| 1947 | # Check After |
|
| 1948 | user = uapi.get_one(user_id) |
|
| 1949 | assert user.validate_password('pass') |
|
| 1950 | assert not user.validate_password('mynewpassword') |
|
| 1951 | ||
| 1952 | def test_api__set_account_password__err_400__admin_passwords_do_not_match(self): # nopep8 |
|
| 1953 | dbsession = get_tm_session(self.session_factory, transaction.manager) |
|
| @@ 4876-4940 (lines=65) @@ | ||
| 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) |
|
| 4878 | admin = dbsession.query(models.User) \ |
|
| 4879 | .filter(models.User.email == '[email protected]') \ |
|
| 4880 | .one() |
|
| 4881 | uapi = UserApi( |
|
| 4882 | current_user=admin, |
|
| 4883 | session=dbsession, |
|
| 4884 | config=self.app_config, |
|
| 4885 | ) |
|
| 4886 | gapi = GroupApi( |
|
| 4887 | current_user=admin, |
|
| 4888 | session=dbsession, |
|
| 4889 | config=self.app_config, |
|
| 4890 | ) |
|
| 4891 | groups = [gapi.get_one_with_name('users')] |
|
| 4892 | test_user = uapi.create_user( |
|
| 4893 | email='[email protected]', |
|
| 4894 | password='pass', |
|
| 4895 | name='bob', |
|
| 4896 | groups=groups, |
|
| 4897 | timezone='Europe/Paris', |
|
| 4898 | lang='fr', |
|
| 4899 | do_save=True, |
|
| 4900 | do_notify=False, |
|
| 4901 | ) |
|
| 4902 | uapi.save(test_user) |
|
| 4903 | transaction.commit() |
|
| 4904 | user_id = int(test_user.user_id) |
|
| 4905 | ||
| 4906 | self.testapp.authorization = ( |
|
| 4907 | 'Basic', |
|
| 4908 | ( |
|
| 4909 | '[email protected]', |
|
| 4910 | '[email protected]' |
|
| 4911 | ) |
|
| 4912 | ) |
|
| 4913 | # check before |
|
| 4914 | user = uapi.get_one(user_id) |
|
| 4915 | assert user.validate_password('pass') |
|
| 4916 | assert not user.validate_password('mynewpassword') |
|
| 4917 | # Set password |
|
| 4918 | params = { |
|
| 4919 | 'new_password': 'mynewpassword', |
|
| 4920 | 'new_password2': 'mynewpassword', |
|
| 4921 | 'loggedin_user_password': 'wrongpassword', |
|
| 4922 | } |
|
| 4923 | res = self.testapp.put_json( |
|
| 4924 | '/api/v2/users/{}/password'.format(user_id), |
|
| 4925 | params=params, |
|
| 4926 | status=403, |
|
| 4927 | ) |
|
| 4928 | assert res.json_body |
|
| 4929 | assert 'code' in res.json_body |
|
| 4930 | assert res.json_body['code'] == error.WRONG_USER_PASSWORD |
|
| 4931 | dbsession = get_tm_session(self.session_factory, transaction.manager) |
|
| 4932 | uapi = UserApi( |
|
| 4933 | current_user=admin, |
|
| 4934 | session=dbsession, |
|
| 4935 | config=self.app_config, |
|
| 4936 | ) |
|
| 4937 | # Check After |
|
| 4938 | user = uapi.get_one(user_id) |
|
| 4939 | assert user.validate_password('pass') |
|
| 4940 | assert not user.validate_password('mynewpassword') |
|
| 4941 | ||
| 4942 | def test_api__set_user_password__err_400__admin_passwords_do_not_match(self): # nopep8 |
|
| 4943 | dbsession = get_tm_session(self.session_factory, transaction.manager) |
|