I have a testcontainer that creates a Oryd/Hydra container in a Junit 4 test.
@Bean
public GenericContainer hydra() {
WaitStrategy waitStrategy = Wait.forHttp("/health/ready").forStatusCode(200);
GenericContainer hydra =
new GenericContainer("oryd/hydra:1.4.8")
.withCommand("serve all --dangerous-force-http")
.withEnv("URLS_SELF_ISSUER", "http://127.0.0.1:4444/")
.withEnv("DSN", "memory")
.withEnv("SECRETS_SYSTEM", "youReallyNeedToChangeThis")
.withEnv("OIDC_SUBJECT_IDENTIFIERS_SUPPORTED_TYPES", "public,pairwise")
.withEnv("OIDC_SUBJECT_IDENTIFIERS_PAIRWISE_SALT", "youReallyNeedToChangeThis")
.withEnv("STRATEGIES_ACCESS_TOKEN", "jwt")
.withEnv("OIDC_SUBJECT_IDENTIFIERS_SUPPORTED_TYPES", "public")
.withEnv("URLS_CONSENT", "http://127.0.0.1:3000/consent")
.withEnv("URLS_LOGIN", "http://127.0.0.1:3000/login")
.withExposedPorts(4444, 4445)
.waitingFor(waitStrategy)
.withNetwork(network)
.withLogConsumer(consumer);
hydra.start();
return hydra;
}
The problem is with the environment variable "URLS_SELF_ISSUER". The clients of the Hydra server, validate that the URL of the server matches the value of "URLS_SELF_ISSUER". Its value should match the URL exposed to its clients, however testcontainers bind exposed port 4444 to a random port. So, URL will almost always be different from 127.0.0.1:4444.
This is a chicken and egg problem. I don't know what the port is until after the container starts, and then it's too late to update the variable.
Is there a way to know the exposed port so I can configure the container variable "URLS_SELF_ISSUER " with the right URL??