Merged in [19344] from krathnayake@ietf.org:
Implements /api/appauth/authortools API endpoint. Fixes #3396.
- Legacy-Id: 19364
Note: SVN reference [19344] has been migrated to Git commit dc833aa85c
This commit is contained in:
commit
766a4638b2
|
@ -355,7 +355,6 @@ class CustomApiTests(TestCase):
|
|||
missing_fields = [ f.strip() for f in fields.split(',') ]
|
||||
self.assertEqual(set(missing_fields), set(drop_fields))
|
||||
|
||||
|
||||
def test_api_version(self):
|
||||
url = urlreverse('ietf.api.views.version')
|
||||
r = self.client.get(url)
|
||||
|
@ -363,6 +362,29 @@ class CustomApiTests(TestCase):
|
|||
self.assertEqual(data['version'], ietf.__version__+ietf.__patch__)
|
||||
self.assertIn(data['date'], ietf.__date__)
|
||||
|
||||
def test_api_appauth_authortools(self):
|
||||
url = urlreverse('ietf.api.views.author_tools')
|
||||
person = PersonFactory()
|
||||
apikey = PersonalApiKey.objects.create(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)
|
||||
|
||||
|
||||
class TastypieApiTestCase(ResourceTestCaseMixin, TestCase):
|
||||
def __init__(self, *args, **kwargs):
|
||||
|
|
|
@ -40,6 +40,8 @@ urlpatterns = [
|
|||
url(r'^submit/?$', submit_views.api_submit),
|
||||
# Datatracker version
|
||||
url(r'^version/?$', api_views.version),
|
||||
# Authtools API key
|
||||
url(r'^appauth/authortools', api_views.author_tools),
|
||||
]
|
||||
|
||||
# Additional (standard) Tastypie endpoints
|
||||
|
|
|
@ -215,3 +215,10 @@ def version(request):
|
|||
content_type='application/json',
|
||||
)
|
||||
|
||||
|
||||
@require_api_key
|
||||
@csrf_exempt
|
||||
def author_tools(request):
|
||||
return HttpResponse(
|
||||
json.dumps({'success': True}),
|
||||
content_type='application/json')
|
||||
|
|
|
@ -368,6 +368,7 @@ PERSON_API_KEY_VALUES = [
|
|||
("/api/meeting/session/video/url", "/api/meeting/session/video/url", "Recording Manager"),
|
||||
("/api/notify/meeting/registration", "/api/notify/meeting/registration", "Robot"),
|
||||
("/api/notify/meeting/bluesheet", "/api/notify/meeting/bluesheet", "Recording Manager"),
|
||||
("/api/appauth/authortools", "/api/appauth/authortools", None),
|
||||
]
|
||||
PERSON_API_KEY_ENDPOINTS = sorted(list(set([ (v, n) for (v, n, r) in PERSON_API_KEY_VALUES ])))
|
||||
|
||||
|
|
Loading…
Reference in a new issue