async def _(): user = User( id=10, email="*****@*****.**", date_joined=datetime.now(timezone.utc), is_active=False, ) with raises(UserIsNotActiveError): await reset_password( ResetPasswordInput(token=user.create_reset_password_token(), new_password="******"), repository=FakeUsersRepository([user]), )
async def _(): user = User( id=10, email="*****@*****.**", date_joined=datetime.now(timezone.utc), password="******", is_active=True, jwt_auth_id=1, ) token = user.create_reset_password_token() user.jwt_auth_id = 2 with raises(ResetPasswordTokenInvalidError): await reset_password( ResetPasswordInput(token=token, new_password="******"), repository=FakeUsersRepository([user]), )
async def request_reset_password(user: User): if not user.is_active: logger.info( "Trying to request reset password of not active user_id=%s", user.id) raise UserIsNotActiveError() token = user.create_reset_password_token() send_email( template=EmailTemplate.RESET_PASSWORD, to=user.email, subject="Reset your password", variables={ "firstname": user.name, # "resetpasswordlink": f"{ASSOCIATION_FRONTEND_URL}/reset-password/{token}", "resetpasswordlink": f"https://pycon.it/en/reset-password/{token}", }, ) logger.info("Sent reset password token of user_id=%s", user.id)
async def _(): user = User( id=10, email="*****@*****.**", date_joined=datetime.now(timezone.utc), password="******", is_active=True, jwt_auth_id=1, ) with time_machine.travel("2020-10-10 10:10:10Z", tick=False): token = user.create_reset_password_token() with time_machine.travel( "2020-10-10 15:10:10Z", tick=False), raises(ResetPasswordTokenExpiredError): await reset_password( ResetPasswordInput(token=token, new_password="******"), repository=FakeUsersRepository([user]), )
async def _(): user = User( id=50, email="*****@*****.**", date_joined=datetime.now(timezone.utc), jwt_auth_id=1, ) with time_machine.travel("2020-10-10 10:10:10Z", tick=False): token = user.create_reset_password_token() decoded_token = jwt.decode( token, str(SECRET_KEY), audience="users/reset-password", issuer="users", algorithms=["HS256"], ) assert decoded_token["user_id"] == 50 assert decoded_token["jti"] == "reset-password:50:1"
async def _(): user = User( id=10, email="*****@*****.**", date_joined=datetime.now(timezone.utc), password="******", is_active=True, jwt_auth_id=1, ) await reset_password( ResetPasswordInput(token=user.create_reset_password_token(), new_password="******"), repository=FakeUsersRepository([user]), ) assert user.new_password == "testnewpassword" # we did column + 1 so the value updated in the DB and not python assert user.jwt_auth_id.left.name == "jwt_auth_id" assert user.jwt_auth_id.right.value == 1