diff --git a/ietf/api/tests.py b/ietf/api/tests.py index 0699d438b0..74a220b40b 100644 --- a/ietf/api/tests.py +++ b/ietf/api/tests.py @@ -945,28 +945,30 @@ def test_api_version(self): def test_api_appauth(self): - url = urlreverse('ietf.api.views.app_auth') - person = PersonFactory() - apikey = PersonalApiKeyFactory(endpoint=url, person=person) - - self.client.login(username=person.user.username,password=f'{person.user.username}+password') - self.client.logout() - - # error cases - # missing apikey - r = self.client.post(url, {}) - self.assertContains(r, 'Missing apikey parameter', status_code=400) - - # invalid apikey - r = self.client.post(url, {'apikey': 'foobar'}) - self.assertContains(r, 'Invalid apikey', status_code=403) - - # working case - r = self.client.post(url, {'apikey': apikey.hash()}) - self.assertEqual(r.status_code, 200) - jsondata = r.json() - self.assertEqual(jsondata['success'], True) + for app in ["authortools", "bibxml"]: + url = urlreverse('ietf.api.views.app_auth', kwargs={"app": app}) + person = PersonFactory() + apikey = PersonalApiKeyFactory(endpoint=url, person=person) + self.client.login(username=person.user.username,password=f'{person.user.username}+password') + self.client.logout() + + # error cases + # missing apikey + r = self.client.post(url, {}) + self.assertContains(r, 'Missing apikey parameter', status_code=400) + + # invalid apikey + r = self.client.post(url, {'apikey': 'foobar'}) + self.assertContains(r, 'Invalid apikey', status_code=403) + + # working case + r = self.client.post(url, {'apikey': apikey.hash()}) + self.assertEqual(r.status_code, 200) + jsondata = r.json() + self.assertEqual(jsondata['success'], True) + self.client.logout() + def test_api_get_session_matherials_no_agenda_meeting_url(self): meeting = MeetingFactory(type_id='ietf') session = SessionFactory(meeting=meeting) diff --git a/ietf/ietfauth/tests.py b/ietf/ietfauth/tests.py index 722c1e8b6f..ef98ec11f7 100644 --- a/ietf/ietfauth/tests.py +++ b/ietf/ietfauth/tests.py @@ -788,7 +788,7 @@ def test_apikey_errors(self): self.assertContains(r, 'Invalid apikey', status_code=403) # invalid apikey (invalidated api key) - unauthorized_url = urlreverse('ietf.api.views.app_auth') + unauthorized_url = urlreverse('ietf.api.views.app_auth', kwargs={'app': 'authortools'}) invalidated_apikey = PersonalApiKey.objects.create( endpoint=unauthorized_url, person=person, valid=False) r = self.client.post(unauthorized_url, {'apikey': invalidated_apikey.hash()}) diff --git a/ietf/person/factories.py b/ietf/person/factories.py index e91aafeff9..71f7e12d57 100644 --- a/ietf/person/factories.py +++ b/ietf/person/factories.py @@ -158,7 +158,7 @@ class Meta: class PersonalApiKeyFactory(factory.django.DjangoModelFactory): person = factory.SubFactory(PersonFactory) - endpoint = FuzzyChoice(PERSON_API_KEY_ENDPOINTS) + endpoint = FuzzyChoice(v for v, n in PERSON_API_KEY_ENDPOINTS) class Meta: model = PersonalApiKey