-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #14173 from cemnura/feature/oidc-wiremock-codeflow
Added CodeFlowAuthorizationTest
- Loading branch information
Showing
6 changed files
with
183 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
integration-tests/oidc-wiremock/src/main/java/io/quarkus/it/keycloak/CodeFlowResource.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package io.quarkus.it.keycloak; | ||
|
||
import javax.inject.Inject; | ||
import javax.ws.rs.GET; | ||
import javax.ws.rs.Path; | ||
|
||
import io.quarkus.security.Authenticated; | ||
import io.quarkus.security.identity.SecurityIdentity; | ||
|
||
@Path("/code-flow") | ||
@Authenticated | ||
public class CodeFlowResource { | ||
|
||
@Inject | ||
SecurityIdentity identity; | ||
|
||
@GET | ||
public String access() { | ||
return identity.getPrincipal().getName(); | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
...ration-tests/oidc-wiremock/src/main/java/io/quarkus/it/keycloak/CustomTenantResolver.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package io.quarkus.it.keycloak; | ||
|
||
import javax.enterprise.context.ApplicationScoped; | ||
|
||
import io.quarkus.oidc.TenantResolver; | ||
import io.vertx.ext.web.RoutingContext; | ||
|
||
@ApplicationScoped | ||
public class CustomTenantResolver implements TenantResolver { | ||
|
||
@Override | ||
public String resolve(RoutingContext context) { | ||
String path = context.normalisedPath(); | ||
if (path.endsWith("code-flow")) { | ||
return "code-flow"; | ||
} | ||
return null; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
...n-tests/oidc-wiremock/src/test/java/io/quarkus/it/keycloak/CodeFlowAuthorizationTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package io.quarkus.it.keycloak; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
import java.io.IOException; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import com.gargoylesoftware.htmlunit.SilentCssErrorHandler; | ||
import com.gargoylesoftware.htmlunit.WebClient; | ||
import com.gargoylesoftware.htmlunit.html.HtmlForm; | ||
import com.gargoylesoftware.htmlunit.html.HtmlPage; | ||
|
||
import io.quarkus.test.common.QuarkusTestResource; | ||
import io.quarkus.test.junit.QuarkusTest; | ||
|
||
@QuarkusTest | ||
@QuarkusTestResource(KeycloakTestResource.class) | ||
public class CodeFlowAuthorizationTest { | ||
|
||
@Test | ||
public void testCodeFlow() throws IOException { | ||
try (final WebClient webClient = createWebClient()) { | ||
webClient.getOptions().setRedirectEnabled(true); | ||
HtmlPage page = webClient.getPage("http://localhost:8081/code-flow"); | ||
|
||
HtmlForm form = page.getFormByName("form"); | ||
form.getInputByName("username").type("alice"); | ||
form.getInputByName("password").type("alice"); | ||
|
||
page = form.getInputByValue("login").click(); | ||
|
||
assertEquals("alice", page.getBody().asText()); | ||
} | ||
} | ||
|
||
private WebClient createWebClient() { | ||
WebClient webClient = new WebClient(); | ||
webClient.setCssErrorHandler(new SilentCssErrorHandler()); | ||
return webClient; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters