diff --git a/core/src/main/kotlin/org/evomaster/core/output/service/HttpWsTestCaseWriter.kt b/core/src/main/kotlin/org/evomaster/core/output/service/HttpWsTestCaseWriter.kt index 11aaf46a1f..f4aee830be 100644 --- a/core/src/main/kotlin/org/evomaster/core/output/service/HttpWsTestCaseWriter.kt +++ b/core/src/main/kotlin/org/evomaster/core/output/service/HttpWsTestCaseWriter.kt @@ -200,7 +200,7 @@ abstract class HttpWsTestCaseWriter : ApiTestCaseWriter() { handleLastStatementComment(res, lines) - if (config.enableBasicAssertions) { + if (config.enableBasicAssertions && !call.shouldSkipAssertionsOnResponseBody()) { handleResponseAssertions(lines, res, responseVariableName) } } @@ -438,7 +438,7 @@ abstract class HttpWsTestCaseWriter : ApiTestCaseWriter() { handleLastStatementComment(res, lines) - if (config.enableBasicAssertions) { + if (config.enableBasicAssertions && !call.shouldSkipAssertionsOnResponseBody()) { handleResponseAssertions(lines, res, null) } diff --git a/core/src/main/kotlin/org/evomaster/core/problem/api/ApiWsAction.kt b/core/src/main/kotlin/org/evomaster/core/problem/api/ApiWsAction.kt index 7dc6071b9d..25228739f9 100644 --- a/core/src/main/kotlin/org/evomaster/core/problem/api/ApiWsAction.kt +++ b/core/src/main/kotlin/org/evomaster/core/problem/api/ApiWsAction.kt @@ -24,4 +24,12 @@ abstract class ApiWsAction( fun addParam(param: Param){ addChild(param) } + + /** + * In some very special cases, we want to skip creating assertions on response bodies from the API + */ + open fun shouldSkipAssertionsOnResponseBody() : Boolean{ + return false + } + } \ No newline at end of file diff --git a/core/src/main/kotlin/org/evomaster/core/problem/rest/RestCallAction.kt b/core/src/main/kotlin/org/evomaster/core/problem/rest/RestCallAction.kt index 6a0794634e..99bc60856e 100644 --- a/core/src/main/kotlin/org/evomaster/core/problem/rest/RestCallAction.kt +++ b/core/src/main/kotlin/org/evomaster/core/problem/rest/RestCallAction.kt @@ -8,6 +8,7 @@ import org.evomaster.core.problem.rest.param.FormParam import org.evomaster.core.problem.api.param.Param import org.evomaster.core.problem.rest.param.PathParam import org.evomaster.core.problem.rest.resource.ActionRToken +import org.evomaster.core.problem.rest.service.AbstractRestSampler import org.evomaster.core.problem.util.ParamUtil import org.evomaster.core.problem.rest.util.ParserUtil import org.evomaster.core.problem.util.BindingBuilder @@ -222,4 +223,8 @@ class RestCallAction( // binding params in this action, e.g., path param with body param if there exists BindingBuilder.bindParamsInRestAction(this, randomness = randomness) } + + override fun shouldSkipAssertionsOnResponseBody(): Boolean { + return id == AbstractRestSampler.CALL_TO_SWAGGER_ID + } } \ No newline at end of file diff --git a/core/src/main/kotlin/org/evomaster/core/problem/rest/service/AbstractRestSampler.kt b/core/src/main/kotlin/org/evomaster/core/problem/rest/service/AbstractRestSampler.kt index 66b6194c6b..12e26eee46 100644 --- a/core/src/main/kotlin/org/evomaster/core/problem/rest/service/AbstractRestSampler.kt +++ b/core/src/main/kotlin/org/evomaster/core/problem/rest/service/AbstractRestSampler.kt @@ -34,6 +34,8 @@ abstract class AbstractRestSampler : HttpWsSampler() { companion object { private val log: Logger = LoggerFactory.getLogger(AbstractRestSampler::class.java) + + const val CALL_TO_SWAGGER_ID = "Call to Swagger" } @Inject @@ -209,11 +211,9 @@ abstract class AbstractRestSampler : HttpWsSampler() { */ private fun addCallToSwagger() : RestCallAction?{ - val id = "Call to Swagger" - if (configuration.blackBox && !configuration.bbExperiments) { return if (configuration.bbSwaggerUrl.startsWith("http", true)){ - buildActionBasedOnUrl(BlackBoxUtils.targetUrl(config,this), id, HttpVerb.GET, configuration.bbSwaggerUrl, true) + buildActionBasedOnUrl(BlackBoxUtils.targetUrl(config,this), CALL_TO_SWAGGER_ID, HttpVerb.GET, configuration.bbSwaggerUrl, true) } else null } @@ -229,7 +229,7 @@ abstract class AbstractRestSampler : HttpWsSampler() { return null } - return buildActionBasedOnUrl(base, id, HttpVerb.GET, openapi, true) + return buildActionBasedOnUrl(base, CALL_TO_SWAGGER_ID, HttpVerb.GET, openapi, true) } /**