Skip to content

Commit db378aa

Browse files
committed
fixes
1 parent 6451428 commit db378aa

2 files changed

Lines changed: 17 additions & 7 deletions

File tree

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -859,10 +859,10 @@ abstract class HttpWsTestCaseWriter : ApiTestCaseWriter() {
859859
private fun handleCallbackVerifierRequests(lines: Lines, action: Action, verifier: ActionStubMapping, assertTrue: Boolean) {
860860
if (assertTrue) {
861861
lines.addSingleCommentLine("Verifying that the request is successfully made to HttpCallbackVerifier after test execution.")
862-
lines.add("assertTrue(verifierHasReceivedRequests(${verifier.getVerifierName()}, \"${action.getName()}\"))")
862+
lines.addStatement("assertTrue(verifierHasReceivedRequests(${verifier.getVerifierName()}, \"${action.getName()}\"))")
863863
} else {
864864
lines.addSingleCommentLine("Verifying that there are no requests made to HttpCallbackVerifier before test execution.")
865-
lines.add("assertFalse(verifierHasReceivedRequests(${verifier.getVerifierName()}, \"${action.getName()}\"))")
865+
lines.addStatement("assertFalse(verifierHasReceivedRequests(${verifier.getVerifierName()}, \"${action.getName()}\"))")
866866
}
867867
}
868868

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

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -643,6 +643,7 @@ class TestSuiteWriter {
643643
if (config.ssrf && solution.hasSsrfFaults()) {
644644
httpCallbackVerifier.getActionVerifierMappings().forEach { v ->
645645
addStatement("private static WireMockServer ${v.getVerifierName()}", lines)
646+
addStatement("private static final String SSRF_METADATA_TAG = \"SSRF\"", lines)
646647
}
647648
}
648649

@@ -676,6 +677,7 @@ class TestSuiteWriter {
676677
addStatement("private lateinit var ${v.getVerifierName()}: WireMockServer", lines)
677678
addStatement("private const val SSRF_METADATA_TAG: String = \"SSRF\" ", lines)
678679
}
680+
assertionUtilFunctionForSSRF(lines, config.outputFormat)
679681
}
680682

681683
if(config.problemType == EMConfig.ProblemType.WEBFRONTEND){
@@ -1038,7 +1040,7 @@ class TestSuiteWriter {
10381040
initTestMethod(solution, lines, testSuiteFileName)
10391041
lines.addEmpty(2)
10401042

1041-
if (config.ssrf && solution.hasSsrfFaults()) {
1043+
if (config.ssrf && solution.hasSsrfFaults() && format.isJava()) {
10421044
assertionUtilFunctionForSSRF(lines, config.outputFormat)
10431045
}
10441046
}
@@ -1150,15 +1152,18 @@ class TestSuiteWriter {
11501152
}
11511153

11521154
private fun assertionUtilFunctionForSSRF(lines: Lines, format: OutputFormat) {
1153-
lines.startCommentBlock()
1154-
lines.addBlockCommentLine("A method for verifying requests sent to HttpCallbackVerifier.")
1155-
lines.endCommentBlock()
1155+
lines.addEmpty(1)
1156+
11561157
when {
11571158
format.isKotlin() -> {
1159+
lines.addSingleCommentLine("To verify whether the HttpCallbackVerifier has received any requests.")
11581160
lines.add("fun verifierHasReceivedRequests(verifier: WireMockServer, actionName: String) : Boolean")
11591161
}
11601162
format.isJava() -> {
1161-
lines.add("public boolean verifierHasReceivedRequests(WireMockServer verifier, String actionName)")
1163+
lines.startCommentBlock()
1164+
lines.addBlockCommentLine("Method to verify whether the HttpCallbackVerifier has received any requests.")
1165+
lines.endCommentBlock()
1166+
lines.add("public static boolean verifierHasReceivedRequests(WireMockServer verifier, String actionName)")
11621167
}
11631168
}
11641169
lines.block {
@@ -1169,6 +1174,11 @@ class TestSuiteWriter {
11691174
lines.add(".filter { it.wasMatched && it.stubMapping.metadata != null }")
11701175
lines.add(".any { it.stubMapping.metadata.getString(SSRF_METADATA_TAG) == actionName }")
11711176
}
1177+
if (format.isJava()) {
1178+
lines.add(".getAllServeEvents()")
1179+
lines.add(".stream().filter( r -> r.getWasMatched() && r.getStubMapping().getMetadata() != null)")
1180+
lines.add(".anyMatch( r -> r.getStubMapping().getMetadata().getString(SSRF_METADATA_TAG).equals(actionName));")
1181+
}
11721182
}
11731183
}
11741184
}

0 commit comments

Comments
 (0)