Skip to content

Commit

Permalink
fake es for taint test
Browse files Browse the repository at this point in the history
  • Loading branch information
seran committed May 15, 2023
1 parent dbcbac8 commit 8346dd9
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<FooDto> fooDtoList = new ArrayList<>();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,4 @@ public void testRunEM() throws Throwable {
assertHasAtLeastOne(solution, HttpVerb.GET, 200, "/api/taint/collection","collection OK");
});
}
}
}
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -11,19 +16,32 @@

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 {

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",
Expand All @@ -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();
}
}

0 comments on commit 8346dd9

Please sign in to comment.