Commit 0cb6b158 authored by Daniel Kastl's avatar Daniel Kastl Committed by Ken Zangelin
Browse files

fix(httpctrl): match stub query parameters after decoding them

Since !311, D017_01_inc stubs a DELETE with a query:

  DELETE /ngsi-ld/v1/entities?type=Vehicle&id=${entity_id}

For requests other than GET, the mock compares the stub with the request
path only. This is never true for a stub with a query. Then the mock
compares the full URLs as plain text. A broker that sends the id
percent-encoded (id=urn%3Angsi-ld%3AVehicle%3A...) never matches, although
it is the same query. The suite's own client also sends the encoded form.
The mock does not answer, and the test fails.

Compare the path and the decoded parameters instead. The order of the
parameters no longer matters. A stub without a query works as before.
parent 52837277
Loading
Loading
Loading
Loading
+12 −0
Changes for libraries/robotframework-httpctrl/src/HttpCtrl/http_stub.py: 12 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -147,6 +147,18 @@ class HttpStubContainer(metaclass=Singleton):
            
            # if the method is not GET, we should ignore parameters and check if the url is the same
            else:
                # The stub has a query, for example D017_01_inc:
                #   DELETE /entities?type=Vehicle&id=...
                # The check below compares the stub with the request path only, so it
                # is never true for such a stub. Then the full URLs are compared as
                # plain text, and a percent-encoded id (id=urn%3Angsi-ld%3A...) never
                # matches id=urn:ngsi-ld:... Both are the same query, so compare the
                # decoded parameters.
                stub_path, _, stub_query = stub.criteria.url.partition('?')
                if stub_query and \
                        stub_path.rstrip("/") == criteria_url_components[0].rstrip("/") and \
                        parse_qs(stub_query) == parse_qs(criteria_url_components[1]):
                    return True
                if stub.criteria.url.rstrip("/") == criteria_url_components[0].rstrip("/"):
                    # if the request is a query via POST, we should have a specific check
                    if stub.criteria.url == "/ngsi-ld/v1/entityoperations/query":