skipcheck

TM1 Testcontainers · Docs · Containers

CognosContainer

import { CognosContainer } from "@skipcheck/tm1-testcontainers";

IBM Cognos Analytics in Docker, for tests, built on the cognos-server image: the security (CAM) a TM1 server in CAM mode takes its users from.

Give it test users, and the container builds an LDAP directory with them and a Cognos namespace (LDAP) for it. Then run a Tm1ServerContainer against it with Tm1ServerContainer.withCamSecurity, and log in to TM1 as each test user:

await using cognos = new CognosContainer(cognosSource).withUser("admin", "adminpw", "Admins").withUser("viewer", "viewerpw", "Readers");
await using server = new Tm1ServerContainer(tm1Source).withCamSecurity(cognos, "admin");
await server.start(); // starts Cognos first
// Each test user logs in with their own identity, through the LDAP namespace
await using viewer = Tm1Client.builder()
  .baseUrl(server.getRestUrl())
  .authenticator(Tm1Authenticator.camNamespace("viewer", "viewerpw", CognosContainer.NAMESPACE))
  .build();
// TM1 knows the user by their CAMID
const user = await viewer.users.activeUser(ODataQuery.none().select(User.Fields.Name));
return user.Name;

Cognos is heavy: it takes about two minutes to start and uses about 8 GB of memory, so Docker needs at least 12 GB. Every user is a Cognos administrator (a new content store puts Everyone there); TM1's own security comes from the groups. The image contains no IBM software, so every container needs a CognosSource.

Members

DEFAULT_IMAGE propertyThe cognos-server image, without a tag.
SERVER_IMAGE propertyOverrides the cognos-server image (not used with CognosSource.PrivateImage).
DISPATCHER_PORT propertyThe dispatcher's port inside the container.
NETWORK_ALIAS propertyIts name on the network, and its host name, which Cognos's own URLs use.
NAMESPACE propertyThe ID of the LDAP namespace the test users are in.
CognosContainer constructorCognos from source, in the default image (or COGNOS_SERVER_IMAGE).
CognosContainer constructorCognos from source, in image, which must be cognos-server or built on it.
CognosContainer constructor
withUserAdds a test user to the LDAP namespace, in groups.
withKeycloakAdds the OIDC namespace, backed by keycloak, on a network the two share.
getKeycloakThe Keycloak behind the OIDC namespace; undefined without one.
getUsersThe test users, in the order added.
getUserA test user.
getGroupsThe test users' groups, in the order first named.
getSourceWhere Cognos comes from.
getUrlCognos's web address on the Docker host, http://host:port/bi/.
getNetworkUrlThe dispatcher's address on the network, as TM1 reaches it.
camAuthorizationThe Authorization header that logs user (a test user) on to TM1 through namespace (LDAP by default).
camAuthorization staticCAMNamespace with user:password:namespace, as TM1 takes it.
passportA CAM passport for an OIDC ID token (from KeycloakContainer.idToken), as a browser gets one, for TM1's CAMPassport logon.
usersSpecThe users as the image takes them.
configure@internal
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.

DEFAULT_IMAGE

property
static DEFAULT_IMAGE

The cognos-server image, without a tag.

SERVER_IMAGE

property
static SERVER_IMAGE

Overrides the cognos-server image (not used with CognosSource.PrivateImage).

DISPATCHER_PORT

property
static DISPATCHER_PORT

The dispatcher's port inside the container.

NETWORK_ALIAS

property
static NETWORK_ALIAS

Its name on the network, and its host name, which Cognos's own URLs use.

NAMESPACE

property
static NAMESPACE

The ID of the LDAP namespace the test users are in.

CognosContainer

constructor
constructor(source: CognosSource)

Cognos from source, in the default image (or COGNOS_SERVER_IMAGE).

CognosContainer

constructor
constructor(image: string, source: CognosSource)

Cognos from source, in image, which must be cognos-server or built on it.

CognosContainer

constructor
constructor(imageOrSource: string | CognosSource, maybeSource?: CognosSource)

withUser

withUser(name: string, password: string, ...groups: string[]): this

Adds a test user to the LDAP namespace, in groups.

Throws

IllegalArgumentException for a name or password the image can't take apart, or a user added twice

withKeycloak

withKeycloak(keycloak: KeycloakContainer): this

Adds the OIDC namespace, backed by keycloak, on a network the two share. Starting Cognos starts Keycloak first.

getKeycloak

getKeycloak(): KeycloakContainer | undefined

The Keycloak behind the OIDC namespace; undefined without one.

getUsers

getUsers(): CognosContainer.User[]

The test users, in the order added.

getUser

getUser(name: string): CognosContainer.User

A test user.

Throws

IllegalArgumentException if there's no such user

getGroups

getGroups(): ReadonlySet<string>

The test users' groups, in the order first named.

getSource

getSource(): CognosSource

Where Cognos comes from.

getUrl

getUrl(): string

Cognos's web address on the Docker host, http://host:port/bi/.

getNetworkUrl

getNetworkUrl(): string

The dispatcher's address on the network, as TM1 reaches it.

camAuthorization

camAuthorization(user: string, namespace: CognosContainer.Namespace = CognosContainer.Namespace.LDAP): string

The Authorization header that logs user (a test user) on to TM1 through namespace (LDAP by default).

Throws

IllegalArgumentException if there's no such user

camAuthorization

static
static camAuthorization(user: string, password: string, namespace: string): string

CAMNamespace with user:password:namespace, as TM1 takes it.

passport

passport(idToken: string): Promise<string>

A CAM passport for an OIDC ID token (from KeycloakContainer.idToken), as a browser gets one, for TM1's CAMPassport logon.

Throws

IllegalStateException if Cognos refused the token

usersSpec

usersSpec(): string

The users as the image takes them: name:password[:group,group], space-separated.

configure

configure(): void

@internal

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.