Skip to content

Commit eb3b3dd

Browse files
committed
test: mock smtp server for reset events
1 parent 8f588af commit eb3b3dd

3 files changed

Lines changed: 25 additions & 1 deletion

File tree

pom.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,12 @@
5757
</exclusion>
5858
</exclusions>
5959
</dependency>
60+
<dependency>
61+
<groupId>org.subethamail</groupId>
62+
<artifactId>subethasmtp</artifactId>
63+
<version>3.1.7</version>
64+
<scope>test</scope>
65+
</dependency>
6066
<dependency>
6167
<groupId>com.github.dasniko</groupId>
6268
<artifactId>testcontainers-keycloak</artifactId>

src/test/java/fr/cnieg/keycloak/providers/login/attribute/KeycloakLoginAttributeProviderTest.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
import io.restassured.common.mapper.TypeRef;
1010
import io.restassured.http.ContentType;
1111
import org.junit.jupiter.api.*;
12+
import org.subethamail.wiser.Wiser;
13+
import org.testcontainers.Testcontainers;
1214
import org.testcontainers.junit.jupiter.Container;
1315
import org.testcontainers.junit.jupiter.Testcontainers;
1416

@@ -27,6 +29,12 @@
2729

2830
@Testcontainers
2931
class KeycloakLoginAttributeProviderTest {
32+
private static final int SMTP_PORT = 2525;
33+
34+
static {
35+
Testcontainers.exposeHostPorts(SMTP_PORT);
36+
}
37+
3038
@Container
3139
private static final KeycloakContainer KEYCLOAK_CONTAINER = new KeycloakContainer()
3240
.withAdminUsername("admin")
@@ -36,18 +44,23 @@ class KeycloakLoginAttributeProviderTest {
3644
private static Playwright playwright;
3745
private static Browser browser;
3846
private static KeycloakEventsClient eventsClient;
47+
private static Wiser smtpServer;
3948
BrowserContext context;
4049
Page page;
4150

4251
@BeforeAll
4352
static void launchBrowser() {
53+
smtpServer = new Wiser();
54+
smtpServer.setPort(SMTP_PORT);
55+
smtpServer.start();
4456
playwright = Playwright.create();
4557
browser = playwright.chromium().launch();
4658
eventsClient = new KeycloakEventsClient(KEYCLOAK_CONTAINER, "testloginattribute");
4759
}
4860

4961
@AfterAll
5062
static void closeBrowser() {
63+
smtpServer.stop();
5164
playwright.close();
5265
}
5366

src/test/resources/testloginattribute-realm.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1125,7 +1125,12 @@
11251125
"xXSSProtection" : "1; mode=block",
11261126
"strictTransportSecurity" : "max-age=31536000; includeSubDomains"
11271127
},
1128-
"smtpServer" : { },
1128+
"smtpServer" : {
1129+
"host" : "host.testcontainers.internal",
1130+
"port" : "2525",
1131+
"from" : "noreply@example.test",
1132+
"fromDisplayName" : "Keycloak Test"
1133+
},
11291134
"eventsEnabled" : true,
11301135
"eventsListeners" : [ "jboss-logging" ],
11311136
"enabledEventTypes" : [ ],

0 commit comments

Comments
 (0)