Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

handling of too large body payloads #134

Merged
merged 1 commit into from Nov 29, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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