Commit f62b4c9d authored by Siebers, Michael's avatar Siebers, Michael
Browse files

test endpoints against wrong payload

for endpoints expecting none
parent 21680bbd
......@@ -436,6 +436,11 @@ system_test:robust against wrong payload:
variables:
TEST_NAME: robust_wrong_content_payload
system_test:robust against superfluous payload:
extends: .system_test:run_with_data
variables:
TEST_NAME: robust_wrong_content_empty
# If no FORCE_... variable is set to "yes", no pipeline is created for merge
# requests targetting a non-default branch. Thus, the MR cannot be merged. This
# dummy job remedies the missing pipeline.
......
[
{"endpoint": "bg/clear", "method": "POST"},
{"endpoint": "bg/show", "method": "GET"},
{"endpoint": "state", "method": "GET"}
]
{
"info": {
"_postman_id": "2b8373d9-dcd5-4665-96bb-4bed388ad1e3",
"name": "Robustness Wrong Content without Payload",
"description": "This collection tests whether the [Reasoning WebAPI for Dare2Del](https://gitlab.rz.uni-bamberg.de/cogsys/dare2del/demonstrator) (Version 1.0.0) handles requests expecting no payload with payload or wrong HTTP headers. The response's error message (if any) is not checked.\n\nThe collection is to be run with data file `robust_wrong_content_empty-data.json`.",
"schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json"
},
"item": [
{
"name": "With Text Body",
"event": [
{
"listen": "prerequest",
"script": {
"exec": [
"pm.request.method=pm.variables.get(\"method\");"
],
"type": "text/javascript"
}
},
{
"listen": "test",
"script": {
"exec": [
"pm.test(pm.variables.get(\"test_prefix\") + \"OK\", function () {",
" pm.expect(pm.response.code).to.eql(200);",
"});"
],
"type": "text/javascript"
}
}
],
"request": {
"method": "POST",
"header": [],
"body": {
"mode": "raw",
"raw": "some body"
},
"url": {
"raw": "http://{{SERVER}}/{{endpoint}}",
"protocol": "http",
"host": [
"{{SERVER}}"
],
"path": [
"{{endpoint}}"
]
}
},
"response": []
},
{
"name": "With JSON Body",
"event": [
{
"listen": "prerequest",
"script": {
"exec": [
"pm.request.method=pm.variables.get(\"method\");"
],
"type": "text/javascript"
}
},
{
"listen": "test",
"script": {
"exec": [
"pm.test(pm.variables.get(\"test_prefix\") + \"OK\", function () {",
" pm.expect(pm.response.code).to.eql(200);",
"});"
],
"type": "text/javascript"
}
}
],
"request": {
"method": "POST",
"header": [],
"body": {
"mode": "raw",
"raw": "{\"key\":\"value\"}",
"options": {
"raw": {
"language": "json"
}
}
},
"url": {
"raw": "http://{{SERVER}}/{{endpoint}}",
"protocol": "http",
"host": [
"{{SERVER}}"
],
"path": [
"{{endpoint}}"
]
}
},
"response": []
},
{
"name": "No Body with Content-Length Header",
"event": [
{
"listen": "prerequest",
"script": {
"exec": [
"pm.request.method=pm.variables.get(\"method\");"
],
"type": "text/javascript"
}
},
{
"listen": "test",
"script": {
"exec": [
"pm.test(pm.variables.get(\"test_prefix\") + \"Request Timeout\", function () {",
" pm.expect(pm.response.code).to.eql(408);",
"});",
"",
"pm.test(pm.variables.get(\"test_prefix\") + \"Valid error response body\", function() {",
" pm.response.to.be.withBody;",
" pm.response.to.be.json;",
"",
" var Ajv = require('ajv');",
" ajv = new Ajv();",
" const validate = ajv.compile(JSON.parse(pm.variables.get(\"response-schema:error\")));",
"",
" const jsonData = pm.response.json();",
" pm.expect(validate(jsonData)).to.be.true;",
" pm.expect(jsonData.code).to.eql(408);",
"});"
],
"type": "text/javascript"
}
}
],
"request": {
"method": "POST",
"header": [
{
"key": "Content-Length",
"value": "1",
"type": "text"
}
],
"url": {
"raw": "http://{{SERVER}}/{{endpoint}}",
"protocol": "http",
"host": [
"{{SERVER}}"
],
"path": [
"{{endpoint}}"
]
}
},
"response": []
}
],
"event": [
{
"listen": "prerequest",
"script": {
"type": "text/javascript",
"exec": [
"if(! pm.collectionVariables.get(\"response-schema:error\")) {",
" var code_ok = false;",
" const schema_url = \"http://\" + pm.environment.get(\"SERVER\") + pm.environment.get(\"SCHEMA_PATH\") ",
" + \"/response-error-schema.json\";",
" pm.sendRequest(schema_url, function(err, response){",
" pm.test(\"Load error response schema: Status code is 200\", function () {",
" pm.expect(err).to.not.be.ok;",
" console.log(response);",
" pm.expect(response.code).to.eql(200);",
" code_ok = true;",
" });",
"",
"",
" pm.test(\"Load error response schema: Response is JSON object\", function() {",
" const jsonData = response.json();",
" pm.expect(jsonData).is.an(\"object\");",
"",
" if(code_ok)",
" pm.collectionVariables.set(\"response-schema:error\", JSON.stringify(jsonData));",
" });",
" });",
"}",
"",
"pm.variables.set(\"test_prefix\", pm.variables.get(\"endpoint\") + \": \" );"
]
}
},
{
"listen": "test",
"script": {
"type": "text/javascript",
"exec": [
""
]
}
}
],
"variable": [
{
"key": "response-schema:error",
"value": ""
}
]
}
\ No newline at end of file
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment