Skip to content

Commit

Permalink
Merge pull request #943 from EMResearch/avoid-assertions
Browse files Browse the repository at this point in the history
make sure calls to Swagger do not lead to generate assertions on it
  • Loading branch information
arcuri82 authored Mar 29, 2024
2 parents bdf239f + d0eae15 commit 1f6ea2b
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ abstract class HttpWsTestCaseWriter : ApiTestCaseWriter() {

handleLastStatementComment(res, lines)

if (config.enableBasicAssertions) {
if (config.enableBasicAssertions && !call.shouldSkipAssertionsOnResponseBody()) {
handleResponseAssertions(lines, res, responseVariableName)
}
}
Expand Down Expand Up @@ -438,7 +438,7 @@ abstract class HttpWsTestCaseWriter : ApiTestCaseWriter() {

handleLastStatementComment(res, lines)

if (config.enableBasicAssertions) {
if (config.enableBasicAssertions && !call.shouldSkipAssertionsOnResponseBody()) {
handleResponseAssertions(lines, res, null)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ abstract class AbstractRestSampler : HttpWsSampler<RestIndividual>() {

companion object {
private val log: Logger = LoggerFactory.getLogger(AbstractRestSampler::class.java)

const val CALL_TO_SWAGGER_ID = "Call to Swagger"
}

@Inject
Expand Down Expand Up @@ -209,11 +211,9 @@ abstract class AbstractRestSampler : HttpWsSampler<RestIndividual>() {
*/
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
}
Expand All @@ -229,7 +229,7 @@ abstract class AbstractRestSampler : HttpWsSampler<RestIndividual>() {
return null
}

return buildActionBasedOnUrl(base, id, HttpVerb.GET, openapi, true)
return buildActionBasedOnUrl(base, CALL_TO_SWAGGER_ID, HttpVerb.GET, openapi, true)
}

/**
Expand Down

0 comments on commit 1f6ea2b

Please sign in to comment.