Skip to content

Commit

Permalink
Remove + and ====
Browse files Browse the repository at this point in the history
  • Loading branch information
sberyozkin committed Oct 12, 2023
1 parent d91871b commit d5e32b2
Showing 1 changed file with 22 additions and 48 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -398,10 +398,10 @@ For information about supported authentication options, see the xref:security-oi
[[integration-testing]]
=== Testing

You can choose between <<integration-testing-wiremock>>,<<integration-testing-oidc-test-client>>, <<integration-testing-keycloak-devservices>>, <<integration-testing-keycloak>>, <<integration-testing-public-key>> and <<integration-testing-security-annotation>> test options to test Quarkus endpoints expecting bearer access tokens.
You can choose between <<integration-testing-wiremock>>, <<integration-testing-oidc-test-client>>, <<integration-testing-keycloak-devservices>>, <<integration-testing-keycloak>>, <<integration-testing-public-key,Local public key>> and <<integration-testing-security-annotation>> test options to test Quarkus endpoints expecting bearer access tokens.

You can begin testing by adding the following dependencies to your test project:
====

[source,xml,role="primary asciidoc-tabs-target-sync-cli asciidoc-tabs-target-sync-maven"]
.pom.xml
----
Expand All @@ -423,19 +423,14 @@ You can begin testing by adding the following dependencies to your test project:
testImplementation("io.rest-assured:rest-assured")
testImplementation("io.quarkus:quarkus-junit5")
----
====

//@sberyozkin - It might be good to add a stament here about the different mechanisms or methods to integration testing. For example, WireMock... etc


[[integration-testing-wiremock]]
==== WireMock

You can also use link:https://wiremock.org/[WireMock] for integration testing.

. Add the following dependencies to your test project:
+
====

[source,xml,role="primary asciidoc-tabs-target-sync-cli asciidoc-tabs-target-sync-maven"]
.pom.xml
----
Expand All @@ -451,22 +446,19 @@ You can also use link:https://wiremock.org/[WireMock] for integration testing.
----
testImplementation("io.quarkus:quarkus-test-oidc-server")
----
====
+

. Prepare the REST test endpoint and set `application.properties`, as shown in the following example:
+
====

[source, properties]
----
# keycloak.url is set by OidcWiremockTestResource
quarkus.oidc.auth-server-url=${keycloak.url}/realms/quarkus/
quarkus.oidc.client-id=quarkus-service-app
quarkus.oidc.application-type=service
----
====

. Finally, write the test code, as shown in the following example:
+
====

[source, java]
----
import static org.hamcrest.Matchers.equalTo;
Expand Down Expand Up @@ -504,7 +496,7 @@ public class BearerTokenAuthorizationTest {
}
}
----
====

. The `quarkus-test-oidc-server` extension includes a signing RSA private key file in a `JSON Web Key` (`JWK`) format and points to it with a `smallrye.jwt.sign.key.location` configuration property.
You can sign the token by using a no-argument `sign()` operation.

Expand Down Expand Up @@ -626,8 +618,7 @@ Consider using xref:security-openid-connect-dev-services.adoc[Dev Services for K
Then, it will create a `quarkus` realm and a `quarkus-app` client (`secret` secret) and add `alice` (`admin` and `user` roles) and `bob` (`user` role) users, where all of these properties can be customized.

. First, add the following dependency, which provides a utility class `io.quarkus.test.keycloak.client.KeycloakTestClient` that you can use in tests for acquiring the access tokens:
+
====

[source,xml,role="primary asciidoc-tabs-target-sync-cli asciidoc-tabs-target-sync-maven"]
.pom.xml
----
Expand All @@ -637,37 +628,30 @@ Then, it will create a `quarkus` realm and a `quarkus-app` client (`secret` secr
<scope>test</scope>
</dependency>
----
====
+
====

[source,gradle,role="secondary asciidoc-tabs-target-sync-gradle"]
.build.gradle
----
testImplementation("io.quarkus:quarkus-test-keycloak-server")
----
====
+

. Next, prepare your `application.properties` configuration file.
You can start with an empty `application.properties` file because `Dev Services for Keycloak` registers `quarkus.oidc.auth-server-url` and points it to the running test container, `quarkus.oidc.client-id=quarkus-app`, and `quarkus.oidc.credentials.secret=secret`.
. *Optional*: If you have already configured the required `quarkus-oidc` properties, you will need only to associate `quarkus.oidc.auth-server-url` with the `prod` profile for `Dev Services for Keycloak` to start a container, as shown in the following example:
+
====

[source,properties]
----
%prod.quarkus.oidc.auth-server-url=http://localhost:8180/realms/quarkus
----
====
+

. If a custom realm file must be imported into Keycloak before running the tests, configure `Dev Services for Keycloak` as follows:
+
====

[source,properties]
----
%prod.quarkus.oidc.auth-server-url=http://localhost:8180/realms/quarkus
quarkus.keycloak.devservices.realm-path=quarkus-realm.json
----
====
+

. Finally, write your test, as outlined in the following examples:

.Example of a test executed in JVM mode:
Expand Down Expand Up @@ -720,7 +704,6 @@ public class NativeBearerTokenAuthenticationIT extends BearerTokenAuthentication
For more information about initializing and configuring Dev Services for Keycloak, see the xref:security-openid-connect-dev-services.adoc[Dev Services for Keycloak] guide.

[[integration-testing-keycloak]]

==== KeycloakTestResourceLifecycleManager


Expand All @@ -733,10 +716,8 @@ Where possible, use the method described in <<integration-testing-keycloak-devse

The following example provides `io.quarkus.test.keycloak.server.KeycloakTestResourceLifecycleManager`, which is an implementaton of `io.quarkus.test.common.QuarkusTestResourceLifecycleManager` that starts a Keycloak container.


. To start integration testing, add the following dependency:
+
====

[source,xml,role="primary asciidoc-tabs-target-sync-cli asciidoc-tabs-target-sync-maven"]
.pom.xml
----
Expand All @@ -752,11 +733,9 @@ The following example provides `io.quarkus.test.keycloak.server.KeycloakTestReso
----
testImplementation("io.quarkus:quarkus-test-keycloak-server")
----
====
+

. Configure the Maven Surefire plugin as follows, or similarly with `maven.failsafe.plugin` for native image testing:
+
====

[source,xml]
----
<plugin>
Expand All @@ -773,11 +752,9 @@ testImplementation("io.quarkus:quarkus-test-keycloak-server")
</configuration>
</plugin>
----
====
+

. Prepare the REST test endpoint and set `application.properties` as outlined in the following example:
+
====

[source, properties]
----
# keycloak.url is set by KeycloakTestResourceLifecycleManager
Expand All @@ -786,11 +763,9 @@ quarkus.oidc.client-id=quarkus-service-app
quarkus.oidc.credentials=secret
quarkus.oidc.application-type=service
----
====
+

. Finally, write the test code, for example:
+
====

[source, java]
----
import static io.quarkus.test.keycloak.server.KeycloakTestResourceLifecycleManager.getAccessToken;
Expand Down Expand Up @@ -820,7 +795,6 @@ public class BearerTokenAuthorizationTest {
}
----
====

.Summary

Expand Down

0 comments on commit d5e32b2

Please sign in to comment.