-
Notifications
You must be signed in to change notification settings - Fork 4
Understanding Variables & Context
Restel supports variables, which gives certain amount of dynamicity to the test definition in Restel, like referring to the request/response of some other request.
Variables are referred using ${<fully_qualified_variable_name>}. The variables are supported in almost all the fields of test/scenario definitions. The evaluation of the value happens just before the execution of the respective tests.
Context is a map of values maintained by Restel while the test is being executed,
Restel tracks all the requests and responses within the context.
The contexts can be referred using variables by giving the fully qualified name of what we are referring to.
For example, say we have an Test Definition some_API under the Test Scenario some_scenario and if the response of the API call is,
{
"name" : "name of the user",
"groups" : ["g1", "g2" ,"g3"]
}${some_scenario.some_API.response.name}.
-
If we want to refer to the first groups in the response, we can do it as
${some_scenario.some_API.response.groups[0]}.
Restel, can help you solve more woes with the help of middleware. Restel middleware provides us an opportunity to add pre or post processor to the requests and response.
In test definition sheet two columns are earmarked for middleware as follows:
-
request_pre_call_hook
-
request_post_call_hook
as the name suggests former one is used for pre processing and the later is used in post processing. Wondering what kind of processing would require while testing? We often bump into the requirements of storing the response into a file for debugging or for comparisons and the most important aspect in today’s context is authentication & authorization.
At this moment we Restel supports three request middleware:
-
BasicAuth Middleware
-
Oauth2 Client credential Middleware
-
Oauth2 Resource Owner Password Middleware
If you’re dealing with APIs that supports BasicAuth then you should probably use this middleware it adds Authorization header to the request headers with the given username and password. Header Key : Authorization , Value : Basic <token> . Where token is the Base64 encoding of username:password
{
"Authorization": {
"basic_auth": {
"username": "<username>",
"password": "<password>"
}
}
}| Field | Mandatory/Optional | Format | Example |
|---|---|---|---|
username |
Mandatory |
String |
Billy |
password |
Mandatory |
String |
ThisIsACrazyPassword |
OAuth based authentication has become a de facto standard for most of the application these days and if your application is relying on OAuth2 with client credentials then use this middleware it adds Authorization header to the request headers which make calls to the authorization server to fetch accessToken which has Oauth2 authentication with grant type client credentials.. Header Key : Authorization , Value : Bearer <accesstoken> . Where accesstoken is a token generated by the Authorization Server.
{
"Authorization": {
"oauth2": {
"client_credentials": {
"authUrl": "<auth_url>",
"clientId": "<client_id>",
"clientSecret": "<clientSecret>",
"scope": "<Scopes>"
}
}
}
}
| Field | Mandatory/Optional | Format | Example |
|---|---|---|---|
authUrl |
Mandatory |
String |
|
clientSecret |
Mandatory |
String |
8A6eAB8hUjOb9w5hWCT6CndX5FY0gFomfRMvv65jDON’TEXPOSEYOURSECERETSANYWHERE |
clientId |
Mandatory |
String |
YOURCLIENTIDLIKE0oa10nhj6gkhyPLXb4x9 |
scope |
Optional |
Space separated String |
emailId personal groups |
password |
Mandatory |
String |
ThisIsACrazyPassword |
If you’re using resource owner password while invoking the application then use this middleware it adds Authorization header to the request headers which make calls to the authorization server to fetch accessToken which has Oauth2 authentication with grant type password.. Header Key : Authorization , Value : Bearer <accesstoken> . Where accesstoken is a token generated by the Authorization Server.
{
"Authorization": {
"oauth2": {
"password": {
"username": "<username>",
"password": "<password>",
"authUrl": "<auth_url>",
"clientId": "<client_id>",
"clientSecret": "<clientSecret>",
"scope": "<Scopes>"
}
}
}
}| Field | Mandatory/Optional | Format | Example |
|---|---|---|---|
username |
Mandatory |
String |
Billy |
password |
Mandatory |
String |
ThisIsACrazyPassword |
authUrl |
Mandatory |
String |
|
clientSecret |
Mandatory |
String |
8A6eAB8hUjOb9w5hWCT6CndX5FY0gFomfRMvv65jDON’TEXPOSEYOURSECERETSANYWHERE |
clientId |
Mandatory |
String |
YOURCLIENTIDLIKE0oa10nhj6gkhyPLXb4x9 |
scope |
Optional |
Space separated String |
emailId personal groups |
password |
Mandatory |
String |
ThisIsACrazyPassword |