This commit is contained in:
Magnus Staberg 2016-05-03 03:46:49 +00:00
commit 38683d304c

View File

@ -5,12 +5,14 @@ from __future__ import unicode_literals
import base64 import base64
from django.conf.urls import include, url 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.db import models
from django.http import HttpResponse from django.http import HttpResponse
from django.test import TestCase from django.test import TestCase
from django.utils import six from django.utils import six
import pytest
from rest_framework import ( from rest_framework import (
HTTP_HEADER_ENCODING, exceptions, permissions, renderers, status HTTP_HEADER_ENCODING, exceptions, permissions, renderers, status
) )
@ -265,6 +267,26 @@ class CustomTokenAuthTests(BaseTokenAuthTests, TestCase):
path = '/customtoken/' 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): class IncorrectCredentialsTests(TestCase):
def test_incorrect_credentials(self): def test_incorrect_credentials(self):
""" """