Skip to content

Test case for issue #4033 #4034

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 23 additions & 1 deletion tests/test_authentication.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@
import base64

from django.conf.urls import include, url
from django.contrib.auth.models import User
from django.contrib.auth.models import AnonymousUser, User
from django.db import models
from django.http import HttpResponse
from django.test import TestCase
from django.utils import six

import pytest

from rest_framework import (
HTTP_HEADER_ENCODING, exceptions, permissions, renderers, status
)
Expand Down Expand Up @@ -265,6 +267,26 @@ class CustomTokenAuthTests(BaseTokenAuthTests, TestCase):
path = '/customtoken/'


class AttributeErrorInAuthenticateTests(TestCase):
def test_incorrect_credentials(self):
"""
Make sure AttributeErrors thrown in .authenticate() are not suppressed.
"""
class AttributeErrorThrowingAuth(BaseAuthentication):
def authenticate(self, request):
raise AttributeError('This exception should crash the authentication')

request = factory.get('/')
request.user = AnonymousUser()
view = MockView.as_view(
authentication_classes=(AttributeErrorThrowingAuth,),
permission_classes=()
)

with pytest.raises(AttributeError):
view(request)


class IncorrectCredentialsTests(TestCase):
def test_incorrect_credentials(self):
"""
Expand Down