Skip to content

Commit 766a463

Browse files
committed
Merged in [19344] from krathnayake@ietf.org:
Implements /api/appauth/authortools API endpoint. Fixes ietf-tools#3396. - Legacy-Id: 19364 Note: SVN reference [19344] has been migrated to Git commit dc833aa
2 parents b531a5c + dc833aa commit 766a463

4 files changed

Lines changed: 33 additions & 1 deletion

File tree

ietf/api/tests.py

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -355,14 +355,36 @@ def test_api_new_meeting_registration(self):
355355
missing_fields = [ f.strip() for f in fields.split(',') ]
356356
self.assertEqual(set(missing_fields), set(drop_fields))
357357

358-
359358
def test_api_version(self):
360359
url = urlreverse('ietf.api.views.version')
361360
r = self.client.get(url)
362361
data = r.json()
363362
self.assertEqual(data['version'], ietf.__version__+ietf.__patch__)
364363
self.assertIn(data['date'], ietf.__date__)
365364

365+
def test_api_appauth_authortools(self):
366+
url = urlreverse('ietf.api.views.author_tools')
367+
person = PersonFactory()
368+
apikey = PersonalApiKey.objects.create(endpoint=url, person=person)
369+
370+
self.client.login(username=person.user.username,password=f'{person.user.username}+password')
371+
self.client.logout()
372+
373+
# error cases
374+
# missing apikey
375+
r = self.client.post(url, {})
376+
self.assertContains(r, 'Missing apikey parameter', status_code=400)
377+
378+
# invalid apikey
379+
r = self.client.post(url, {'apikey': 'foobar'})
380+
self.assertContains(r, 'Invalid apikey', status_code=403)
381+
382+
# working case
383+
r = self.client.post(url, {'apikey': apikey.hash()})
384+
self.assertEqual(r.status_code, 200)
385+
jsondata = r.json()
386+
self.assertEqual(jsondata['success'], True)
387+
366388

367389
class TastypieApiTestCase(ResourceTestCaseMixin, TestCase):
368390
def __init__(self, *args, **kwargs):

ietf/api/urls.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@
4040
url(r'^submit/?$', submit_views.api_submit),
4141
# Datatracker version
4242
url(r'^version/?$', api_views.version),
43+
# Authtools API key
44+
url(r'^appauth/authortools', api_views.author_tools),
4345
]
4446

4547
# Additional (standard) Tastypie endpoints

ietf/api/views.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,3 +215,10 @@ def version(request):
215215
content_type='application/json',
216216
)
217217

218+
219+
@require_api_key
220+
@csrf_exempt
221+
def author_tools(request):
222+
return HttpResponse(
223+
json.dumps({'success': True}),
224+
content_type='application/json')

ietf/person/models.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -368,6 +368,7 @@ def salt():
368368
("/api/meeting/session/video/url", "/api/meeting/session/video/url", "Recording Manager"),
369369
("/api/notify/meeting/registration", "/api/notify/meeting/registration", "Robot"),
370370
("/api/notify/meeting/bluesheet", "/api/notify/meeting/bluesheet", "Recording Manager"),
371+
("/api/appauth/authortools", "/api/appauth/authortools", None),
371372
]
372373
PERSON_API_KEY_ENDPOINTS = sorted(list(set([ (v, n) for (v, n, r) in PERSON_API_KEY_VALUES ])))
373374

0 commit comments

Comments
 (0)