Skip to content

Commit 8355a48

Browse files
committed
working commit
1 parent fd7c5e7 commit 8355a48

2 files changed

Lines changed: 39 additions & 26 deletions

File tree

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

Lines changed: 13 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -859,34 +859,21 @@ 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(${verifier.getVerifierName()}")
862+
lines.add("assertTrue(callbackVerifierHasServed(${verifier.getVerifierName()}, \"${action.getName()}\"))")
863+
// lines.add("assertTrue(${verifier.getVerifierName()}")
863864
} else {
864865
lines.addSingleCommentLine("Verifying that there are no requests made to HttpCallbackVerifier before test execution.")
865-
lines.add("assertFalse(${verifier.getVerifierName()}")
866-
}
867-
lines.indented {
868-
if (format.isKotlin()) {
869-
lines.add(".allServeEvents")
870-
lines.add(".filter { it.wasMatched && it.stubMapping.metadata != null }")
871-
lines.add(".any { it.stubMapping.metadata.getString(\"ssrf\") == \"${action.getName()}\" }")
872-
}
873-
}
874-
lines.add(")")
875-
}
876-
877-
private fun ssrfAssertionsUtilFunction(lines: Lines, action: Action, verifier: ActionStubMapping, assertTrue: Boolean) {
878-
// TODO: Add function
879-
// lines.add()
880-
lines.indented {
881-
lines.add(verifier.getVerifierName())
882-
lines.indented {
883-
if (format.isKotlin()) {
884-
lines.add(".allServeEvents")
885-
lines.add(".filter { it.wasMatched && it.stubMapping.metadata != null }")
886-
lines.add(".any { it.stubMapping.metadata.getString(\"ssrf\") == \"${action.getName()}\" }")
887-
}
888-
}
889-
}
866+
// lines.add("assertFalse(${verifier.getVerifierName()}")
867+
lines.add("assertFalse(callbackVerifierHasServed(${verifier.getVerifierName()}, \"${action.getName()}\"))")
868+
}
869+
// lines.indented {
870+
// if (format.isKotlin()) {
871+
// lines.add(".allServeEvents")
872+
// lines.add(".filter { it.wasMatched && it.stubMapping.metadata != null }")
873+
// lines.add(".any { it.stubMapping.metadata.getString(\"ssrf\") == \"${action.getName()}\" }")
874+
// }
875+
// }
876+
// lines.add(")")
890877
}
891878

892879
}

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

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1036,6 +1036,10 @@ class TestSuiteWriter {
10361036

10371037
initTestMethod(solution, lines, testSuiteFileName)
10381038
lines.addEmpty(2)
1039+
1040+
if (config.ssrf && solution.hasSsrfFaults()) {
1041+
ssrfAssertionsUtilFunction(lines, config.outputFormat)
1042+
}
10391043
}
10401044

10411045

@@ -1144,4 +1148,26 @@ class TestSuiteWriter {
11441148
.toList()
11451149
}
11461150

1151+
private fun ssrfAssertionsUtilFunction(lines: Lines, format: OutputFormat) {
1152+
// lines.addBlockCommentLine()
1153+
when {
1154+
format.isKotlin() -> {
1155+
lines.add("fun callbackVerifierHasServed(verifier: WireMockServer, actionName: String) : Boolean")
1156+
}
1157+
format.isJava() -> {
1158+
lines.add("public boolean callbackVerifierHasServed(WireMockServer verifier, String actionName)")
1159+
}
1160+
}
1161+
lines.block {
1162+
lines.add("return verifier")
1163+
lines.indented {
1164+
if (format.isKotlin()) {
1165+
lines.add(".allServeEvents")
1166+
lines.add(".filter { it.wasMatched && it.stubMapping.metadata != null }")
1167+
lines.add(".any { it.stubMapping.metadata.getString(\"ssrf\") == actionName }")
1168+
}
1169+
}
1170+
}
1171+
}
1172+
11471173
}

0 commit comments

Comments
 (0)