Using testImplementation "com.github.dasniko:testcontainers-keycloak:2.5.0" and testImplementation "io.rest-assured:rest-assured:5.3.0" for keycloak version 21.1.1.
I am trying to import a realm during the tests. I use testcontainers-keycloak with the following way:
KeycloakContainer keycloak = new KeycloakContainer("quay.io/keycloak/keycloak:21.1.1")
.withRealmImportFile(realmImportFile)
// this would normally be just "target/classes"
.withProviderClassesFrom("target/test-classes");
On the command keycloak.start an exception is thrown with the error "caused by: java.lang.IllegalArgumentException: Resource with path". When i click on the path the json file is in the right position and i can read it.
It doesn't matter if the realm is like the following or a more complex one.
{
"id": "myrealm",
"realm": "myrealm",
"enabled": true,
"loginWithEmailAllowed": true,
"resetPasswordAllowed": true
}
The behavior is the same.
The exact above command without withRealmImportFile(realmImportFile), it runs as expected.
Version
2.5.0
Expected behavior
The realm should be imported and the keycloak container should start and read the setting of the realm
Actual behavior
I am trying to import a realm during the tests. I use testcontainers-keycloak with the following way:
KeycloakContainer keycloak = new KeycloakContainer("quay.io/keycloak/keycloak:21.1.1")
.withRealmImportFile(realmImportFile)
// this would normally be just "target/classes"
.withProviderClassesFrom("target/test-classes");
keycloak.start();
On the command keycloak.start an exception is thrown with the error "caused by: java.lang.IllegalArgumentException: Resource with path". When i click on the path the json file is in the right position and i can read it.
It doesn't matter if the realm is like the following or a more complex one.
{
"id": "myrealm",
"realm": "myrealm",
"enabled": true,
"loginWithEmailAllowed": true,
"resetPasswordAllowed": true
}
This starts the container
KeycloakContainer keycloak = new KeycloakContainer("quay.io/keycloak/keycloak:21.1.1")
// this would normally be just "target/classes"
.withProviderClassesFrom("target/test-classes");
keycloak.start();
How to Reproduce?
I got the json file from the flistones and just tried to run similar test with testcontainers for keycloak with keycloak version 21.1.1
Relevant log output
Container startup failed
org.testcontainers.containers.ContainerLaunchException: Container startup failed
at app//org.testcontainers.containers.GenericContainer.doStart(GenericContainer.java:349)
at app//org.testcontainers.containers.GenericContainer.start(GenericContainer.java:322)
at app//org.testcontainers.junit.jupiter.TestcontainersExtension$StoreAdapter.start(TestcontainersExtension.java:242)
at app//org.testcontainers.junit.jupiter.TestcontainersExtension$StoreAdapter.access$200(TestcontainersExtension.java:229)
at app//org.testcontainers.junit.jupiter.TestcontainersExtension.lambda$null$1(TestcontainersExtension.java:56)
at app//org.junit.jupiter.engine.execution.ExtensionValuesStore.lambda$getOrComputeIfAbsent$4(ExtensionValuesStore.java:86)
at app//org.junit.jupiter.engine.execution.ExtensionValuesStore$MemoizingSupplier.computeValue(ExtensionValuesStore.java:223)
at app//org.junit.jupiter.engine.execution.ExtensionValuesStore$MemoizingSupplier.get(ExtensionValuesStore.java:211)
at app//org.junit.jupiter.engine.execution.ExtensionValuesStore$StoredValue.evaluate(ExtensionValuesStore.java:191)
at app//org.junit.jupiter.engine.execution.ExtensionValuesStore$StoredValue.access$100(ExtensionValuesStore.java:171)
at app//org.junit.jupiter.engine.execution.ExtensionValuesStore.getOrComputeIfAbsent(ExtensionValuesStore.java:89)
at app//org.junit.jupiter.engine.execution.NamespaceAwareStore.getOrComputeIfAbsent(NamespaceAwareStore.java:53)
at app//org.testcontainers.junit.jupiter.TestcontainersExtension.lambda$beforeAll$2(TestcontainersExtension.java:56)
at java.base@17.0.3/java.util.ArrayList.forEach(ArrayList.java:1511)
at app//org.testcontainers.junit.jupiter.TestcontainersExtension.beforeAll(TestcontainersExtension.java:55)
at app//org.junit.jupiter.engine.descriptor.ClassBasedTestDescriptor.lambda$invokeBeforeAllCallbacks$12(ClassBasedTestDescriptor.java:395)
at app//org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
at app//org.junit.jupiter.engine.descriptor.ClassBasedTestDescriptor.invokeBeforeAllCallbacks(ClassBasedTestDescriptor.java:395)
at app//org.junit.jupiter.engine.descriptor.ClassBasedTestDescriptor.before(ClassBasedTestDescriptor.java:211)
at app//org.junit.jupiter.engine.descriptor.ClassBasedTestDescriptor.before(ClassBasedTestDescriptor.java:84)
at app//org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$6(NodeTestTask.java:148)
at app//org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
at app//org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$8(NodeTestTask.java:141)
at app//org.junit.platform.engine.support.hierarchical.Node.around(Node.java:137)
at app//org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$9(NodeTestTask.java:139)
at app//org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
at app//org.junit.platform.engine.support.hierarchical.NodeTestTask.executeRecursively(NodeTestTask.java:138)
at app//org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:95)
at java.base@17.0.3/java.util.ArrayList.forEach(ArrayList.java:1511)
at app//org.junit.platform.engine.support.hierarchical.SameThreadHierarchicalTestExecutorService.invokeAll(SameThreadHierarchicalTestExecutorService.java:41)
at app//org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$6(NodeTestTask.java:155)
at app//org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
at app//org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$8(NodeTestTask.java:141)
at app//org.junit.platform.engine.support.hierarchical.Node.around(Node.java:137)
at app//org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$9(NodeTestTask.java:139)
at app//org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
at app//org.junit.platform.engine.support.hierarchical.NodeTestTask.executeRecursively(NodeTestTask.java:138)
at app//org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:95)
at app//org.junit.platform.engine.support.hierarchical.SameThreadHierarchicalTestExecutorService.submit(SameThreadHierarchicalTestExecutorService.java:35)
at app//org.junit.platform.engine.support.hierarchical.HierarchicalTestExecutor.execute(HierarchicalTestExecutor.java:57)
at app//org.junit.platform.engine.support.hierarchical.HierarchicalTestEngine.execute(HierarchicalTestEngine.java:54)
at app//org.junit.platform.launcher.core.EngineExecutionOrchestrator.execute(EngineExecutionOrchestrator.java:107)
at app//org.junit.platform.launcher.core.EngineExecutionOrchestrator.execute(EngineExecutionOrchestrator.java:88)
at app//org.junit.platform.launcher.core.EngineExecutionOrchestrator.lambda$execute$0(EngineExecutionOrchestrator.java:54)
at app//org.junit.platform.launcher.core.EngineExecutionOrchestrator.withInterceptedStreams(EngineExecutionOrchestrator.java:67)
at app//org.junit.platform.launcher.core.EngineExecutionOrchestrator.execute(EngineExecutionOrchestrator.java:52)
at app//org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:114)
at app//org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:86)
at app//org.junit.platform.launcher.core.DefaultLauncherSession$DelegatingLauncher.execute(DefaultLauncherSession.java:86)
at org.gradle.api.internal.tasks.testing.junitplatform.JUnitPlatformTestClassProcessor$CollectAllTestClassesExecutor.processAllTestClasses(JUnitPlatformTestClassProcessor.java:110)
at org.gradle.api.internal.tasks.testing.junitplatform.JUnitPlatformTestClassProcessor$CollectAllTestClassesExecutor.access$000(JUnitPlatformTestClassProcessor.java:90)
at org.gradle.api.internal.tasks.testing.junitplatform.JUnitPlatformTestClassProcessor.stop(JUnitPlatformTestClassProcessor.java:85)
at org.gradle.api.internal.tasks.testing.SuiteTestClassProcessor.stop(SuiteTestClassProcessor.java:62)
at java.base@17.0.3/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base@17.0.3/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
at java.base@17.0.3/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base@17.0.3/java.lang.reflect.Method.invoke(Method.java:568)
at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:36)
at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:24)
at org.gradle.internal.dispatch.ContextClassLoaderDispatch.dispatch(ContextClassLoaderDispatch.java:33)
at org.gradle.internal.dispatch.ProxyDispatchAdapter$DispatchingInvocationHandler.invoke(ProxyDispatchAdapter.java:94)
at jdk.proxy2/jdk.proxy2.$Proxy5.stop(Unknown Source)
at org.gradle.api.internal.tasks.testing.worker.TestWorker$3.run(TestWorker.java:193)
at org.gradle.api.internal.tasks.testing.worker.TestWorker.executeAndMaintainThreadName(TestWorker.java:129)
at org.gradle.api.internal.tasks.testing.worker.TestWorker.execute(TestWorker.java:100)
at org.gradle.api.internal.tasks.testing.worker.TestWorker.execute(TestWorker.java:60)
at org.gradle.process.internal.worker.child.ActionExecutionWorker.execute(ActionExecutionWorker.java:56)
at org.gradle.process.internal.worker.child.SystemApplicationClassLoaderWorker.call(SystemApplicationClassLoaderWorker.java:113)
at org.gradle.process.internal.worker.child.SystemApplicationClassLoaderWorker.call(SystemApplicationClassLoaderWorker.java:65)
at app//worker.org.gradle.process.internal.worker.GradleWorkerMain.run(GradleWorkerMain.java:69)
at app//worker.org.gradle.process.internal.worker.GradleWorkerMain.main(GradleWorkerMain.java:74)
Caused by: java.lang.IllegalArgumentException: Resource with path keycloak-provider-myprovider/src/test/resources/myrealm-realm.json could not be found on any of these classloaders: [jdk.internal.loader.ClassLoaders$AppClassLoader@251a69d7]
at org.testcontainers.utility.MountableFile.getClasspathResource(MountableFile.java:158)
at org.testcontainers.utility.MountableFile.forClasspathResource(MountableFile.java:103)
at org.testcontainers.utility.MountableFile.forClasspathResource(MountableFile.java:72)
at dasniko.testcontainers.keycloak.ExtendableKeycloakContainer.configure(ExtendableKeycloakContainer.java:179)
at org.testcontainers.containers.GenericContainer.doStart(GenericContainer.java:327)
... 70 more
The resource for the realm under the test should be explicitly be into this path: resources/keycloak/myrealm.json and then it works like a charm. Thank you @dasniko for this implementation.
Describe the bug
Using testImplementation "com.github.dasniko:testcontainers-keycloak:2.5.0" and testImplementation "io.rest-assured:rest-assured:5.3.0" for keycloak version 21.1.1. I am trying to import a realm during the tests. I use testcontainers-keycloak with the following way: KeycloakContainer keycloak = new KeycloakContainer("quay.io/keycloak/keycloak:21.1.1") .withRealmImportFile(realmImportFile) // this would normally be just "target/classes" .withProviderClassesFrom("target/test-classes"); On the command keycloak.start an exception is thrown with the error "caused by: java.lang.IllegalArgumentException: Resource with path". When i click on the path the json file is in the right position and i can read it. It doesn't matter if the realm is like the following or a more complex one. { "id": "myrealm", "realm": "myrealm", "enabled": true, "loginWithEmailAllowed": true, "resetPasswordAllowed": true }
The behavior is the same. The exact above command without withRealmImportFile(realmImportFile), it runs as expected.
Version
2.5.0
Expected behavior
The realm should be imported and the keycloak container should start and read the setting of the realm
Actual behavior
I am trying to import a realm during the tests. I use testcontainers-keycloak with the following way: KeycloakContainer keycloak = new KeycloakContainer("quay.io/keycloak/keycloak:21.1.1") .withRealmImportFile(realmImportFile) // this would normally be just "target/classes" .withProviderClassesFrom("target/test-classes"); keycloak.start(); On the command keycloak.start an exception is thrown with the error "caused by: java.lang.IllegalArgumentException: Resource with path". When i click on the path the json file is in the right position and i can read it. It doesn't matter if the realm is like the following or a more complex one. { "id": "myrealm", "realm": "myrealm", "enabled": true, "loginWithEmailAllowed": true, "resetPasswordAllowed": true }
This starts the container KeycloakContainer keycloak = new KeycloakContainer("quay.io/keycloak/keycloak:21.1.1") // this would normally be just "target/classes" .withProviderClassesFrom("target/test-classes"); keycloak.start();
How to Reproduce?
I got the json file from the flistones and just tried to run similar test with testcontainers for keycloak with keycloak version 21.1.1
Relevant log output
Anything else?
No response