Skip to content

Commit e8ee8aa

Browse files
committed
tmp workaround to avoid crashes in id resolution
1 parent f2be4b3 commit e8ee8aa

3 files changed

Lines changed: 22 additions & 1 deletion

File tree

core/src/main/kotlin/org/evomaster/core/output/service/RestTestCaseWriter.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -436,6 +436,7 @@ class RestTestCaseWriter : HttpWsTestCaseWriter {
436436
"\"$path\""
437437
}
438438

439+
//FIXME this should be same algorithm as in AbstractRestFitness
439440
val idPointer = res.getResourceId()?.pointer ?: "/id"
440441

441442
val extract = extractValueFromJsonResponse(resVarName, idPointer)

core/src/main/kotlin/org/evomaster/core/problem/rest/data/RestPath.kt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -391,6 +391,12 @@ class RestPath(path: String) {
391391
it.value.name == t.name && (it.value.scope == null || it.value.scope == RestLinkParameter.Scope.PATH)
392392
}?.key
393393

394+
/*
395+
TODO are these correct??? are we properly escaping?
396+
also, URI does not comply with RFC 3968... :(
397+
need more testing
398+
*/
399+
394400
if(variable != null){
395401
/*
396402
reserved characters need to be encoded

core/src/main/kotlin/org/evomaster/core/problem/rest/service/fitness/AbstractRestFitness.kt

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,10 @@ import org.evomaster.core.taint.TaintAnalysis
6363
import org.evomaster.core.utils.StackTraceUtils
6464
import org.slf4j.Logger
6565
import org.slf4j.LoggerFactory
66+
import java.net.URI
6667
import java.net.URL
68+
import java.net.URLEncoder
69+
import java.nio.charset.StandardCharsets
6770
import javax.annotation.PostConstruct
6871
import javax.inject.Inject
6972
import javax.ws.rs.ProcessingException
@@ -881,9 +884,11 @@ abstract class AbstractRestFitness : HttpWsFitness<RestIndividual>() {
881884
*/
882885
//it.replace("\"", "")
883886
//FIXME outputFormat shouldn't really be used here
887+
//FIXME in resolveLocation
884888
GeneUtils.applyEscapes(it, GeneUtils.EscapeMode.URI, configuration.outputFormat)
885889
}
886890

891+
Lazy.assert { URI.create(fullUri).isAbsolute }
887892

888893
val builder = try {
889894
if (a.produces.isEmpty()) {
@@ -1020,8 +1025,17 @@ abstract class AbstractRestFitness : HttpWsFitness<RestIndividual>() {
10201025
val id = rcr.getResourceId()
10211026

10221027
if (id != null) {
1023-
location = callGraphService.resolveLocationForChildOperationUsingCreatedResource(a,id.value)
1028+
1029+
//FIXME tmp fix. need to be handled properly, also in generated tests with test-utils-*
1030+
val escapedId = URLEncoder.encode(id.value, StandardCharsets.UTF_8)
1031+
.replace("+", "%20");
1032+
1033+
location = callGraphService.resolveLocationForChildOperationUsingCreatedResource(a,escapedId)
10241034
if(location != null) {
1035+
/*
1036+
FIXME this case seems ignored in RestTestCaseWriter.handleLocationHeader.
1037+
Need proper handling + E2E for all these cases
1038+
*/
10251039
rcr.setHeuristicsForChainedLocation(true)
10261040
}
10271041
}

0 commit comments

Comments
 (0)