def test_send_reset_password_email(data_fixture, mailoutbox): user = data_fixture.create_user(email='test@localhost') handler = UserHandler() signer = handler.get_reset_password_signer() handler.send_reset_password_email(user, 'http://localhost/reset-password') assert len(mailoutbox) == 1 email = mailoutbox[0] assert email.subject == 'Reset password' assert email.from_email == 'no-reply@localhost' assert 'test@localhost' in email.to html_body = email.alternatives[0][0] search_url = 'http://localhost/reset-password/' start_url_index = html_body.index(search_url) assert start_url_index != -1 end_url_index = html_body.index('"', start_url_index) token = html_body[start_url_index + len(search_url):end_url_index] user_id = signer.loads(token) assert user_id == user.id
def test_send_reset_password_email(data_fixture, mailoutbox): user = data_fixture.create_user(email="test@localhost") handler = UserHandler() with pytest.raises(BaseURLHostnameNotAllowed): handler.send_reset_password_email(user, "http://test.nl/reset-password") signer = handler.get_reset_password_signer() handler.send_reset_password_email(user, "http://*****:*****@localhost" assert "test@localhost" in email.to html_body = email.alternatives[0][0] search_url = "http://localhost:3000/reset-password/" start_url_index = html_body.index(search_url) assert start_url_index != -1 end_url_index = html_body.index('"', start_url_index) token = html_body[start_url_index + len(search_url):end_url_index] user_id = signer.loads(token) assert user_id == user.id
def post(self, request, data): """ If the email is found, an email containing the password reset link is send to the user. """ handler = UserHandler() try: user = handler.get_user(email=data["email"]) handler.send_reset_password_email(user, data["base_url"]) except UserNotFound: pass return Response("", status=204)