From 8346dd990b1f7045a48d1803105f7a9b7a3904f9 Mon Sep 17 00:00:00 2001 From: seran <7030273+seran@users.noreply.github.com> Date: Mon, 15 May 2023 14:57:36 +0200 Subject: [PATCH] fake es for taint test --- .../spring/taintcast/TaintCastRest.java | 2 +- .../spring/examples/taint/TaintEMTest.java | 2 +- .../examples/taintcast/TaintCastEMTest.java | 27 ++++++++++++++++--- 3 files changed, 26 insertions(+), 5 deletions(-) diff --git a/e2e-tests/spring-rest-openapi-v2/src/main/java/com/foo/rest/examples/spring/taintcast/TaintCastRest.java b/e2e-tests/spring-rest-openapi-v2/src/main/java/com/foo/rest/examples/spring/taintcast/TaintCastRest.java index 71ed4e7523..f76990a89f 100644 --- a/e2e-tests/spring-rest-openapi-v2/src/main/java/com/foo/rest/examples/spring/taintcast/TaintCastRest.java +++ b/e2e-tests/spring-rest-openapi-v2/src/main/java/com/foo/rest/examples/spring/taintcast/TaintCastRest.java @@ -24,7 +24,7 @@ public String getTaintedArray(){ RestTemplate restTemplate = new RestTemplate(); ObjectMapper mapper = new ObjectMapper(); - FooList list = restTemplate.postForObject("http://mock.local/api/fetch", ids, FooList.class); + FooList list = restTemplate.postForObject("http://mock.local:13579/api/fetch", ids, FooList.class); List fooDtoList = new ArrayList<>(); diff --git a/e2e-tests/spring-rest-openapi-v2/src/test/java/org/evomaster/e2etests/spring/examples/taint/TaintEMTest.java b/e2e-tests/spring-rest-openapi-v2/src/test/java/org/evomaster/e2etests/spring/examples/taint/TaintEMTest.java index 434b8bb30e..f7b10e6e5a 100644 --- a/e2e-tests/spring-rest-openapi-v2/src/test/java/org/evomaster/e2etests/spring/examples/taint/TaintEMTest.java +++ b/e2e-tests/spring-rest-openapi-v2/src/test/java/org/evomaster/e2etests/spring/examples/taint/TaintEMTest.java @@ -44,4 +44,4 @@ public void testRunEM() throws Throwable { assertHasAtLeastOne(solution, HttpVerb.GET, 200, "/api/taint/collection","collection OK"); }); } -} \ No newline at end of file +} diff --git a/e2e-tests/spring-rest-openapi-v2/src/test/java/org/evomaster/e2etests/spring/examples/taintcast/TaintCastEMTest.java b/e2e-tests/spring-rest-openapi-v2/src/test/java/org/evomaster/e2etests/spring/examples/taintcast/TaintCastEMTest.java index 38c7651e37..fca98a0fde 100644 --- a/e2e-tests/spring-rest-openapi-v2/src/test/java/org/evomaster/e2etests/spring/examples/taintcast/TaintCastEMTest.java +++ b/e2e-tests/spring-rest-openapi-v2/src/test/java/org/evomaster/e2etests/spring/examples/taintcast/TaintCastEMTest.java @@ -1,6 +1,11 @@ package org.evomaster.e2etests.spring.examples.taintcast; +import com.alibaba.dcm.DnsCacheManipulator; import com.foo.rest.examples.spring.taintcast.TaintCastController; +import com.github.tomakehurst.wiremock.WireMockServer; +import com.github.tomakehurst.wiremock.client.WireMock; +import com.github.tomakehurst.wiremock.core.WireMockConfiguration; +import com.github.tomakehurst.wiremock.extension.responsetemplating.ResponseTemplateTransformer; import org.evomaster.core.EMConfig; import org.evomaster.core.problem.rest.HttpVerb; import org.evomaster.core.problem.rest.RestIndividual; @@ -11,7 +16,7 @@ import static org.junit.jupiter.api.Assertions.assertTrue; -public class TaintCastEMTest extends SpringTestBase{ +public class TaintCastEMTest extends SpringTestBase { @BeforeAll public static void initClass() throws Exception { @@ -19,11 +24,24 @@ public static void initClass() throws Exception { TaintCastController taintCastController = new TaintCastController(); EMConfig config = new EMConfig(); config.setInstrumentMR_NET(true); - SpringTestBase.initClass(taintCastController,config); + SpringTestBase.initClass(taintCastController, config); } @Test public void testRunEM() throws Throwable { + WireMockConfiguration wmConfig = new WireMockConfiguration() + .bindAddress("127.0.0.1") + .port(13579) + .extensions(new ResponseTemplateTransformer(false)); + + WireMockServer wm = new WireMockServer(wmConfig); + wm.start(); + wm.stubFor(WireMock.post(WireMock.urlEqualTo("/api/fetch")) + .atPriority(1) + .willReturn(WireMock.aResponse().withStatus(200) + .withBody("{\"results\": [{\"id\": \"9fLSZFMq\",\"name\": \"sample-1\"},{\"id\": \"9fLSZFMq\",\"name\": \"sample-1\"}]}"))); + + DnsCacheManipulator.setDnsCache("mock.int", "127.0.0.1"); runTestHandlingFlakyAndCompilation( "TaintCastEM", @@ -41,7 +59,10 @@ public void testRunEM() throws Throwable { assertTrue(solution.getIndividuals().size() >= 1); - assertHasAtLeastOne(solution, HttpVerb.GET, 200, "/api/taint/cast","OK"); + assertHasAtLeastOne(solution, HttpVerb.GET, 200, "/api/taint/cast", "OK"); }); + + wm.shutdown(); + DnsCacheManipulator.clearDnsCache(); } }