Taurus error when try to check response code - blazemeter

I am trying to assert the response for a HTTP GET
execution:
- executor: selenium
scenario: dashboard
iterations: 1
reporting:
- module: final-stats
dump-xml: results/test.xml
dump-csv: results/test2.csv
- module: junit-xml
filename: results/testfinal.xml
data-source: pass-fail
modules:
console:
disable: true
scenarios:
dashboard:
browser: Chrome
timeout: 60s
default-address: https://${URL}
requests:
- label: ignore
url: https://${URL}
actions:
- waitByXPath(/html/body/div/div[2]/div/div/div/div[4]/div[2]/form/input[4]): Visible
- keysByXPath(/html/body/div/div[2]/div/div/div/div[4]/div[2]/form/input[4]): ${USERNAME}
- keysByXPath(/html/body/div/div[2]/div/div/div/div[4]/div[2]/form/input[5]): ${PASSWORD}
- clickByXPath(/html/body/div/div[2]/div/div/div/div[4]/div[2]/form/div[4]/button)
- url: /Sites/testsite/api/level1/status/auth-service-health-check
method: GET
assert:
- contains:
- 200
subject: status-code
Error i am getting is "TypeError: first argument must be string or compiled pattern"
Please can any one help with this
All what i need to check is whether the reponse status is 200 for url: /Sites/testsite/api/level1/status/auth-service-health-check
issue is on here exactly
- contains:
- 200
subject: status-code
if i add like this error disappeared but then it checking the response body not status code
- contains:
- '200'
subject: status-code

The suggestion to check http-code instead of status-code is correct. To expand on that, check out the explanation here:
https://gettaurus.org/docs/JMeter/#HTTP-Requests
Scroll down a bit and there's a discussion of how exactly assertions work in Taurus, with some examples. Of particular note is this part:
Possible subjects are:
body
headers
http-code

Have you tried changing the subject to http-code?:
subject: http-code

Related

In swagger, can I use the whole post request body as plain text parameter?

In some documents it says it allows this:
parameters:
- name: body
'in': 'body'
required: true
schema:
type: string
But in reality, the in argument can only be path, query, cookie or header.
I also could not skip the parameters, because it would generate the wrong rust code.
Yes! As described in the docs, here (under 'Primitive Body'):
https://swagger.io/docs/specification/2-0/describing-request-body/
In your swagger.yml you can specify it like so:
paths:
/status:
post:
summary: Updates the status message.
consumes:
- text/plain # <----------
parameters:
- in: body
name: status
required: true
schema:
type: string # <----------
responses:
200:
description: Success!
This is the exact code snipped from the docs, pasted here for your convenience. :)
No I don't think there is any way you can make the request body object part of your parameter object anymore, but you could skip your parameters with:
parameters: []

how to send post requests to AWS Lambda function created with serverless

TLDR
I cant figure out how to format my post request for my AWS Lambda API created with serverless
Current Implementation
I have a Lambda function created using the serverless framework. I have two functions; a function which prints out all modules and their version, and another that does a prediction on data sent via a post request. It handles dependency storage by mounting an EFS volume, here's the serverless.yml
service: test3Predict
plugins:
- serverless-pseudo-parameters
custom:
efsAccessPoint: fsap-**********
LocalMountPath: /mnt/efs
subnetsId: subnet-**********
securityGroup: sg-**********
provider:
name: aws
runtime: python3.6
region: us-east-2
timeout: 20
package:
exclude:
- node_modules/**
- .vscode/**
- .serverless/**
- .pytest_cache/**
- __pychache__/**
functions:
ohPredict:
handler: handler.lambda_handler_OH
environment: # Service wide environment variables
MNT_DIR: ${self:custom.LocalMountPath}
vpc:
securityGroupIds:
- ${self:custom.securityGroup}
subnetIds:
- ${self:custom.subnetsId}
iamManagedPolicies:
- arn:aws:iam::aws:policy/AmazonElasticFileSystemClientReadWriteAccess
events:
- http:
path: ohPredict
method: get
fileSystemConfig:
localMountPath: '${self:custom.LocalMountPath}'
arn: 'arn:aws:elasticfilesystem:${self:provider.region}:#{AWS::AccountId}:access-point/${self:custom.efsAccessPoint}'
test:
handler: handler.test
environment: # Service wide environment variables
MNT_DIR: ${self:custom.LocalMountPath}
vpc:
securityGroupIds:
- ${self:custom.securityGroup}
subnetIds:
- ${self:custom.subnetsId}
iamManagedPolicies:
- arn:aws:iam::aws:policy/AmazonElasticFileSystemClientReadWriteAccess
events:
- http:
path: test
method: get
fileSystemConfig:
localMountPath: '${self:custom.LocalMountPath}'
arn: 'arn:aws:elasticfilesystem:${self:provider.region}:#{AWS::AccountId}:access-point/${self:custom.efsAccessPoint}'
It seems like the test is working; If I run sls deploy and enter the URL for my test function in a browser, I get the expected output.
Problem
The ohPredict function is not working as well. When I send it a post request with the requests python module,
url = 'https://****.execute-api.****.amazonaws.com/dev/ohPredict'
myobj = {"data": data}
x = requests.post(url, json=myobj)
res = eval(x.text)
print(res)
I get the following error:
{'message': 'Missing Authentication Token'}
I ran a test with a simple lambda function and a post request without using serverless, and that was all the code I needed. I figured I would try experimenting and supplying a few values, and I ended up with this:
url = 'https://****.execute-api.****.amazonaws.com/dev/ohPredict'
myobj = {"data": data}
x = requests.post(url, headers={'Authorization': 'FOO'}, json=myobj)
res = eval(x.text)
print(res)
which resulted in:
{'message': "Authorization header requires 'Credential' parameter. Authorization header requires 'Signature' parameter. Authorization header requires 'SignedHeaders' parameter. Authorization header requires existence of either a 'X-Amz-Date' or a 'Date' header. Authorization=FOO"}
I tried playing around with supplying other values, and didn't get any change in the output. How can I get my post request to be recieved by my function?
As mentioned by yvesonline, the problem was the method. This was fixed by simply replacing method: get to method: post

Nelmio Docs is returning 401 Undocumented

When I try to execute API route without authentication, it returns correct message but there in the code I see 401 Undocumented. Is this undocumented normal? where should I fix it. I have attached an image below:
yaml file:
nelmio_api_doc:
documentation:
securityDefinitions:
my_token:
type: apiKey
description: 'token'
name: token_name
in: header

Error testing API with Swagger response header 405

So I'm fairly new to creating API documentation and I'm having some difficulty creating a new entry via the swagger UI. I keep getting a 405 response. I have no idea what the issue is, I've become code blind. The link to the API is below. Any pointers would be greatly appreciated.
https://swaggerhub.com/apis/Sharper-Web-Dev/test/1.0.0
Your definition specifies SwaggerHub's mock server (virtserver.swaggerhub.com) as the target server. The mock server generates the responses based on the responses defined in your API definition. POST /charity defines just the 405 response, that's why the mock returns 405.
To get a "normal" response, you need to define a 200 OK or 201 Created response, and add the response schema (or response examples) describing the desired JSON structure.
paths:
/charity:
post:
...
produces:
- application/json
parameters:
...
responses:
200:
description: OK
schema:
$ref: "#/definitions/MyResponseSchema"
405:
description: "Invalid input"
See How Response Mocking Works in SwaggerHub docs for further information.

How to provide example value to a Response Body of content-type: text/html in Swagger (to test with dredd)

I have an API call which responds 200 OK and returns an HTML. I would like to add this to my API documentation
(especially since i validate it using dredd and unless i provide it with the expected response body the test fails). How
would i do this in Swagger?
--- More details ---
My Response to an API call is 200 OK and with a one line Response Body:
<html><body>You are being redirected.</body></html>
I can easily define the Response Body in Blueprint in the following form:
+ Response 302 (text/html; charset=utf-8)
+ Body
`<html><body>You are being redirected.</body></html>`
But i'm not sure how to do this in Swagger. Almost all examples i can find are for application/json responses (understandably) and i'm having trouble
guessing the correct syntax for this kind of response.
The relevant swagger text in my document is this (so far without specifying the response body, so with an empty body dredd
fails because the response body should be <html><body>You are being redirected.</body></html>):
# this is my API spec in YAML
swagger: '2.0'
info:
title: My API (Swagger)
description: blablabla
version: "1.0.0"
# the domain of the service
host: my.domain.com
# array of all schemes that your API supports
schemes:
- https
# will be prefixed to all paths
basePath: /
produces:
- application/json; charset=utf-8
paths:
/users/password:
post:
summary: Password Reset
description: |
Handles Reset password for existing user.
consumes:
- application/x-www-form-urlencoded
produces:
- text/html; charset=utf-8
parameters:
- name: "user[email]"
description: email
in: formData
required: true
type: string
default: "user#gmail.com"
tags:
- Reset Password
responses:
200:
description: Success
Please comment if you have any suggestions on this. Thanks!
Figured it out. the response object has a field called "examples" which allows to show examples to your API response.
The syntax is clearly shown in the specification and basically says you need to identify the MIME-type for the example response, in my case text/html and the value is the actual text.
so like this:
responses:
200:
description: success and returns some html text
examples:
text/html:
<html><body>Your HTML text</body></html>
That's it. Now whether or not dredd knows to take this value and compare it is another story. their docs state that any response other than JSON is validated as plain text so this should work.
Hope this helped.
In case someone needs this in the openapi version 3.0 you can do it this way:
Save your HTML. For example give this at the end of your file:
components:
schemas:
error401:
type: string
example: '<html>HTML text</html>'
Then you can reference this scheme in responses wherever you want. For example:
responses:
'401':
description: Error
content:
text/html:
schema:
$ref: '#/components/schemas/error401'

Resources