Revize ed55c677
Přidáno uživatelem Jan Pašek před asi 4 roky(ů)
src/controllers/certificates_controller.py | ||
---|---|---|
1 |
import json |
|
1 | 2 |
from datetime import datetime |
2 | 3 |
from itertools import chain |
3 | 4 |
from flask import request |
... | ... | |
214 | 215 |
CertController.setup() # TODO remove after issue fixed |
215 | 216 |
|
216 | 217 |
targets = {ROOT_CA_ID, INTERMEDIATE_CA_ID, CERTIFICATE_ID} # all targets |
217 |
if request.is_json: # if the request carries JSON data |
|
218 |
data = request.get_json() # get it |
|
218 |
|
|
219 |
# the filtering parameter can be read as URL argument or as a request body |
|
220 |
if request.is_json or "filtering" in request.args.keys(): # if the request carries JSON data |
|
221 |
if request.is_json: |
|
222 |
data = request.get_json() # get it |
|
223 |
else: |
|
224 |
data = {"filtering": json.loads(request.args["filtering"])} |
|
219 | 225 |
if FILTERING in data: # if the 'filtering' field exists |
220 | 226 |
if isinstance(data[FILTERING], dict): # and it is also a 'dict' |
221 | 227 |
if CA in data[FILTERING]: # containing 'CA' |
tests/integration_tests/rest_api/certificates_test.py | ||
---|---|---|
345 | 345 |
|
346 | 346 |
|
347 | 347 |
def test_filtering(server): |
348 |
ret = server.get("/api/certificates?filtering=%7B%22CA%22:true%7D") |
|
349 |
|
|
350 |
assert ret.status_code == 200 |
|
351 |
|
|
352 |
assert "data" in ret.json |
|
353 |
assert "success" in ret.json |
|
354 |
assert ret.json["success"] |
|
355 |
|
|
356 |
d = ret.json["data"] |
|
357 |
|
|
358 |
assert all(c["usage"]["CA"] for c in d) |
|
359 |
|
|
348 | 360 |
ret = server.get("/api/certificates", json={"filtering": {"CA": True}}) |
349 | 361 |
|
350 | 362 |
assert ret.status_code == 200 |
Také k dispozici: Unified diff
Re #8475 - Fixed minor bug in GET /api/certificates endpoint with filtering