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

test bg/add and bg/remove against non-item payload

parent e22c2218
......@@ -431,7 +431,7 @@ system_test:robust against wrong method:
variables:
TEST_NAME: robust_wrong_method
system_test:robust against wrong payload:
system_test:robust against wrong body:
extends: .system_test:run_with_data
variables:
TEST_NAME: robust_wrong_content_payload
......@@ -441,6 +441,11 @@ system_test:robust against superfluous payload:
variables:
TEST_NAME: robust_wrong_content_empty
system_test:bg robust against non-item payload:
extends: .system_test:run_with_data
variables:
TEST_NAME: robust_bg_non_item_payload
# 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.
......
This diff is collapsed.
{
"info": {
"_postman_id": "2424552e-46a8-45bd-9b4a-f5a78aa79d2e",
"name": "Robustness BG Non-Item 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 POST requests to bg/add` and `/bg/remove` with semantically wrong payload gracefully. These should all result in 4xx responses. The response body should be an error response with the same code. The response message is not checked. \n\nThe collection is to be run with data file `robust_bg_non_item_payload-data.json`.",
"schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json"
},
"item": [
{
"name": "Add Items",
"event": [
{
"listen": "test",
"script": {
"exec": [
"pm.test(pm.variables.get(\"test_prefix\") + \"Bad Request\", function () {",
" pm.expect(pm.response.code).to.eql(400);",
"});",
"",
"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(400);",
"});"
],
"type": "text/javascript"
}
},
{
"listen": "prerequest",
"script": {
"exec": [
""
],
"type": "text/javascript"
}
}
],
"request": {
"method": "POST",
"header": [],
"body": {
"mode": "raw",
"raw": "{{request_body}}",
"options": {
"raw": {
"language": "json"
}
}
},
"url": {
"raw": "http://{{SERVER}}/bg/add",
"protocol": "http",
"host": [
"{{SERVER}}"
],
"path": [
"bg",
"add"
]
},
"description": "Add a single, previously unknown file (good case)."
},
"response": []
},
{
"name": "Remove Items",
"event": [
{
"listen": "test",
"script": {
"exec": [
"pm.test(pm.variables.get(\"test_prefix\") + \"Bad Request\", function () {",
" pm.expect(pm.response.code).to.eql(400);",
"});",
"",
"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(400);",
"});"
],
"type": "text/javascript"
}
},
{
"listen": "prerequest",
"script": {
"exec": [
""
],
"type": "text/javascript"
}
}
],
"request": {
"method": "POST",
"header": [],
"body": {
"mode": "raw",
"raw": "{{request_body}}",
"options": {
"raw": {
"language": "json"
}
}
},
"url": {
"raw": "http://{{SERVER}}/bg/remove",
"protocol": "http",
"host": [
"{{SERVER}}"
],
"path": [
"bg",
"remove"
]
},
"description": "Add a single, previously unknown file (good case)."
},
"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.info.iteration + 1).toString() + '/' ",
" + pm.info.iterationCount.toString() + '] ' + pm.info.requestName + \": \");"
]
}
},
{
"listen": "test",
"script": {
"type": "text/javascript",
"exec": [
""
]
}
}
],
"variable": [
{
"key": "request_body",
"value": ""
},
{
"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