The OryHydraDockerComposeContainer
is a Testcontainer extension designed for the Ory Hydra OAuth 2.0 and OpenID Connect provider. It allows you to quickly integrate and test Ory Hydra functionalities in Java applications using Docker Compose.
-
Automatic setup of Ory Hydra’s admin and public ports.
-
Convenient methods to fetch base URIs for both the admin and public endpoints.
-
Easy retrieval of OAuth2 Authorization and JWKS URIs.
-
Customizable through a builder pattern, allowing for the configuration of Docker Compose files and environment variables.
First, include the OryHydraDockerComposeContainer
in your project’s build.gradle
:
dependencies {
testImplementation 'com.ardetrick.testcontainers:ory-hydra-testcontainer:0.0.1'
}
import com.ardetrick.testcontainers.OryHydraDockerComposeContainer;
public class HydraIntegrationTest {
OryHydraDockerComposeContainer<?> dockerComposeEnvironment;
@BeforeEach
public void beforeEachTest() {
dockerComposeEnvironment = OryHydraDockerComposeContainer.builder()
.dockerComposeFile(new File("path_to_docker_compose.yml"))
.urlsLogin("http://example.com/login")
.urlsConsent("http://example.com/consent")
.urlsSelfIssuer("http://example.com/")
.start();
}
@Test
public void testOAuthFlow() {
// Use the helper methods like hydra.getOAuth2AuthUri() for your tests.
// Your test logic here...
}
}
Using the Builder
class, you can configure:
-
dockerComposeFile(File)
: Specify the Docker Compose file to use. -
urlsLogin(String)
: Set the login URL. -
urlsConsent(String)
: Set the consent URL. -
urlsSelfIssuer(String)
: Set the self-issuer URL.
To build from the source using the Gradle Wrapper:
$ git clone https://github.com/ardetrick/ory-hydra-testcontainer.git $ cd ory-hydra-testcontainer $ ./gradlew clean build
For Windows:
$ git clone https://github.com/ardetrick/ory-hydra-testcontainer.git $ cd ory-hydra-testcontainer $ gradlew.bat clean build
We welcome contributions! Please submit pull requests or open issues for feedback.
This project is licensed under the MIT License. See the LICENSE
file for details.