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

test robustness of explain

parent 0878655b
......@@ -465,6 +465,11 @@ system_test:irrelevant robust against non-path payload:
variables:
TEST_NAME: robust_irrelevant@file_non_path_payload
system_test:explain robust against non-path payload:
extends: .system_test:run_with_data
variables:
TEST_NAME: robust_explain_non_path_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
......
[
{"request_body": "plain text"},
{"request_body": "\"a string\""},
{"request_body": "true"},
{"request_body": "false"},
{"request_body": "null"},
{"request_body": 1},
{"request_body": -1},
{"request_body": 1.2345},
{"request_body": 1234567891011121314151617181920},
{"request_body": "123456789101112131415161718192021222324252627282930"},
{"request_body": "[1,2,3]"},
{"request_body": "{}"},
{"request_body": "{\"abs_path\":65}"},
{"request_body": "{\"abs_path\":23.48}"},
{"request_body": "{\"abs_path\":[]}"},
{"request_body": "{\"abs_path\":[1,2,3]}"},
{"request_body": "{\"abs_path\":{}}"},
{"request_body": "{\"abs_path\":{\"content\":\"a_file\"}}"},
{"request_body": "{\"abs_path\":\"a_file\",\"another_key\":6}"}
]
{
"info": {
"_postman_id": "1ef533c8-03ff-4cfc-a5fd-51a4664e1031",
"name": "Robustness explain Non-Path Payload Copy",
"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 `explain` 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 the data file `robust_explain_non_path_payload-data.json`.",
"schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json"
},
"item": [
{
"name": "Querry Explanation",
"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": [
"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.requestName + \"[\" + (pm.info.iteration + 1).toString() + '/' ",
" + pm.info.iterationCount.toString() + ']: ');"
],
"type": "text/javascript"
}
}
],
"protocolProfileBehavior": {
"disabledSystemHeaders": {
"connection": true
}
},
"request": {
"method": "POST",
"header": [],
"body": {
"mode": "raw",
"raw": "{{request_body}}",
"options": {
"raw": {
"language": "json"
}
}
},
"url": {
"raw": "http://{{SERVER}}/explain",
"protocol": "http",
"host": [
"{{SERVER}}"
],
"path": [
"explain"
]
}
},
"response": []
}
],
"event": [
{
"listen": "prerequest",
"script": {
"type": "text/javascript",
"exec": [
""
]
}
},
{
"listen": "test",
"script": {
"type": "text/javascript",
"exec": [
""
]
}
}
],
"variable": [
{
"key": "response-schema:error",
"value": ""
},
{
"key": "request_body",
"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