From d7af568cb67a0c6e6e18748785c37bb97efce65b Mon Sep 17 00:00:00 2001 From: Tanner Prestegard <tanner.prestegard@ligo.org> Date: Tue, 26 Feb 2019 10:46:33 -0600 Subject: [PATCH] Fix API authentication unit tests --- gracedb/api/tests/test_authentication.py | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/gracedb/api/tests/test_authentication.py b/gracedb/api/tests/test_authentication.py index 953463380..0b8497e3f 100644 --- a/gracedb/api/tests/test_authentication.py +++ b/gracedb/api/tests/test_authentication.py @@ -1,4 +1,5 @@ from base64 import b64encode +import mock from django.conf import settings from django.urls import reverse @@ -88,6 +89,18 @@ class TestGraceDbBasicAuthentication(GraceDbApiTestBase): class TestGraceDbX509Authentication(GraceDbApiTestBase): """Test X509 certificate auth backend for API in full auth cycle""" + def setUp(self): + super(TestGraceDbX509Authentication, self).setUp() + # Patch auth classes to make sure the right one is active + self.auth_patcher = mock.patch( + 'rest_framework.views.APIView.get_authenticators', + return_value=[GraceDbX509Authentication(),]) + self.auth_patcher.start() + + def tearDown(self): + super(TestGraceDbX509Authentication, self).tearDown() + self.auth_patcher.stop() + @classmethod def setUpTestData(cls): super(TestGraceDbX509Authentication, cls).setUpTestData() @@ -126,7 +139,7 @@ class TestGraceDbX509Authentication(GraceDbApiTestBase): response = self.client.get(url, data=None, **headers) # Check response - self.assertEqual(response.status_code, 403) + self.assertEqual(response.status_code, 401) self.assertIn("Invalid certificate subject", response.content) def test_inactive_user_authenticate(self): @@ -143,7 +156,7 @@ class TestGraceDbX509Authentication(GraceDbApiTestBase): response = self.client.get(url, data=None, **headers) # Check response - self.assertEqual(response.status_code, 403) + self.assertEqual(response.status_code, 401) self.assertIn("User inactive or deleted", response.content) def test_authenticate_cert_with_proxy(self): -- GitLab