KeycloakContainer
import { KeycloakContainer } from "@skipcheck/tm1-testcontainers"; Keycloak in Docker, as the OpenID Connect provider for a CognosContainer's OIDC
namespace (CognosContainer.withKeycloak). Cognos builds a realm in it from its
test users when it starts.
Its issuer is its address on the shared Docker network, http://keycloak:8080,
whichever way it's reached, so Cognos accepts tokens that tests get through the
host-side port (idToken). The interactive (browser) logon would need a browser
that reaches that network address, so it isn't wrapped here.
Members
DEFAULT_IMAGE property | The Keycloak image. |
IMAGE property | Overrides the Keycloak image. |
HTTP_PORT property | Keycloak's HTTP port inside the container. |
NETWORK_ALIAS property | Its name on the network. |
REALM property | The realm the Cognos test users are in. |
APP_CLIENT property | The client an app gets ID tokens with, by the password grant. |
KeycloakContainer constructor | Keycloak in image; DEFAULT_IMAGE, or KEYCLOAK_IMAGE if set, by default. |
getNetworkUrl | Keycloak's address on its network, as Cognos and TM1 reach it. |
getUrl | Keycloak's address on the Docker host. |
idToken | An ID token for a test user, by the password grant of APP_CLIENT. |
getDockerImageName | The image it runs. |
getEnvMap | Its environment variables, so far. |
getCommandParts | The command it runs, if not the image's. |
getExposedPorts | The ports it exposes on the Docker host. |
getNetwork | The network it joins, or undefined for Docker's default bridge. |
getNetworkAliases | Its names on getNetwork. |
getDependencies | What starts before it. |
getLabels | The labels set with withLabel. |
isShouldBeReused | Whether it asks to be kept for later runs (withReuse). |
getCopiedFiles | The files and folders copied in with withCopyFileToContainer. |
getBinds | The bind mounts, source:target[:ro], the source a host folder or a volume. |
getContainer | The started container. |
isRunning | |
getHost | The host its ports are mapped on. |
getContainerId | The Docker container's ID. |
getMappedPort | The host port port is mapped to. |
withEnv | Sets an environment variable, or several. |
withEnv | Sets several environment variables at once. |
withEnv | |
withCommand | Runs commandParts in place of the image's command. |
withExposedPorts | Exposes ports on the Docker host, each on a free port. |
withNetwork | Joins network (created when the first container on it starts). |
withNetworkAliases | Adds names it's reached by on getNetwork. |
dependsOn | Starts startables before it. |
withExtraHost | Adds an /etc/hosts entry. |
withHostname | Sets the container's host name. |
withReuse | Keeps the container for later runs, when reuse is switched on as Testcontainers for Java has it (testcontainers.reuse.enable=true in ~/.testcontainers.properties, or TESTCONTAINERS_REUSE_ENABLE=true); otherwise it's removed after the run. |
withLabel | Adds a Docker label. |
withCopyFileToContainer | Copies a host file or folder into the container before it starts. |
withStartupTimeout | How long to wait for it to be ready, in milliseconds. |
start | |
stop | |
[Symbol.asyncDispose] | Stops it, for await using. |
getLogs | Its log, so far. |
configure | Finishes the configuration as it starts, once what it depends on is running; the tests call it to check the wiring. |
DEFAULT_IMAGE
propertystatic DEFAULT_IMAGEThe Keycloak image.
IMAGE
propertystatic IMAGEOverrides the Keycloak image.
HTTP_PORT
propertystatic HTTP_PORTKeycloak's HTTP port inside the container.
NETWORK_ALIAS
propertystatic NETWORK_ALIASIts name on the network.
REALM
propertystatic REALMThe realm the Cognos test users are in.
APP_CLIENT
propertystatic APP_CLIENTThe client an app gets ID tokens with, by the password grant.
KeycloakContainer
constructorconstructor(image: string = Settings.text(Settings.get(KeycloakContainer.IMAGE)) ?? KeycloakContainer.DEFAULT_IMAGE)Keycloak in image; DEFAULT_IMAGE, or KEYCLOAK_IMAGE if set, by default.
getNetworkUrl
getNetworkUrl(): stringKeycloak's address on its network, as Cognos and TM1 reach it.
getUrl
getUrl(): stringKeycloak's address on the Docker host.
idToken
idToken(user: string, password: string): Promise<string>An ID token for a test user, by the password grant of APP_CLIENT.
Throws
- IllegalStateException if Keycloak refused
getDockerImageName
getDockerImageName(): stringThe image it runs.
getEnvMap
getEnvMap(): ReadonlyMap<string, string>Its environment variables, so far.
getCommandParts
getCommandParts(): readonly string[]The command it runs, if not the image's.
getExposedPorts
getExposedPorts(): readonly number[]The ports it exposes on the Docker host.
getNetwork
getNetwork(): Network | undefinedThe network it joins, or undefined for Docker's default bridge.
getNetworkAliases
getNetworkAliases(): readonly string[]Its names on getNetwork.
getDependencies
getDependencies(): readonly Startable[]What starts before it.
getLabels
getLabels(): ReadonlyMap<string, string>The labels set with withLabel.
isShouldBeReused
isShouldBeReused(): booleanWhether it asks to be kept for later runs (withReuse).
getCopiedFiles
getCopiedFiles(): ReadonlyMap<string, string>The files and folders copied in with withCopyFileToContainer: the path in the container to the path on the host.
getBinds
getBinds(): string[]The bind mounts, source:target[:ro], the source a host folder or a volume.
getContainer
getContainer(): StartedTestContainerThe started container.
Throws
- IllegalStateException if it isn't started
isRunning
isRunning(): booleangetHost
getHost(): stringThe host its ports are mapped on.
getContainerId
getContainerId(): stringThe Docker container's ID.
getMappedPort
getMappedPort(port: number): numberThe host port port is mapped to.
withEnv
withEnv(name: string, value: string): thisSets an environment variable, or several.
withEnv
withEnv(variables: Readonly<Record<string, string>> | ReadonlyMap<string, string>): thisSets several environment variables at once.
withEnv
withEnv(name: string | Readonly<Record<string, string>> | ReadonlyMap<string, string>, value?: string): thiswithCommand
withCommand(...commandParts: string[]): thisRuns commandParts in place of the image's command.
withExposedPorts
withExposedPorts(...ports: number[]): thisExposes ports on the Docker host, each on a free port.
withNetwork
withNetwork(network: Network | undefined): thisJoins network (created when the first container on it starts).
withNetworkAliases
withNetworkAliases(...aliases: string[]): thisAdds names it's reached by on getNetwork.
dependsOn
dependsOn(...startables: Startable[]): thisStarts startables before it.
withExtraHost
withExtraHost(host: string, ipAddress: string): thisAdds an /etc/hosts entry.
withHostname
withHostname(hostname: string): thisSets the container's host name.
withReuse
withReuse(reusable: boolean): thisKeeps the container for later runs, when reuse is switched on as Testcontainers for Java has it (testcontainers.reuse.enable=true in ~/.testcontainers.properties, or TESTCONTAINERS_REUSE_ENABLE=true); otherwise it's removed after the run.
withLabel
withLabel(key: string, value: string): thisAdds a Docker label.
withCopyFileToContainer
withCopyFileToContainer(hostPath: string, containerPath: string): thisCopies a host file or folder into the container before it starts.
withStartupTimeout
withStartupTimeout(timeout: number): thisHow long to wait for it to be ready, in milliseconds.
start
start(): Promise<void>stop
stop(): Promise<void>[Symbol.asyncDispose]
[Symbol.asyncDispose](): Promise<void>Stops it, for await using: the same as stop.
getLogs
getLogs(): Promise<string>Its log, so far.
configure
configure(): voidFinishes the configuration as it starts, once what it depends on is running; the tests call it to check the wiring.