From 3c0b22417885f25f10964204251de42fcf82a3ba Mon Sep 17 00:00:00 2001 From: Robin Mackaij Date: Fri, 12 Apr 2024 12:25:45 +0000 Subject: [PATCH 1/2] Test Forbidden keyword added --- src/OpenApiDriver/openapi_executors.py | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/src/OpenApiDriver/openapi_executors.py b/src/OpenApiDriver/openapi_executors.py index 50c620c..9b5d137 100644 --- a/src/OpenApiDriver/openapi_executors.py +++ b/src/OpenApiDriver/openapi_executors.py @@ -109,7 +109,29 @@ def test_unauthorized(self, path: str, method: str) -> None: url=url, verify=False, ) - assert response.status_code == 401 + if response.status_code != 401: + raise AssertionError( + f"Response {response.status_code} was not 401." + ) + + @keyword + def test_forbidden(self, path: str, method: str) -> None: + """ + Perform a request for `method` on the `path`, with the provided authorization. + + This keyword only passes if the response code is 403: Forbidden. + + For this keyword to pass, the authorization parameters used to initialize the + library should grant insufficient access rights to the target endpoint. + > Note: No headers or (json) body are send with the request. For security + reasons, the access rights validation should be checked first. + """ + url: str = run_keyword("get_valid_url", path, method) + response: Response = run_keyword("authorized_request", url, method) + if response.status_code != 403: + raise AssertionError( + f"Response {response.status_code} was not 403." + ) @keyword def test_invalid_url( From dded5b794c4ad7dff7d4a3234b9dafdc2c830f38 Mon Sep 17 00:00:00 2001 From: Robin Mackaij Date: Fri, 12 Apr 2024 12:53:17 +0000 Subject: [PATCH 2/2] Format and updated libspec --- src/OpenApiDriver/openapi_executors.py | 8 ++------ src/OpenApiDriver/openapidriver.libspec | 23 ++++++++++++++++++++--- src/OpenApiDriver/openapidriver.py | 1 + 3 files changed, 23 insertions(+), 9 deletions(-) diff --git a/src/OpenApiDriver/openapi_executors.py b/src/OpenApiDriver/openapi_executors.py index 9b5d137..e2a57e8 100644 --- a/src/OpenApiDriver/openapi_executors.py +++ b/src/OpenApiDriver/openapi_executors.py @@ -110,9 +110,7 @@ def test_unauthorized(self, path: str, method: str) -> None: verify=False, ) if response.status_code != 401: - raise AssertionError( - f"Response {response.status_code} was not 401." - ) + raise AssertionError(f"Response {response.status_code} was not 401.") @keyword def test_forbidden(self, path: str, method: str) -> None: @@ -129,9 +127,7 @@ def test_forbidden(self, path: str, method: str) -> None: url: str = run_keyword("get_valid_url", path, method) response: Response = run_keyword("authorized_request", url, method) if response.status_code != 403: - raise AssertionError( - f"Response {response.status_code} was not 403." - ) + raise AssertionError(f"Response {response.status_code} was not 403.") @keyword def test_invalid_url( diff --git a/src/OpenApiDriver/openapidriver.libspec b/src/OpenApiDriver/openapidriver.libspec index a6d628c..c11c01e 100644 --- a/src/OpenApiDriver/openapidriver.libspec +++ b/src/OpenApiDriver/openapidriver.libspec @@ -1,5 +1,5 @@ - + 0.1.3 <p>Visit the <a href="https://github.com/MarketSquare/robotframework-openapidriver">library page</a> for an introduction and examples.</p> @@ -199,7 +199,7 @@ - + path @@ -219,7 +219,23 @@ <p>The keyword calls other keywords to generate the neccesary data to perform the desired operation and validate the response against the openapi document.</p> Validate that performing the `method` operation on `path` results in a `status_code` response. - + + + +path +str + + +method +str + + +<p>Perform a request for <span class="name">method</span> on the <a href="#type-Path" class="name">path</a>, with the provided authorization.</p> +<p>This keyword only passes if the response code is 403: Forbidden.</p> +<p>For this keyword to pass, the authorization parameters used to initialize the library should grant insufficient access rights to the target endpoint. &gt; Note: No headers or (json) body are send with the request. For security reasons, the access rights validation should be checked first.</p> +Perform a request for `method` on the `path`, with the provided authorization. + + path @@ -361,6 +377,7 @@ __init__ Test Endpoint +Test Forbidden Test Invalid Url Test Unauthorized diff --git a/src/OpenApiDriver/openapidriver.py b/src/OpenApiDriver/openapidriver.py index a42f39c..b17b665 100644 --- a/src/OpenApiDriver/openapidriver.py +++ b/src/OpenApiDriver/openapidriver.py @@ -357,6 +357,7 @@ def get_keyword_names() -> List[str]: """Curated keywords for libdoc and libspec.""" return [ "test_unauthorized", + "test_forbidden", "test_invalid_url", "test_endpoint", ] # pragma: no cover