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 property | The cognos-server image, without a tag. |
SERVER_IMAGE property | Overrides the cognos-server image (not used with CognosSource.PrivateImage). |
DISPATCHER_PORT property | The dispatcher's port inside the container. |
NETWORK_ALIAS property | Its name on the network, and its host name, which Cognos's own URLs use. |
NAMESPACE property | The ID of the LDAP namespace the test users are in. |
CognosContainer constructor | Cognos from source, in the default image (or COGNOS_SERVER_IMAGE). |
CognosContainer constructor | Cognos from source, in image, which must be cognos-server or built on it. |
CognosContainer constructor | |
withUser | Adds a test user to the LDAP namespace, in groups. |
withKeycloak | Adds the OIDC namespace, backed by keycloak, on a network the two share. |
getKeycloak | The Keycloak behind the OIDC namespace; undefined without one. |
getUsers | The test users, in the order added. |
getUser | A test user. |
getGroups | The test users' groups, in the order first named. |
getSource | Where Cognos comes from. |
getUrl | Cognos's web address on the Docker host, http://host:port/bi/. |
getNetworkUrl | The dispatcher's address on the network, as TM1 reaches it. |
camAuthorization | The Authorization header that logs user (a test user) on to TM1 through namespace (LDAP by default). |
camAuthorization static | CAMNamespace with user:password:namespace, as TM1 takes it. |
passport | A CAM passport for an OIDC ID token (from KeycloakContainer.idToken), as a browser gets one, for TM1's CAMPassport logon. |
usersSpec | The users as the image takes them. |
configure | @internal |
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. |
DEFAULT_IMAGE
propertystatic DEFAULT_IMAGEThe cognos-server image, without a tag.
SERVER_IMAGE
propertystatic SERVER_IMAGEOverrides the cognos-server image (not used with CognosSource.PrivateImage).
DISPATCHER_PORT
propertystatic DISPATCHER_PORTThe dispatcher's port inside the container.
NETWORK_ALIAS
propertystatic NETWORK_ALIASIts name on the network, and its host name, which Cognos's own URLs use.
NAMESPACE
propertystatic NAMESPACEThe ID of the LDAP namespace the test users are in.
CognosContainer
constructorconstructor(source: CognosSource)Cognos from source, in the default image (or COGNOS_SERVER_IMAGE).
CognosContainer
constructorconstructor(image: string, source: CognosSource)Cognos from source, in image, which must be cognos-server or built on it.
CognosContainer
constructorconstructor(imageOrSource: string | CognosSource, maybeSource?: CognosSource)withUser
withUser(name: string, password: string, ...groups: string[]): thisAdds 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): thisAdds the OIDC namespace, backed by keycloak, on a network the two share. Starting Cognos starts Keycloak first.
getKeycloak
getKeycloak(): KeycloakContainer | undefinedThe Keycloak behind the OIDC namespace; undefined without one.
getUsers
getUsers(): CognosContainer.User[]The test users, in the order added.
getUser
getUser(name: string): CognosContainer.UserA 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(): CognosSourceWhere Cognos comes from.
getUrl
getUrl(): stringCognos's web address on the Docker host, http://host:port/bi/.
getNetworkUrl
getNetworkUrl(): stringThe dispatcher's address on the network, as TM1 reaches it.
camAuthorization
camAuthorization(user: string, namespace: CognosContainer.Namespace = CognosContainer.Namespace.LDAP): stringThe 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
staticstatic camAuthorization(user: string, password: string, namespace: string): stringCAMNamespace 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(): stringThe users as the image takes them: name:password[:group,group], space-separated.
configure
configure(): void@internal
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.