-
Notifications
You must be signed in to change notification settings - Fork 2.7k
/
OidcTokenReactivePropagationTest.java
59 lines (44 loc) · 1.87 KB
/
OidcTokenReactivePropagationTest.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package io.quarkus.it.keycloak;
import static org.junit.jupiter.api.Assertions.assertEquals;
import org.junit.jupiter.api.Test;
import com.gargoylesoftware.htmlunit.SilentCssErrorHandler;
import com.gargoylesoftware.htmlunit.TextPage;
import com.gargoylesoftware.htmlunit.WebClient;
import com.gargoylesoftware.htmlunit.html.HtmlForm;
import com.gargoylesoftware.htmlunit.html.HtmlPage;
import io.quarkus.test.junit.QuarkusTest;
import io.restassured.RestAssured;
@QuarkusTest
public class OidcTokenReactivePropagationTest {
@Test
public void testGetUserNameWithAccessTokenPropagation() throws Exception {
try (final WebClient webClient = createWebClient()) {
HtmlPage page = webClient.getPage("http://localhost:8081/frontend/access-token-propagation");
assertEquals("Sign in to quarkus", page.getTitleText());
HtmlForm loginForm = page.getForms().get(0);
loginForm.getInputByName("username").setValueAttribute("alice");
loginForm.getInputByName("password").setValueAttribute("alice");
TextPage textPage = loginForm.getInputByName("login").click();
assertEquals("alice", textPage.getContent());
webClient.getCookieManager().clearCookies();
}
}
@Test
public void testNoToken() {
RestAssured.given().when().redirects().follow(false)
.get("/frontend/access-token-propagation")
.then()
.statusCode(302);
}
private WebClient createWebClient() throws Exception {
WebClient webClient = new WebClient();
webClient.setCssErrorHandler(new SilentCssErrorHandler());
return webClient;
}
@Test
public void testGetUserNameWithServiceWithoutToken() {
RestAssured.when().get("/frontend/service-without-token")
.then()
.statusCode(500);
}
}