def _authenticate_token(username: str, token: str) -> Tuple[model.User, model.UserToken]: ''' Try to authenticate user. Throw AuthError for invalid users. ''' user = users.get_user_by_name(username) user_token = user_tokens.get_by_user_and_token(user, token) if not auth.is_valid_token(user_token): raise errors.AuthError('잘못된 토큰입니다.') return user, user_token
def _authenticate_token( username: str, token: str) -> Tuple[model.User, model.UserToken]: ''' Try to authenticate user. Throw AuthError for invalid users. ''' user = users.get_user_by_name(username) user_token = user_tokens.get_by_user_and_token(user, token) if not auth.is_valid_token(user_token): raise errors.AuthError('Invalid token.') return user, user_token
def test_expired_token_is_invalid(user_token_factory): past_expiration = (datetime.utcnow() - timedelta(minutes=30)) user_token = user_token_factory(expiration_time=past_expiration) assert not auth.is_valid_token(user_token)
def test_disabled_token_is_invalid(user_token_factory): user_token = user_token_factory(enabled=False) assert not auth.is_valid_token(user_token)
def test_is_valid_token(user_token_factory): user_token = user_token_factory() assert auth.is_valid_token(user_token)