feat(rpc): support jsonp callbacks

This change introduces alternate rendering of text/javascript
JSONP-compatible callback content. The `examples/jsonp.html`
HTML document can be used to test this functionality against
a running aurweb server.

Signed-off-by: Kevin Morris <kevr@0cost.org>
This commit is contained in:
Kevin Morris 2021-10-31 00:28:55 -07:00
parent 05e6cfca62
commit 12b4269ba8
No known key found for this signature in database
GPG key ID: F7E46DED420788F3
3 changed files with 107 additions and 7 deletions

View file

@ -1,3 +1,5 @@
import re
from http import HTTPStatus
from unittest import mock
@ -610,3 +612,15 @@ def test_rpc_search_checkdepends():
def test_rpc_incorrect_by():
response = make_request("/rpc?v=5&type=search&by=fake&arg=big")
assert response.json().get("error") == "Incorrect by field specified."
def test_rpc_jsonp_callback():
""" Test the callback parameter.
For end-to-end verification, the `examples/jsonp.html` file can be
used to submit jsonp callback requests to the RPC.
"""
response = make_request(
"/rpc?v=5&type=search&arg=big&callback=jsonCallback")
assert response.headers.get("content-type") == "text/javascript"
assert re.search(r'^/\*\*/jsonCallback\(.*\)$', response.text) is not None