@@ -56,3 +56,54 @@ Wrapper
5656 Call And Validate ${case}
5757
5858```
59+
60+ # Authentication
61+
62+ ## Dynamic token authentication
63+ Library currently supports Schemathesis
64+ [ dynamic token] ( https://schemathesis.readthedocs.io/en/stable/guides/auth/#dynamic-token-authentication )
65+ authentication by the library import ` auth ` argument. The dynamic token generation
66+ class should follow the Schemathesis documentation. The only addition is the import.
67+ Importing the class must follow the Robot Framework library
68+ [ import rules] ( https://robotframework.org/robotframework/latest/RobotFrameworkUserGuide.html#specifying-library-to-import )
69+ , example if importing with filename, filename much match to the class name. Example
70+ if test case looks like:
71+
72+ ``` robotframework
73+ *** Settings ***
74+ Library SchemathesisLibrary url=http://127.0.0.1/openapi.json auth=${CURDIR}/AuthExtension.py
75+ Test Template Wrapper
76+
77+ *** Test Cases ***
78+ All Tests
79+ Wrapper test_case_1
80+
81+ *** Keywords ***
82+ Wrapper
83+ [Arguments] ${case}
84+ Call And Validate ${case}
85+ ```
86+ And ` AuthExtension.py ` looks like
87+ ``` python
88+ from base64 import b64encode
89+
90+ import schemathesis
91+ from robot.api import logger
92+
93+
94+ @schemathesis.auth ()
95+ class AuthExtension :
96+ def get (self , case , ctx ):
97+ # Instead of hard coding secrets to class, it is better to get them dynamically.
98+ # Jenkins or GitHub secrets, Azure keyvault, or from somewhere which is appropriate
99+ # for your needs.
100+ return b64encode(" joulu:pukki" .encode(" utf-8" )).decode(" ascii" )
101+
102+ def set (self , case , data , ctx ):
103+ case.headers = case.headers or {}
104+ case.headers[" Authorization" ] = f " Basic { data} "
105+ logger.debug(f " Updated headers for case: { case.operation.method} { case.operation.path} " )
106+ ```
107+ Then with all API calls, will have
108+ [ basic auth] ( https://en.wikipedia.org/wiki/Basic_access_authentication ) set in the
109+ headers for all calls made to your API endpoint.
0 commit comments