Skip to content

Commit 99da9d8

Browse files
authored
Merge pull request #132 from WebFuzzing/spring-rest-example-drivers
spring-rest-example drivers
2 parents f31e838 + b8aed70 commit 99da9d8

File tree

14 files changed

+935
-3
lines changed

14 files changed

+935
-3
lines changed

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ For simplicity, all schemas are also available as JSON/YML files under the folde
7070
> **IMPORTANT**: More details (e.g., #LOCs and used databases) on these APIs can be found [in this table](statistics/table_emb.md).
7171
7272

73-
### REST: Java/Kotlin (27)
73+
### REST: Java/Kotlin (28)
7474

7575
* **Bibliothek** (MIT), [jdk_17_gradle/cs/rest/bibliothek](jdk_17_gradle/cs/rest/bibliothek), from [https://github.com/PaperMC/bibliothek](https://github.com/PaperMC/bibliothek)
7676

@@ -120,6 +120,8 @@ For simplicity, all schemas are also available as JSON/YML files under the folde
120120

121121
* **Spring-batch-rest** (Apache), [jdk_8_maven/cs/rest/original/spring-batch-rest](jdk_8_maven/cs/rest/original/spring-batch-rest), from [https://github.com/chrisgleissner/spring-batch-rest](https://github.com/chrisgleissner/spring-batch-rest)
122122

123+
* **Spring Boot Restful API Example** (MIT), [jdk_17_maven/cs/rest/spring-rest-example](jdk_17_maven/cs/rest/spring-rest-example), from [https://github.com/phantasmicmeans/spring-boot-restful-api-example](https://github.com/phantasmicmeans/spring-boot-restful-api-example)
124+
123125
* **Tiltaksgjennomføring API** (MIT), [jdk_17_maven/cs/rest/tiltaksgjennomforing-api](jdk_17_maven/cs/rest/tiltaksgjennomforing-api), from [https://github.com/navikt/tiltaksgjennomforing-api](https://github.com/navikt/tiltaksgjennomforing-api)
124126

125127
* **User Management** (MIT), [jdk_8_maven/cs/rest/original/user-management](jdk_8_maven/cs/rest/original/user-management), from [https://github.com/andreagiassi/microservice-rbac-user-management](https://github.com/andreagiassi/microservice-rbac-user-management)
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
FROM amazoncorretto:17-alpine-jdk
2+
3+
COPY ./dist/spring-rest-example-sut.jar .
4+
COPY ./dist/jacocoagent.jar .
5+
6+
7+
8+
#ENV TOOL="undefined"
9+
#ENV RUN="0"
10+
11+
ENTRYPOINT \
12+
java \
13+
# unfortunately dumponexit is completely unreliable in Docker :(
14+
# -javaagent:jacocoagent.jar=destfile=./jacoco/spring-rest-example__${TOOL}__${RUN}__jacoco.exec,append=false,dumponexit=true \
15+
-javaagent:jacocoagent.jar=output=tcpserver,address=*,port=6300,append=false,dumponexit=false \
16+
-jar spring-rest-example-sut.jar \
17+
--server.port=8080 --spring.datasource.username=root --spring.datasource.password=root --spring.datasource.url="jdbc:mysql://db:3306/example?useSSL=false&allowPublicKeyRetrieval=true"
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
services:
2+
sut-spring-rest-example:
3+
build:
4+
dockerfile: ./dockerfiles/spring-rest-example.dockerfile
5+
context: ..
6+
# environment:
7+
# TOOL: ${TOOL:-undefined}
8+
# RUN: ${RUN:-0}
9+
ports:
10+
- "${HOST_PORT:-8080}:8080"
11+
- "${JACOCO_PORT:-6300}:6300"
12+
# volumes:
13+
# default env does not work on volumes
14+
# - ${JACOCODIR}:/jacoco
15+
depends_on:
16+
db:
17+
condition: service_healthy
18+
19+
db:
20+
image: mysql:8.0
21+
tmpfs:
22+
- '/var/lib/mysql'
23+
24+
25+
environment:
26+
MYSQL_ROOT_PASSWORD: root
27+
MYSQL_DATABASE: example
28+
29+
30+
31+
32+
healthcheck:
33+
test: ["CMD", "mysqladmin", "ping", "-h", "localhost"]
34+
interval: 30s
35+
timeout: 30s
36+
retries: 3
37+
38+

jdk_17_maven/em/embedded/rest/pom.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
<module>familie-ba-sak</module>
1616
<module>tiltaksgjennomforing-api</module>
1717
<module>ohsome-api</module>
18+
<module>spring-rest-example</module>
1819

1920

2021
<!-- <module>signal-server</module>-->
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<modelVersion>4.0.0</modelVersion>
6+
<parent>
7+
<groupId>org.evomaster</groupId>
8+
<artifactId>evomaster-benchmark-jdk17-em-embedded-rest</artifactId>
9+
<version>3.4.1-SNAPSHOT</version>
10+
</parent>
11+
12+
<artifactId>evomaster-benchmark-jdk17-em-embedded-rest-spring-rest-example</artifactId>
13+
<packaging>jar</packaging>
14+
15+
<dependencyManagement>
16+
<dependencies>
17+
<dependency>
18+
<groupId>org.springframework.boot</groupId>
19+
<artifactId>spring-boot-dependencies</artifactId>
20+
<version>3.0.4</version>
21+
<type>pom</type>
22+
<scope>import</scope>
23+
</dependency>
24+
</dependencies>
25+
</dependencyManagement>
26+
27+
<dependencies>
28+
<dependency>
29+
<groupId>com.example</groupId>
30+
<artifactId>spring-rest-example</artifactId>
31+
<version>0.0.1</version>
32+
</dependency>
33+
<dependency>
34+
<groupId>org.testcontainers</groupId>
35+
<artifactId>testcontainers</artifactId>
36+
<version>1.19.1</version>
37+
<scope>compile</scope>
38+
</dependency>
39+
</dependencies>
40+
41+
42+
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
1+
package em.embedded.com.example.spring;
2+
3+
import com.sw.project.ProjectApiApplication;
4+
import org.evomaster.client.java.controller.EmbeddedSutController;
5+
import org.evomaster.client.java.controller.InstrumentedSutStarter;
6+
import org.evomaster.client.java.controller.api.dto.SutInfoDto;
7+
import org.evomaster.client.java.controller.api.dto.auth.AuthenticationDto;
8+
import org.evomaster.client.java.controller.api.dto.database.schema.DatabaseType;
9+
import org.evomaster.client.java.controller.problem.ProblemInfo;
10+
import org.evomaster.client.java.controller.problem.RestProblem;
11+
import org.evomaster.client.java.sql.DbSpecification;
12+
import org.springframework.boot.SpringApplication;
13+
import org.springframework.context.ConfigurableApplicationContext;
14+
import org.springframework.jdbc.core.JdbcTemplate;
15+
import org.testcontainers.containers.GenericContainer;
16+
17+
import java.sql.Connection;
18+
import java.sql.SQLException;
19+
import java.util.*;
20+
21+
public class EmbeddedEvoMasterController extends EmbeddedSutController {
22+
23+
private static final GenericContainer mysql = new GenericContainer("mysql:8.0" )
24+
.withEnv(new HashMap<String, String>(){{
25+
put("MYSQL_ROOT_PASSWORD", "root");
26+
put("MYSQL_DATABASE", "example");
27+
}})
28+
.withExposedPorts(3306)
29+
.withTmpFs(Collections.singletonMap("/var/lib/mysql", "rw"));
30+
31+
private ConfigurableApplicationContext ctx;
32+
33+
private Connection sqlConnection;
34+
private List<DbSpecification> dbSpecification;
35+
36+
37+
public EmbeddedEvoMasterController() {
38+
this(40100);
39+
}
40+
41+
public EmbeddedEvoMasterController(int port) {
42+
setControllerPort(port);
43+
}
44+
45+
public static void main(String[] args) {
46+
int port = 40100;
47+
if (args.length > 0) {
48+
port = Integer.parseInt(args[0]);
49+
}
50+
51+
EmbeddedEvoMasterController controller = new EmbeddedEvoMasterController(port);
52+
InstrumentedSutStarter starter = new InstrumentedSutStarter(controller);
53+
54+
starter.start();
55+
}
56+
57+
@Override
58+
public boolean isSutRunning() {
59+
return ctx!=null && ctx.isRunning();
60+
}
61+
62+
@Override
63+
public String getPackagePrefixesToCover() {
64+
return "com.sw.project.";
65+
}
66+
67+
@Override
68+
public List<AuthenticationDto> getInfoForAuthentication() {
69+
return null;
70+
}
71+
72+
@Override
73+
public ProblemInfo getProblemInfo() {
74+
return new RestProblem(
75+
"http://localhost:" + getSutPort() + "/v3/api-docs",
76+
null
77+
);
78+
}
79+
80+
@Override
81+
public SutInfoDto.OutputFormat getPreferredOutputFormat() {
82+
return SutInfoDto.OutputFormat.JAVA_JUNIT_5;
83+
}
84+
85+
@Override
86+
public String startSut() {
87+
mysql.start();
88+
89+
String host = mysql.getContainerIpAddress();
90+
int port = mysql.getMappedPort(3306);
91+
String url = "jdbc:mysql://"+host+":"+port+"/example?useSSL=false&allowPublicKeyRetrieval=true";
92+
93+
ctx = SpringApplication.run(ProjectApiApplication.class, new String[]{
94+
"--server.port=0",
95+
"--spring.datasource.url="+url,
96+
"--spring.datasource.username=root",
97+
"--spring.datasource.password=root",
98+
"--management.server.port=-1",
99+
"--logging.level.root=OFF",
100+
"--logging.level.org.springframework=INFO"
101+
});
102+
103+
if (sqlConnection != null) {
104+
try {
105+
sqlConnection.close();
106+
} catch (SQLException e) {
107+
throw new RuntimeException(e);
108+
}
109+
}
110+
JdbcTemplate jdbc = ctx.getBean(JdbcTemplate.class);
111+
try {
112+
sqlConnection = jdbc.getDataSource().getConnection();
113+
} catch (SQLException e) {
114+
throw new RuntimeException(e);
115+
}
116+
117+
dbSpecification = Arrays.asList(new DbSpecification(DatabaseType.MYSQL,sqlConnection));
118+
119+
return "http://localhost:" + getSutPort();
120+
}
121+
122+
protected int getSutPort() {
123+
return (Integer) ((Map) ctx.getEnvironment()
124+
.getPropertySources().get("server.ports").getSource())
125+
.get("local.server.port");
126+
}
127+
128+
@Override
129+
public void stopSut() {
130+
ctx.stop();
131+
mysql.stop();
132+
}
133+
134+
@Override
135+
public void resetStateOfSUT() {
136+
}
137+
138+
@Override
139+
public List<DbSpecification> getDbSpecifications() {
140+
return dbSpecification;
141+
}
142+
}

jdk_17_maven/em/external/rest/pom.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
<module>familie-ba-sak</module>
1717
<module>tiltaksgjennomforing-api</module>
1818
<module>ohsome-api</module>
19+
<module>spring-rest-example</module>
1920
</modules>
2021

2122
</project>
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<modelVersion>4.0.0</modelVersion>
6+
<parent>
7+
<groupId>org.evomaster</groupId>
8+
<artifactId>evomaster-benchmark-jdk17-em-external-rest</artifactId>
9+
<version>3.4.1-SNAPSHOT</version>
10+
</parent>
11+
12+
<artifactId>evomaster-benchmark-jdk17-em-external-rest-spring-rest-example</artifactId>
13+
<packaging>jar</packaging>
14+
15+
16+
<dependencies>
17+
<dependency>
18+
<groupId>org.testcontainers</groupId>
19+
<artifactId>testcontainers</artifactId>
20+
<scope>compile</scope>
21+
</dependency>
22+
<dependency>
23+
<groupId>junit</groupId>
24+
<artifactId>junit</artifactId>
25+
<version>4.12</version>
26+
<scope>compile</scope>
27+
</dependency>
28+
<dependency>
29+
<groupId>mysql</groupId>
30+
<artifactId>mysql-connector-java</artifactId>
31+
<version>8.0.33</version>
32+
</dependency>
33+
</dependencies>
34+
35+
<build>
36+
<plugins>
37+
<plugin>
38+
<groupId>org.apache.maven.plugins</groupId>
39+
<artifactId>maven-shade-plugin</artifactId>
40+
<executions>
41+
<execution>
42+
<phase>package</phase>
43+
<goals>
44+
<goal>shade</goal>
45+
</goals>
46+
<configuration>
47+
<finalName>spring-rest-example-evomaster-runner</finalName>
48+
<transformers>
49+
<transformer
50+
implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
51+
<manifestEntries>
52+
<Main-Class>em.external.com.example.spring.ExternalEvoMasterController
53+
</Main-Class>
54+
<Premain-Class>org.evomaster.client.java.instrumentation.InstrumentingAgent
55+
</Premain-Class>
56+
<Agent-Class>org.evomaster.client.java.instrumentation.InstrumentingAgent
57+
</Agent-Class>
58+
<Can-Redefine-Classes>true</Can-Redefine-Classes>
59+
<Can-Retransform-Classes>true</Can-Retransform-Classes>
60+
</manifestEntries>
61+
</transformer>
62+
</transformers>
63+
</configuration>
64+
</execution>
65+
</executions>
66+
</plugin>
67+
</plugins>
68+
</build>
69+
70+
</project>

0 commit comments

Comments
 (0)