Skip to content

Commit

Permalink
handling of too large body payloads
Browse files Browse the repository at this point in the history
  • Loading branch information
arcuri82 committed Nov 28, 2019
1 parent e8ea441 commit e04c5b1
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 13 deletions.
26 changes: 15 additions & 11 deletions core/src/main/kotlin/org/evomaster/core/output/TestCaseWriter.kt
Expand Up @@ -83,23 +83,25 @@ class TestCaseWriter {

lines.indented {

if (test.test.individual is RestIndividual) {
val ind = test.test.individual

if (ind is RestIndividual) {
// BMR: test.test should have the used objects attached (if any).
if (config.enableCompleteObjects) {
usedObjects = (test.test.individual as RestIndividual).usedObjects.copy()
usedObjects = ind.usedObjects.copy()
}
if(configuration.expectationsActive){
expectationsWriter.addDeclarations(lines)
}
if (!test.test.individual.dbInitialization.isEmpty()) {
handleDbInitialization(format, (test.test.individual as RestIndividual).dbInitialization, lines)
if (ind.dbInitialization.isNotEmpty()) {
handleDbInitialization(format, ind.dbInitialization, lines)
}
}

if (test.hasChainedLocations()) {
lines.addEmpty()

test.test.evaluatedActions()
test.test.evaluatedActions().asSequence()
.map { it.action }
.filterIsInstance(RestCallAction::class.java)
.filter { it.locationId != null }
Expand Down Expand Up @@ -603,12 +605,14 @@ class TestCaseWriter {
else -> {
// This branch will be called if the JSON is null (or has a basic type)
// Currently, it converts the contents to String.
if(bodyString.isNullOrBlank()){
lines.add(".body(isEmptyOrNullString())")
}else {
lines.add(".body(containsString(\"${
GeneUtils.applyEscapes(bodyString, mode = GeneUtils.EscapeMode.BODY, format = format)
}\"))")
when {
res.getTooLargeBody() -> lines.add("/* very large body, which was not handled during the search */")

bodyString.isNullOrBlank() -> lines.add(".body(isEmptyOrNullString())")

else -> lines.add(".body(containsString(\"${
GeneUtils.applyEscapes(bodyString, mode = GeneUtils.EscapeMode.BODY, format = format)
}\"))")
}
}
}
Expand Down
Expand Up @@ -7,6 +7,7 @@ import org.evomaster.client.java.controller.api.dto.HeuristicEntryDto
import org.evomaster.client.java.controller.api.dto.SutInfoDto
import org.evomaster.client.java.controller.api.dto.TestResultsDto
import org.evomaster.core.database.DatabaseExecution
import org.evomaster.core.logging.LoggingUtil
import org.evomaster.core.problem.rest.*
import org.evomaster.core.problem.rest.auth.NoAuth
import org.evomaster.core.problem.rest.param.BodyParam
Expand Down Expand Up @@ -361,7 +362,8 @@ abstract class AbstractRestFitness<T> : FitnessFunction<T>() where T : Individua
if (body.length < configuration.maxResponseByteSize) {
rcr.setBody(body)
} else {
log.warn("A very large response body was retrieved from the endpoint '${a.path}'." +
LoggingUtil.uniqueWarn(log,
"A very large response body was retrieved from the endpoint '${a.path}'." +
" If that was expected, increase the 'maxResponseByteSize' threshold" +
" in the configurations.")
rcr.setTooLargeBody(true)
Expand Down
Expand Up @@ -7,6 +7,7 @@ import org.evomaster.client.java.controller.api.dto.SutInfoDto
import org.evomaster.client.java.controller.api.dto.TestResultsDto
import org.evomaster.client.java.controller.api.dto.database.execution.ExecutionDto
import org.evomaster.core.database.DbActionTransformer
import org.evomaster.core.logging.LoggingUtil
import org.evomaster.core.problem.rest.*
import org.evomaster.core.problem.rest.auth.NoAuth
import org.evomaster.core.problem.rest.param.HeaderParam
Expand Down Expand Up @@ -418,7 +419,8 @@ class ObjFitness : FitnessFunction<ObjIndividual>() {
if (body.length < configuration.maxResponseByteSize) {
rcr.setBody(body)
} else {
log.warn("A very large response body was retrieved from the endpoint '${a.path}'." +
LoggingUtil.uniqueWarn(log,
"A very large response body was retrieved from the endpoint '${a.path}'." +
" If that was expected, increase the 'maxResponseByteSize' threshold" +
" in the configurations.")
rcr.setTooLargeBody(true)
Expand Down

0 comments on commit e04c5b1

Please sign in to comment.