Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -827,7 +827,7 @@ abstract class HttpWsTestCaseWriter : ApiTestCaseWriter() {
lines.indented {
lines.add("get(\"${verifier.stub}\")")
lines.indented {
lines.add(".withMetadata(Metadata.metadata().attr(\"ssrf\", \"${action.getName()}\"))")
lines.add(".withMetadata(Metadata.metadata().attr(SSRF_METADATA_TAG, \"${action.getName()}\"))")
lines.add(".atPriority(1)")
lines.add(".willReturn(")
lines.indented {
Expand Down Expand Up @@ -859,19 +859,11 @@ abstract class HttpWsTestCaseWriter : ApiTestCaseWriter() {
private fun handleCallbackVerifierRequests(lines: Lines, action: Action, verifier: ActionStubMapping, assertTrue: Boolean) {
if (assertTrue) {
lines.addSingleCommentLine("Verifying that the request is successfully made to HttpCallbackVerifier after test execution.")
lines.add("assertTrue(${verifier.getVerifierName()}")
lines.addStatement("assertTrue(verifierHasReceivedRequests(${verifier.getVerifierName()}, \"${action.getName()}\"))")
} else {
lines.addSingleCommentLine("Verifying that there are no requests made to HttpCallbackVerifier before test execution.")
lines.add("assertFalse(${verifier.getVerifierName()}")
lines.addStatement("assertFalse(verifierHasReceivedRequests(${verifier.getVerifierName()}, \"${action.getName()}\"))")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if this verifierHasReceivedRequests label is used more than once in the code, should be put in a val

}
lines.indented {
if (format.isKotlin()) {
lines.add(".allServeEvents")
lines.add(".filter { it.wasMatched && it.stubMapping.metadata != null }")
lines.add(".any { it.stubMapping.metadata.getString(\"ssrf\") == \"${action.getName()}\" }")
}
}
lines.add(")")
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -643,6 +643,7 @@ class TestSuiteWriter {
if (config.ssrf && solution.hasSsrfFaults()) {
httpCallbackVerifier.getActionVerifierMappings().forEach { v ->
addStatement("private static WireMockServer ${v.getVerifierName()}", lines)
addStatement("private static final String SSRF_METADATA_TAG = \"SSRF\"", lines)
}
}

Expand Down Expand Up @@ -674,7 +675,9 @@ class TestSuiteWriter {
if (config.ssrf && solution.hasSsrfFaults()) {
httpCallbackVerifier.getActionVerifierMappings().forEach { v ->
addStatement("private lateinit var ${v.getVerifierName()}: WireMockServer", lines)
addStatement("private const val SSRF_METADATA_TAG: String = \"SSRF\" ", lines)
}
assertionUtilFunctionForSSRF(lines, config.outputFormat)
}

if(config.problemType == EMConfig.ProblemType.WEBFRONTEND){
Expand Down Expand Up @@ -1036,6 +1039,10 @@ class TestSuiteWriter {

initTestMethod(solution, lines, testSuiteFileName)
lines.addEmpty(2)

if (config.ssrf && solution.hasSsrfFaults() && format.isJava()) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not used in Kotlin?

assertionUtilFunctionForSSRF(lines, config.outputFormat)
}
}


Expand Down Expand Up @@ -1144,4 +1151,36 @@ class TestSuiteWriter {
.toList()
}

private fun assertionUtilFunctionForSSRF(lines: Lines, format: OutputFormat) {
lines.addEmpty(1)

when {
format.isKotlin() -> {
lines.addSingleCommentLine("To verify whether the HttpCallbackVerifier has received any requests.")
lines.add("fun verifierHasReceivedRequests(verifier: WireMockServer, actionName: String) : Boolean")
}
format.isJava() -> {
lines.startCommentBlock()
lines.addBlockCommentLine("Method to verify whether the HttpCallbackVerifier has received any requests.")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why the comment for Java is different for the comment for Kotlin ???

lines.endCommentBlock()
lines.add("public static boolean verifierHasReceivedRequests(WireMockServer verifier, String actionName)")
}
}
lines.block {
lines.add("return verifier")
lines.indented {
if (format.isKotlin()) {
lines.add(".allServeEvents")
lines.add(".filter { it.wasMatched && it.stubMapping.metadata != null }")
lines.add(".any { it.stubMapping.metadata.getString(SSRF_METADATA_TAG) == actionName }")
}
if (format.isJava()) {
lines.add(".getAllServeEvents()")
lines.add(".stream().filter( r -> r.getWasMatched() && r.getStubMapping().getMetadata() != null)")
lines.add(".anyMatch( r -> r.getStubMapping().getMetadata().getString(SSRF_METADATA_TAG).equals(actionName));")
}
}
}
}

}