Skip to content

Commit 0c9d33c

Browse files
authored
Merge pull request #1394 from WebFuzzing/wb-issues-11-25
Wb issues 11-25
2 parents f40c3d4 + e8ee8aa commit 0c9d33c

8 files changed

Lines changed: 93 additions & 13 deletions

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: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,7 @@ class RestPath(path: String) {
329329
gene.getViewOfElements()
330330
.joinToString("&") { "$name=${encode(it.getValueAsRawString())}" }
331331
} else {
332-
val value = encode(gene!!.getValueAsRawString())
332+
val value = encode(gene.getValueAsRawString())
333333
"$name=$value"
334334
}
335335
}
@@ -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/CallGraphService.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ class CallGraphService {
6565
/**
6666
* Check in the schema if there is any action which is a direct child of [a] and last path element is a parameter
6767
*/
68-
fun hasParameterChild(a: RestCallAction): Boolean {
68+
fun isThereChildActionWithParameter(a: RestCallAction): Boolean {
6969
return sampler.seeAvailableActions()
7070
.filterIsInstance<RestCallAction>()
7171
.map { it.path }
@@ -81,9 +81,9 @@ class CallGraphService {
8181

8282
fun resolveLocationForParentOfChildOperationUsingCreatedResource(create: RestCallAction): String? {
8383

84-
if(hasParameterChild(create)) {
84+
if(isThereChildActionWithParameter(create)) {
8585
//simple case
86-
return create.resolvedPath()
86+
return create.resolvedOnlyPath()
8787
}
8888

8989
/*

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

Lines changed: 37 additions & 7 deletions
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
@@ -877,23 +880,41 @@ abstract class AbstractRestFitness : HttpWsFitness<RestIndividual>() {
877880
it is or not a valid char.
878881
Furthermore, likely needed to be done in resolveLocation,
879882
or at least check how RestAssured would behave
883+
TODO update RestPathTest, check TODO there, once fixed
880884
*/
881885
//it.replace("\"", "")
886+
//FIXME outputFormat shouldn't really be used here
887+
//FIXME in resolveLocation
882888
GeneUtils.applyEscapes(it, GeneUtils.EscapeMode.URI, configuration.outputFormat)
883889
}
884890

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

886-
val builder = if (a.produces.isEmpty()) {
887-
log.debug("No 'produces' type defined for {}", path)
888-
client.target(fullUri).request("*/*")
893+
val builder = try {
894+
if (a.produces.isEmpty()) {
895+
log.debug("No 'produces' type defined for {}", path)
896+
client.target(fullUri).request("*/*")
889897

890-
} else {
891-
/*
898+
} else {
899+
/*
892900
TODO: This only considers the first in the list of produced responses
893901
This is fine for endpoints that only produce one type of response.
894902
Could be a problem in future
895903
*/
896-
client.target(fullUri).request(a.produces.first())
904+
client.target(fullUri).request(a.produces.first())
905+
}
906+
} catch (e: Exception) {
907+
/*
908+
FIXME we need to solve this issue somehow, as location values might be invalid...
909+
but i guess that should be done in resolveLocation
910+
*/
911+
throw RuntimeException("""
912+
Failed to build HTTP invocation.
913+
Resolved path: $path
914+
Location header: $locationHeader
915+
Resolved location: $fullUri
916+
Error: ${e.message}
917+
""".trimIndent(), e)
897918
}
898919

899920
handleHeaders(a, builder, cookies, tokens)
@@ -1004,8 +1025,17 @@ abstract class AbstractRestFitness : HttpWsFitness<RestIndividual>() {
10041025
val id = rcr.getResourceId()
10051026

10061027
if (id != null) {
1007-
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)
10081034
if(location != null) {
1035+
/*
1036+
FIXME this case seems ignored in RestTestCaseWriter.handleLocationHeader.
1037+
Need proper handling + E2E for all these cases
1038+
*/
10091039
rcr.setHeuristicsForChainedLocation(true)
10101040
}
10111041
}

core/src/main/kotlin/org/evomaster/core/search/gene/regex/QuantifierRxGene.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,9 @@ class QuantifierRxGene(
200200
}
201201

202202
for (i in 0 until other.atoms.size) {
203-
if (!this.atoms[i].containsSameValueAs(other.atoms[i])) {
203+
val x = this.atoms[i]
204+
val y = other.atoms[i]
205+
if (!x.possiblySame(y) || !x.containsSameValueAs(y)) {
204206
return false
205207
}
206208
}

core/src/main/kotlin/org/evomaster/core/search/gene/string/StringGene.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -822,9 +822,10 @@ class StringGene(
822822
try {
823823
toAddGenes.add(RegexHandler.createGeneForJVM(regex))
824824
log.trace("Regex, added specification for: {}", regex)
825-
826825
} catch (e: Exception) {
827826
LoggingUtil.uniqueWarn(log, "Failed to handle regex: $regex")
827+
} catch (e: java.lang.StackOverflowError){
828+
LoggingUtil.uniqueWarn(log, "Failed to handle regex, as it gives a stack overflow error: $regex")
828829
}
829830
}
830831

core/src/test/kotlin/org/evomaster/core/parser/RegexHandlerTest.kt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,20 @@ import org.evomaster.core.search.service.AdaptiveParameterControl
88
import org.evomaster.core.search.service.Randomness
99
import org.evomaster.core.search.service.mutator.MutationWeightControl
1010
import org.junit.jupiter.api.Assertions.*
11+
import org.junit.jupiter.api.Disabled
1112
import org.junit.jupiter.api.Test
1213
import org.junit.jupiter.api.assertThrows
1314
import java.util.regex.Pattern
1415

1516
internal class RegexHandlerTest{
1617

18+
@Disabled("Needs to hande lookahead in regex")
19+
@Test
20+
fun testLanguageTool(){
21+
val s = "^((?iu)@.+)$"
22+
RegexHandler.createGeneForJVM(s)
23+
}
24+
1725

1826
@Test
1927
fun testCwaIssue(){

core/src/test/kotlin/org/evomaster/core/problem/rest/RestPathTest.kt

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package org.evomaster.core.problem.rest
22

33
import io.swagger.v3.oas.models.parameters.Parameter
4+
import org.evomaster.core.output.OutputFormat
45
import org.evomaster.core.problem.rest.builder.RestActionBuilderV3
56
import org.evomaster.core.problem.rest.data.HttpVerb
67
import org.evomaster.core.problem.rest.data.RestPath
@@ -10,13 +11,44 @@ import org.evomaster.core.search.gene.collection.ArrayGene
1011
import org.evomaster.core.search.gene.wrapper.CustomMutationRateGene
1112
import org.evomaster.core.search.gene.numeric.IntegerGene
1213
import org.evomaster.core.search.gene.string.StringGene
14+
import org.evomaster.core.search.gene.utils.GeneUtils
15+
import org.glassfish.jersey.uri.internal.JerseyUriBuilder
1316
import org.junit.jupiter.api.Assertions.*
1417
import org.junit.jupiter.api.Test
1518
import org.junit.jupiter.params.ParameterizedTest
1619
import org.junit.jupiter.params.provider.ValueSource
20+
import java.net.URISyntaxException
21+
import org.junit.jupiter.api.assertThrows
22+
import org.mockserver.configuration.Configuration.configuration
1723

1824
internal class RestPathTest{
1925

26+
@Test
27+
fun testFamilieBaSakIssue(){
28+
29+
val x = "/api/satsendring/kjorsatsendring?EMextraParam123=42/Trigget satsendring for fagsakene []"
30+
31+
assertThrows<Exception>{JerseyUriBuilder.fromUri(x).build()}
32+
33+
val path = RestPath("/api/satsendring/kjorsatsendring")
34+
val q = QueryParam("EMextraParam123", StringGene("EMextraParam123", "42/Trigget satsendring for fagsakene []"))
35+
36+
val uri = path.resolve(listOf(q))
37+
38+
assertNotEquals(x, uri)
39+
40+
JerseyUriBuilder.fromUri(uri).build()
41+
42+
// check escape
43+
//TODO update once fixing AbstractRestFitness
44+
val y = "/api/satsendring/kjorsatsendring/Trigget satsendring for fagsakene []"
45+
JerseyUriBuilder.fromUri(y).build()
46+
47+
val e = GeneUtils.applyEscapes(y, GeneUtils.EscapeMode.URI, OutputFormat.JAVA_JUNIT_4)
48+
//FIXME spaces are not escaped
49+
//assertNotEquals(y,e)
50+
}
51+
2052

2153
@Test
2254
fun testNameQualifier(){

0 commit comments

Comments
 (0)