| @@ 4590-4651 (lines=62) @@ | ||
| 4587 | assert not user.validate_password('mynewpassword') |
|
| 4588 | assert not user.validate_password('mynewpassword2') |
|
| 4589 | ||
| 4590 | def test_api__set_user_password__ok_200__user_itself(self): |
|
| 4591 | dbsession = get_tm_session(self.session_factory, transaction.manager) |
|
| 4592 | admin = dbsession.query(models.User) \ |
|
| 4593 | .filter(models.User.email == '[email protected]') \ |
|
| 4594 | .one() |
|
| 4595 | uapi = UserApi( |
|
| 4596 | current_user=admin, |
|
| 4597 | session=dbsession, |
|
| 4598 | config=self.app_config, |
|
| 4599 | ) |
|
| 4600 | gapi = GroupApi( |
|
| 4601 | current_user=admin, |
|
| 4602 | session=dbsession, |
|
| 4603 | config=self.app_config, |
|
| 4604 | ) |
|
| 4605 | groups = [gapi.get_one_with_name('users')] |
|
| 4606 | test_user = uapi.create_user( |
|
| 4607 | email='[email protected]', |
|
| 4608 | password='pass', |
|
| 4609 | name='bob', |
|
| 4610 | groups=groups, |
|
| 4611 | timezone='Europe/Paris', |
|
| 4612 | lang='fr', |
|
| 4613 | do_save=True, |
|
| 4614 | do_notify=False, |
|
| 4615 | ) |
|
| 4616 | uapi.save(test_user) |
|
| 4617 | transaction.commit() |
|
| 4618 | user_id = int(test_user.user_id) |
|
| 4619 | ||
| 4620 | self.testapp.authorization = ( |
|
| 4621 | 'Basic', |
|
| 4622 | ( |
|
| 4623 | '[email protected]', |
|
| 4624 | 'pass' |
|
| 4625 | ) |
|
| 4626 | ) |
|
| 4627 | # check before |
|
| 4628 | user = uapi.get_one(user_id) |
|
| 4629 | assert user.validate_password('pass') |
|
| 4630 | assert not user.validate_password('mynewpassword') |
|
| 4631 | # Set password |
|
| 4632 | params = { |
|
| 4633 | 'new_password': 'mynewpassword', |
|
| 4634 | 'new_password2': 'mynewpassword', |
|
| 4635 | 'loggedin_user_password': 'pass', |
|
| 4636 | } |
|
| 4637 | self.testapp.put_json( |
|
| 4638 | '/api/v2/users/{}/password'.format(user_id), |
|
| 4639 | params=params, |
|
| 4640 | status=204, |
|
| 4641 | ) |
|
| 4642 | # Check After |
|
| 4643 | dbsession = get_tm_session(self.session_factory, transaction.manager) |
|
| 4644 | uapi = UserApi( |
|
| 4645 | current_user=admin, |
|
| 4646 | session=dbsession, |
|
| 4647 | config=self.app_config, |
|
| 4648 | ) |
|
| 4649 | user = uapi.get_one(user_id) |
|
| 4650 | assert not user.validate_password('pass') |
|
| 4651 | assert user.validate_password('mynewpassword') |
|
| 4652 | ||
| 4653 | def test_api__set_user_email__err_403__other_normal_user(self): |
|
| 4654 | dbsession = get_tm_session(self.session_factory, transaction.manager) |
|
| @@ 4393-4454 (lines=62) @@ | ||
| 4390 | """ |
|
| 4391 | fixtures = [BaseFixture] |
|
| 4392 | ||
| 4393 | def test_api__set_user_password__ok_200__admin(self): |
|
| 4394 | dbsession = get_tm_session(self.session_factory, transaction.manager) |
|
| 4395 | admin = dbsession.query(models.User) \ |
|
| 4396 | .filter(models.User.email == '[email protected]') \ |
|
| 4397 | .one() |
|
| 4398 | uapi = UserApi( |
|
| 4399 | current_user=admin, |
|
| 4400 | session=dbsession, |
|
| 4401 | config=self.app_config, |
|
| 4402 | ) |
|
| 4403 | gapi = GroupApi( |
|
| 4404 | current_user=admin, |
|
| 4405 | session=dbsession, |
|
| 4406 | config=self.app_config, |
|
| 4407 | ) |
|
| 4408 | groups = [gapi.get_one_with_name('users')] |
|
| 4409 | test_user = uapi.create_user( |
|
| 4410 | email='[email protected]', |
|
| 4411 | password='pass', |
|
| 4412 | name='bob', |
|
| 4413 | groups=groups, |
|
| 4414 | timezone='Europe/Paris', |
|
| 4415 | lang='fr', |
|
| 4416 | do_save=True, |
|
| 4417 | do_notify=False, |
|
| 4418 | ) |
|
| 4419 | uapi.save(test_user) |
|
| 4420 | transaction.commit() |
|
| 4421 | user_id = int(test_user.user_id) |
|
| 4422 | ||
| 4423 | self.testapp.authorization = ( |
|
| 4424 | 'Basic', |
|
| 4425 | ( |
|
| 4426 | '[email protected]', |
|
| 4427 | '[email protected]' |
|
| 4428 | ) |
|
| 4429 | ) |
|
| 4430 | # check before |
|
| 4431 | user = uapi.get_one(user_id) |
|
| 4432 | assert user.validate_password('pass') |
|
| 4433 | assert not user.validate_password('mynewpassword') |
|
| 4434 | # Set password |
|
| 4435 | params = { |
|
| 4436 | 'new_password': 'mynewpassword', |
|
| 4437 | 'new_password2': 'mynewpassword', |
|
| 4438 | 'loggedin_user_password': '[email protected]', |
|
| 4439 | } |
|
| 4440 | self.testapp.put_json( |
|
| 4441 | '/api/v2/users/{}/password'.format(user_id), |
|
| 4442 | params=params, |
|
| 4443 | status=204, |
|
| 4444 | ) |
|
| 4445 | # Check After |
|
| 4446 | dbsession = get_tm_session(self.session_factory, transaction.manager) |
|
| 4447 | uapi = UserApi( |
|
| 4448 | current_user=admin, |
|
| 4449 | session=dbsession, |
|
| 4450 | config=self.app_config, |
|
| 4451 | ) |
|
| 4452 | user = uapi.get_one(user_id) |
|
| 4453 | assert not user.validate_password('pass') |
|
| 4454 | assert user.validate_password('mynewpassword') |
|
| 4455 | ||
| 4456 | def test_api__set_user_password__err_403__admin_wrong_password(self): |
|
| 4457 | dbsession = get_tm_session(self.session_factory, transaction.manager) |
|
| @@ 1760-1821 (lines=62) @@ | ||
| 1757 | assert not user.validate_password('mynewpassword') |
|
| 1758 | assert not user.validate_password('mynewpassword2') |
|
| 1759 | ||
| 1760 | def test_api__set_account_password__ok_200__nominal(self): |
|
| 1761 | dbsession = get_tm_session(self.session_factory, transaction.manager) |
|
| 1762 | admin = dbsession.query(models.User) \ |
|
| 1763 | .filter(models.User.email == '[email protected]') \ |
|
| 1764 | .one() |
|
| 1765 | uapi = UserApi( |
|
| 1766 | current_user=admin, |
|
| 1767 | session=dbsession, |
|
| 1768 | config=self.app_config, |
|
| 1769 | ) |
|
| 1770 | gapi = GroupApi( |
|
| 1771 | current_user=admin, |
|
| 1772 | session=dbsession, |
|
| 1773 | config=self.app_config, |
|
| 1774 | ) |
|
| 1775 | groups = [gapi.get_one_with_name('users')] |
|
| 1776 | test_user = uapi.create_user( |
|
| 1777 | email='[email protected]', |
|
| 1778 | password='pass', |
|
| 1779 | name='bob', |
|
| 1780 | groups=groups, |
|
| 1781 | timezone='Europe/Paris', |
|
| 1782 | lang='fr', |
|
| 1783 | do_save=True, |
|
| 1784 | do_notify=False, |
|
| 1785 | ) |
|
| 1786 | uapi.save(test_user) |
|
| 1787 | transaction.commit() |
|
| 1788 | user_id = int(test_user.user_id) |
|
| 1789 | ||
| 1790 | self.testapp.authorization = ( |
|
| 1791 | 'Basic', |
|
| 1792 | ( |
|
| 1793 | '[email protected]', |
|
| 1794 | 'pass' |
|
| 1795 | ) |
|
| 1796 | ) |
|
| 1797 | # check before |
|
| 1798 | user = uapi.get_one(user_id) |
|
| 1799 | assert user.validate_password('pass') |
|
| 1800 | assert not user.validate_password('mynewpassword') |
|
| 1801 | # Set password |
|
| 1802 | params = { |
|
| 1803 | 'new_password': 'mynewpassword', |
|
| 1804 | 'new_password2': 'mynewpassword', |
|
| 1805 | 'loggedin_user_password': 'pass', |
|
| 1806 | } |
|
| 1807 | self.testapp.put_json( |
|
| 1808 | '/api/v2/users/me/password', |
|
| 1809 | params=params, |
|
| 1810 | status=204, |
|
| 1811 | ) |
|
| 1812 | # Check After |
|
| 1813 | dbsession = get_tm_session(self.session_factory, transaction.manager) |
|
| 1814 | uapi = UserApi( |
|
| 1815 | current_user=admin, |
|
| 1816 | session=dbsession, |
|
| 1817 | config=self.app_config, |
|
| 1818 | ) |
|
| 1819 | user = uapi.get_one(user_id) |
|
| 1820 | assert not user.validate_password('pass') |
|
| 1821 | assert user.validate_password('mynewpassword') |
|
| 1822 | ||
| 1823 | ||
| 1824 | ||