예제 #1
0
class TestMultipleAuthentication(TestCase):
    fixtures = fixture('user_2519')

    def setUp(self):
        self.resource = MarketplaceResource()
        self.profile = UserProfile.objects.get(pk=2519)

    def test_single(self):
        req = RequestFactory().get('/')
        req.COOKIES['user'] = ('[email protected],56b6f1a3dd735d962c56ce7d8f46e02ec'
                               '1d4748d2c00c407d75f0969d08bb9c68c31b3371aa8130'
                               '317815c89e5072e31bb94b4121c5c165f3515838d4d6c6'
                               '0c4,165d631d3c3045458b4516242dad7ae')
        self.resource._meta.authentication = (
                authentication.SharedSecretAuthentication())
        eq_(self.resource.is_authenticated(req), None)

    def test_multiple_passes(self):
        req = RequestFactory().get('/')
        req.user = AnonymousUser()
        self.resource._meta.authentication = (
                authentication.SharedSecretAuthentication(),
                # Optional auth passes because there are not auth headers.
                authentication.OptionalOAuthAuthentication())

        eq_(self.resource.is_authenticated(req), None)

    def test_multiple_fails(self):
        client = OAuthClient(Mock(key='foo', secret='bar'))
        req = RequestFactory().get('/',
                HTTP_HOST='api',
                HTTP_AUTHORIZATION=client.header('GET', 'http://foo/'))
        req.user = AnonymousUser()
        next_auth = Mock()
        self.resource._meta.authentication = (
                # OAuth fails because there are bogus auth headers.
                authentication.OAuthAuthentication(),
                next_auth)

        with self.assertRaises(ImmediateHttpResponse):
            eq_(self.resource.is_authenticated(req), None)
        # This never even got called.
        ok_(not next_auth.is_authenticated.called)
예제 #2
0
class TestMultipleAuthentication(TestCase):
    fixtures = fixture('user_2519')

    def setUp(self):
        self.resource = MarketplaceResource()
        self.profile = UserProfile.objects.get(pk=2519)

    def test_single(self):
        req = RequestFactory().get('/')
        req.user = self.profile.user
        self.resource._meta.authentication = (
                authentication.SessionAuthentication())
        eq_(self.resource.is_authenticated(req), None)

    def test_multiple_passes(self):
        req = RequestFactory().get('/')
        req.user = AnonymousUser()
        self.resource._meta.authentication = (
                authentication.SessionAuthentication(),
                # Optional auth passes because there are not auth headers.
                authentication.OptionalOAuthAuthentication())

        eq_(self.resource.is_authenticated(req), None)

    def test_multiple_fails(self):
        client = OAuthClient(Mock(key='foo', secret='bar'))
        req = RequestFactory().get('/',
                HTTP_HOST='api',
                HTTP_AUTHORIZATION=client.header('GET', 'http://foo/'))
        req.user = AnonymousUser()
        next_auth = Mock()
        self.resource._meta.authentication = (
                # OAuth fails because there are bogus auth headers.
                authentication.OAuthAuthentication(),
                next_auth)

        with self.assertRaises(ImmediateHttpResponse):
            eq_(self.resource.is_authenticated(req), None)
        # This never even got called.
        ok_(not next_auth.is_authenticated.called)