| @@ 4456-4520 (lines=65) @@ | ||
| 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) |
|
| 4458 | admin = dbsession.query(models.User) \ |
|
| 4459 | .filter(models.User.email == '[email protected]') \ |
|
| 4460 | .one() |
|
| 4461 | uapi = UserApi( |
|
| 4462 | current_user=admin, |
|
| 4463 | session=dbsession, |
|
| 4464 | config=self.app_config, |
|
| 4465 | ) |
|
| 4466 | gapi = GroupApi( |
|
| 4467 | current_user=admin, |
|
| 4468 | session=dbsession, |
|
| 4469 | config=self.app_config, |
|
| 4470 | ) |
|
| 4471 | groups = [gapi.get_one_with_name('users')] |
|
| 4472 | test_user = uapi.create_user( |
|
| 4473 | email='[email protected]', |
|
| 4474 | password='pass', |
|
| 4475 | name='bob', |
|
| 4476 | groups=groups, |
|
| 4477 | timezone='Europe/Paris', |
|
| 4478 | lang='fr', |
|
| 4479 | do_save=True, |
|
| 4480 | do_notify=False, |
|
| 4481 | ) |
|
| 4482 | uapi.save(test_user) |
|
| 4483 | transaction.commit() |
|
| 4484 | user_id = int(test_user.user_id) |
|
| 4485 | ||
| 4486 | self.testapp.authorization = ( |
|
| 4487 | 'Basic', |
|
| 4488 | ( |
|
| 4489 | '[email protected]', |
|
| 4490 | '[email protected]' |
|
| 4491 | ) |
|
| 4492 | ) |
|
| 4493 | # check before |
|
| 4494 | user = uapi.get_one(user_id) |
|
| 4495 | assert user.validate_password('pass') |
|
| 4496 | assert not user.validate_password('mynewpassword') |
|
| 4497 | # Set password |
|
| 4498 | params = { |
|
| 4499 | 'new_password': 'mynewpassword', |
|
| 4500 | 'new_password2': 'mynewpassword', |
|
| 4501 | 'loggedin_user_password': 'wrongpassword', |
|
| 4502 | } |
|
| 4503 | res = self.testapp.put_json( |
|
| 4504 | '/api/v2/users/{}/password'.format(user_id), |
|
| 4505 | params=params, |
|
| 4506 | status=403, |
|
| 4507 | ) |
|
| 4508 | assert res.json_body |
|
| 4509 | assert 'code' in res.json_body |
|
| 4510 | assert res.json_body['code'] == error.WRONG_USER_PASSWORD |
|
| 4511 | dbsession = get_tm_session(self.session_factory, transaction.manager) |
|
| 4512 | uapi = UserApi( |
|
| 4513 | current_user=admin, |
|
| 4514 | session=dbsession, |
|
| 4515 | config=self.app_config, |
|
| 4516 | ) |
|
| 4517 | # Check After |
|
| 4518 | user = uapi.get_one(user_id) |
|
| 4519 | assert user.validate_password('pass') |
|
| 4520 | assert not user.validate_password('mynewpassword') |
|
| 4521 | ||
| 4522 | def test_api__set_user_password__err_400__admin_passwords_do_not_match(self): # nopep8 |
|
| 4523 | dbsession = get_tm_session(self.session_factory, transaction.manager) |
|
| @@ 1626-1690 (lines=65) @@ | ||
| 1623 | """ |
|
| 1624 | fixtures = [BaseFixture] |
|
| 1625 | ||
| 1626 | def test_api__set_account_password__err_403__admin_wrong_password(self): |
|
| 1627 | dbsession = get_tm_session(self.session_factory, transaction.manager) |
|
| 1628 | admin = dbsession.query(models.User) \ |
|
| 1629 | .filter(models.User.email == '[email protected]') \ |
|
| 1630 | .one() |
|
| 1631 | uapi = UserApi( |
|
| 1632 | current_user=admin, |
|
| 1633 | session=dbsession, |
|
| 1634 | config=self.app_config, |
|
| 1635 | ) |
|
| 1636 | gapi = GroupApi( |
|
| 1637 | current_user=admin, |
|
| 1638 | session=dbsession, |
|
| 1639 | config=self.app_config, |
|
| 1640 | ) |
|
| 1641 | groups = [gapi.get_one_with_name('users')] |
|
| 1642 | test_user = uapi.create_user( |
|
| 1643 | email='[email protected]', |
|
| 1644 | password='pass', |
|
| 1645 | name='bob', |
|
| 1646 | groups=groups, |
|
| 1647 | timezone='Europe/Paris', |
|
| 1648 | lang='fr', |
|
| 1649 | do_save=True, |
|
| 1650 | do_notify=False, |
|
| 1651 | ) |
|
| 1652 | uapi.save(test_user) |
|
| 1653 | transaction.commit() |
|
| 1654 | user_id = int(test_user.user_id) |
|
| 1655 | ||
| 1656 | self.testapp.authorization = ( |
|
| 1657 | 'Basic', |
|
| 1658 | ( |
|
| 1659 | '[email protected]', |
|
| 1660 | '[email protected]' |
|
| 1661 | ) |
|
| 1662 | ) |
|
| 1663 | # check before |
|
| 1664 | user = uapi.get_one(user_id) |
|
| 1665 | assert user.validate_password('pass') |
|
| 1666 | assert not user.validate_password('mynewpassword') |
|
| 1667 | # Set password |
|
| 1668 | params = { |
|
| 1669 | 'new_password': 'mynewpassword', |
|
| 1670 | 'new_password2': 'mynewpassword', |
|
| 1671 | 'loggedin_user_password': 'wrongpassword', |
|
| 1672 | } |
|
| 1673 | res = self.testapp.put_json( |
|
| 1674 | '/api/v2/users/me/password', |
|
| 1675 | params=params, |
|
| 1676 | status=403, |
|
| 1677 | ) |
|
| 1678 | assert res.json_body |
|
| 1679 | assert 'code' in res.json_body |
|
| 1680 | assert res.json_body['code'] == error.WRONG_USER_PASSWORD |
|
| 1681 | dbsession = get_tm_session(self.session_factory, transaction.manager) |
|
| 1682 | uapi = UserApi( |
|
| 1683 | current_user=admin, |
|
| 1684 | session=dbsession, |
|
| 1685 | config=self.app_config, |
|
| 1686 | ) |
|
| 1687 | # Check After |
|
| 1688 | user = uapi.get_one(user_id) |
|
| 1689 | assert user.validate_password('pass') |
|
| 1690 | assert not user.validate_password('mynewpassword') |
|
| 1691 | ||
| 1692 | def test_api__set_account_password__err_400__admin_passwords_do_not_match(self): # nopep8 |
|
| 1693 | dbsession = get_tm_session(self.session_factory, transaction.manager) |
|