Skip to content

Commit 20f8db7

Browse files
committed
test(authorization): Optimize authorization tests
When installing the Keycloak extension, drop the `createRealmPerTest` flag per default. The additional isolation is no longer needed for most tests, since no roles or other data in Keycloak are manipulated during test execution, and an initial setup of test users used by the test cases is sufficient. For tests that do manipulate the state in Keycloak, support enabling this feature on demand. Avoiding the repeated setup of the realm saves a few seconds for every test case, which has a notable effect on the total test execution times. Signed-off-by: Oliver Heger <[email protected]>
1 parent 3bc17b1 commit 20f8db7

File tree

3 files changed

+12
-4
lines changed

3 files changed

+12
-4
lines changed

core/src/test/kotlin/api/AbstractIntegrationTest.kt

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,18 @@ import org.eclipse.apoapsis.ortserver.secrets.SecretsProviderFactoryForTesting
5656
import org.eclipse.apoapsis.ortserver.utils.logging.runBlocking
5757

5858
@Suppress("UnnecessaryAbstractClass")
59-
abstract class AbstractIntegrationTest(body: AbstractIntegrationTest.() -> Unit) : WordSpec() {
59+
abstract class AbstractIntegrationTest(
60+
body: AbstractIntegrationTest.() -> Unit,
61+
62+
/**
63+
* A flag indicating whether a new Keycloak realm should be created for each test. This should be set to *true* for
64+
* test classes that manipulate the Keycloak realm during text execution.
65+
*/
66+
createKeycloakRealmPerTest: Boolean = false
67+
) : WordSpec() {
6068
val dbExtension = extension(DatabaseTestExtension())
6169

62-
val keycloak = install(KeycloakTestExtension(createRealmPerTest = true)) {
70+
val keycloak = install(KeycloakTestExtension(createRealmPerTest = createKeycloakRealmPerTest)) {
6371
setUpUser(SUPERUSER, SUPERUSER_PASSWORD)
6472
setUpUser(TEST_USER, TEST_USER_PASSWORD)
6573
setUpClientScope(TEST_SUBJECT_CLIENT)

core/src/test/kotlin/api/AdminRouteIntegrationTest.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -258,4 +258,4 @@ class AdminRouteIntegrationTest : AbstractIntegrationTest({
258258
}
259259
}
260260
}
261-
})
261+
}, createKeycloakRealmPerTest = true)

shared/ktor-utils/src/testFixtures/kotlin/AbstractAuthorizationTest.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ private const val TEST_USER_PASSWORD = "password"
8383
@Suppress("UnnecessaryAbstractClass")
8484
abstract class AbstractAuthorizationTest(body: AbstractAuthorizationTest.() -> Unit) : WordSpec() {
8585
val dbExtension = DatabaseTestExtension()
86-
val keycloakExtension = KeycloakTestExtension(createRealmPerTest = true)
86+
val keycloakExtension = KeycloakTestExtension()
8787

8888
// The "extension()" and "install()" functions cannot be used above because of
8989
// https://github.com/kotest/kotest/issues/3555.

0 commit comments

Comments
 (0)