Skip to content

Commit ace1a0a

Browse files
committed
First attempt to add JWT tokens to bibliothek.
1 parent c0cd319 commit ace1a0a

1 file changed

Lines changed: 29 additions & 1 deletion

File tree

jdk_17_gradle/em/embedded/rest/bibliothek/src/main/java/em/embedded/bibliothek/EmbeddedEvoMasterController.java

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import com.mongodb.client.MongoClient;
44
import com.mongodb.client.MongoClients;
55
import io.papermc.bibliothek.BibliothekApplication;
6+
import org.evomaster.client.java.controller.AuthUtils;
67
import org.evomaster.client.java.controller.EmbeddedSutController;
78
import org.evomaster.client.java.controller.InstrumentedSutStarter;
89
import org.evomaster.client.java.controller.api.dto.auth.AuthenticationDto;
@@ -13,8 +14,11 @@
1314
import org.springframework.boot.SpringApplication;
1415
import org.springframework.context.ConfigurableApplicationContext;
1516
import org.testcontainers.containers.GenericContainer;
17+
import org.testcontainers.containers.startupcheck.OneShotStartupCheckStrategy;
1618

1719

20+
import java.time.Duration;
21+
import java.util.Arrays;
1822
import java.util.List;
1923
import java.util.Map;
2024
import java.util.Collections;
@@ -52,6 +56,7 @@ public static void main(String[] args) {
5256
private static final GenericContainer mongodbContainer = new GenericContainer("mongo:" + MONGODB_VERSION)
5357
.withTmpFs(Collections.singletonMap("/data/db", "rw"))
5458
.withExposedPorts(MONGODB_PORT);
59+
// .withStartupCheckStrategy(new OneShotStartupCheckStrategy().withTimeout(Duration.ofSeconds(90)));
5560

5661
private String mongoDbUrl;
5762

@@ -70,9 +75,11 @@ public EmbeddedEvoMasterController(int port) {
7075
public String startSut() {
7176

7277
mongodbContainer.start();
78+
7379
mongoDbUrl = "mongodb://" + mongodbContainer.getContainerIpAddress() + ":" + mongodbContainer.getMappedPort(MONGODB_PORT) + "/" + MONGODB_DATABASE_NAME;
7480
mongoClient = MongoClients.create(mongoDbUrl);
7581

82+
//mongodbContainer.setStartupCheckStrategy( new OneShotStartupCheckStrategy() );
7683

7784

7885
ctx = SpringApplication.run(BibliothekApplication.class,
@@ -125,7 +132,28 @@ public List<DbSpecification> getDbSpecifications() {
125132
@Override
126133
public List<AuthenticationDto> getInfoForAuthentication() {
127134
//TODO might need to setup JWT headers here
128-
return null;
135+
System.out.println("HERE");
136+
137+
// @Onur Setting JWT Authentication here.
138+
return Arrays.asList(
139+
AuthUtils.getForJWT(
140+
"User1",
141+
"/api/auth_token/auth1",
142+
"""
143+
{"userId": "User1", "password":"User1_Password123"}
144+
""".trim().stripIndent(),
145+
"/token/authToken1"),
146+
AuthUtils.getForJWT(
147+
"User2",
148+
"/api/auth_token/auth2",
149+
"""
150+
{"userId": "User2", "password":"User2_Password456"}
151+
""".trim().stripIndent(),
152+
"/token/authToken2")
153+
);
154+
155+
156+
//return null;
129157
}
130158

131159

0 commit comments

Comments
 (0)