Skip to content

Commit dc833aa

Browse files
committed
Implements /api/appauth/authortools API endpoint. Fixes ietf-tools#3396. Commit ready for merge.
- Legacy-Id: 19344
1 parent a9ad04c commit dc833aa

File tree

4 files changed

+30
-1
lines changed

4 files changed

+30
-1
lines changed

ietf/api/tests.py

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -355,14 +355,33 @@ 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+
# error cases
371+
# missing apikey
372+
r = self.client.post(url, {})
373+
self.assertContains(r, 'Missing apikey parameter', status_code=400)
374+
375+
# invalid apikey
376+
r = self.client.post(url, {'apikey': 'foobar'})
377+
self.assertContains(r, 'Invalid apikey', status_code=403)
378+
379+
# working case
380+
r = self.client.post(url, {'apikey': apikey.hash()})
381+
self.assertEqual(r.status_code, 200)
382+
jsondata = r.json()
383+
self.assertEqual(data['success'], True)
384+
366385

367386
class TastypieApiTestCase(ResourceTestCaseMixin, TestCase):
368387
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)