~maxiberta/canonical-identity-provider/vanilla-sshkeys-debug

« back to all changes in this revision

Viewing changes to src/api/v20/tests/test_handlers.py

  • Committer: Ubuntu One Auto Copilot
  • Author(s): Jonathan Hartley
  • Date: 2020-01-10 16:30:33 UTC
  • mfrom: (1703.1.18 canonical-identity-provider)
  • Revision ID: otto-copilot@canonical.com-20200110163033-px4ucyt3160acrar
Remove code that cannot be reached.

The containing 'if not account.can_reset_password',
16 lines up from the deletion,
does not check whether there are any validated email addresses.
Instead it just checks that account.status must be either
Suspended or Deleted.

Suspended accounts are handled by an early return,
9 lines up from the deletion.

Deleted accounts also delete their associated email addresses,
so can not be retrieved by the Account.get_by_email call
near the start of this method.

There was a test for this deleted code,
but it monkey patched a fake value to make this code reachable.
I tried replacing the test with one that didn't do monkey patching
(e.g. using a deleted account would be the only way)
but was unable to make the code reachable.

In practice, accounts with no validated email addresses pass
right by this code, and end up reading from account.preferredemail,
14 lines below the deletion,
which falls back to using a new email address.

Merged from https://code.launchpad.net/~tartley/canonical-identity-provider/rm-no-verified-address-para/+merge/377382

Show diffs side-by-side

added added

removed removed

Lines of Context:
1772
1772
        self.mock_logger.debug("PasswordResetTokenHandler.create: email was "
1773
1773
                               "not sent out because %s" % condition)
1774
1774
 
1775
 
    def test_can_not_reset_password(self):
1776
 
        name = 'identityprovider.models.account.Account.can_reset_password'
1777
 
        with patch(name, False):
1778
 
            content = self.do_post(data=self.data, status_code=403)
1779
 
 
1780
 
        self.assertEqual(content, {
1781
 
            'message': 'Can not reset password. Please contact login support',
1782
 
            'code': 'CAN_NOT_RESET_PASSWORD',
1783
 
            'extra': {}})
1784
 
 
1785
 
        condition = "account '%s' is not active" % self.account.displayname
1786
 
        self.mock_logger.debug("PasswordResetTokenHandler.create: email was "
1787
 
                               "not sent out because %s" % condition)
1788
 
 
1789
1775
    def assert_email_used(self, result, expected_email):
1790
1776
        # Then the response contains the user's stored email.
1791
1777
        self.assertEqual(result['email'], expected_email)