skipcheck

TM1 Testcontainers · Docs · Containers

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 propertyThe Keycloak image.
IMAGE propertyOverrides the Keycloak image.
HTTP_PORT propertyKeycloak's HTTP port inside the container.
NETWORK_ALIAS propertyIts name on the network.
REALM propertyThe realm the Cognos test users are in.
APP_CLIENT propertyThe client an app gets ID tokens with, by the password grant.
KeycloakContainer constructorKeycloak in image; DEFAULT_IMAGE, or KEYCLOAK_IMAGE if set, by default.
getNetworkUrlKeycloak's address on its network, as Cognos and TM1 reach it.
getUrlKeycloak's address on the Docker host.
idTokenAn ID token for a test user, by the password grant of APP_CLIENT.
getDockerImageNameThe image it runs.
getEnvMapIts environment variables, so far.
getCommandPartsThe command it runs, if not the image's.
getExposedPortsThe ports it exposes on the Docker host.
getNetworkThe network it joins, or undefined for Docker's default bridge.
getNetworkAliasesIts names on getNetwork.
getDependenciesWhat starts before it.
getLabelsThe labels set with withLabel.
isShouldBeReusedWhether it asks to be kept for later runs (withReuse).
getCopiedFilesThe files and folders copied in with withCopyFileToContainer.
getBindsThe bind mounts, source:target[:ro], the source a host folder or a volume.
getContainerThe started container.
isRunning
getHostThe host its ports are mapped on.
getContainerIdThe Docker container's ID.
getMappedPortThe host port port is mapped to.
withEnvSets an environment variable, or several.
withEnvSets several environment variables at once.
withEnv
withCommandRuns commandParts in place of the image's command.
withExposedPortsExposes ports on the Docker host, each on a free port.
withNetworkJoins network (created when the first container on it starts).
withNetworkAliasesAdds names it's reached by on getNetwork.
dependsOnStarts startables before it.
withExtraHostAdds an /etc/hosts entry.
withHostnameSets the container's host name.
withReuseKeeps 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.
withLabelAdds a Docker label.
withCopyFileToContainerCopies a host file or folder into the container before it starts.
withStartupTimeoutHow long to wait for it to be ready, in milliseconds.
start
stop
[Symbol.asyncDispose]Stops it, for await using.
getLogsIts log, so far.
configureFinishes the configuration as it starts, once what it depends on is running; the tests call it to check the wiring.

DEFAULT_IMAGE

property
static DEFAULT_IMAGE

The Keycloak image.

IMAGE

property
static IMAGE

Overrides the Keycloak image.

HTTP_PORT

property
static HTTP_PORT

Keycloak's HTTP port inside the container.

NETWORK_ALIAS

property
static NETWORK_ALIAS

Its name on the network.

REALM

property
static REALM

The realm the Cognos test users are in.

APP_CLIENT

property
static APP_CLIENT

The client an app gets ID tokens with, by the password grant.

KeycloakContainer

constructor
constructor(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(): string

Keycloak's address on its network, as Cognos and TM1 reach it.

getUrl

getUrl(): string

Keycloak'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(): string

The 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 | undefined

The 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(): boolean

Whether 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(): StartedTestContainer

The started container.

Throws

IllegalStateException if it isn't started

isRunning

isRunning(): boolean

getHost

getHost(): string

The host its ports are mapped on.

getContainerId

getContainerId(): string

The Docker container's ID.

getMappedPort

getMappedPort(port: number): number

The host port port is mapped to.

withEnv

withEnv(name: string, value: string): this

Sets an environment variable, or several.

withEnv

withEnv(variables: Readonly<Record<string, string>> | ReadonlyMap<string, string>): this

Sets several environment variables at once.

withEnv

withEnv(name: string | Readonly<Record<string, string>> | ReadonlyMap<string, string>, value?: string): this

withCommand

withCommand(...commandParts: string[]): this

Runs commandParts in place of the image's command.

withExposedPorts

withExposedPorts(...ports: number[]): this

Exposes ports on the Docker host, each on a free port.

withNetwork

withNetwork(network: Network | undefined): this

Joins network (created when the first container on it starts).

withNetworkAliases

withNetworkAliases(...aliases: string[]): this

Adds names it's reached by on getNetwork.

dependsOn

dependsOn(...startables: Startable[]): this

Starts startables before it.

withExtraHost

withExtraHost(host: string, ipAddress: string): this

Adds an /etc/hosts entry.

withHostname

withHostname(hostname: string): this

Sets the container's host name.

withReuse

withReuse(reusable: boolean): this

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

withLabel(key: string, value: string): this

Adds a Docker label.

withCopyFileToContainer

withCopyFileToContainer(hostPath: string, containerPath: string): this

Copies a host file or folder into the container before it starts.

withStartupTimeout

withStartupTimeout(timeout: number): this

How 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(): void

Finishes the configuration as it starts, once what it depends on is running; the tests call it to check the wiring.