skipcheck

TM1 Testcontainers · Docs · Containers

CognosContainer

using 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 var cognos = new CognosContainer(cognosSource).WithUser("admin", "adminpw", "Admins").WithUser("viewer", "viewerpw", "Readers");
await using var server = new Tm1ServerContainer(tm1Source).WithCamSecurity(cognos, "admin");
await server.StartAsync(); // starts Cognos first
// Each test user logs in with their own identity, through the LDAP namespace
await using var viewer = Tm1Client
    .Builder()
    .BaseUrl(server.RestUrl)
    .Authenticator(Tm1Authenticator.CamNamespace("viewer", "viewerpw", CognosContainer.NamespaceId))
    .Build();
// TM1 knows the user by their CAMID
return (await viewer.Users.ActiveUserAsync(ODataQuery.None().Select(User.Fields.Name))).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

DefaultImage staticThe image Cognos runs in, without its tag.
ServerImage staticThe setting that replaces DefaultImage.
DispatcherPort staticThe dispatcher's port.
NetworkAlias staticIts name on the network.
NamespaceId staticThe LDAP namespace's ID.
CognosContainer constructorCognos from source, in the image for it.
CognosContainer constructorCognos from source, in image.
WithUserAdds a test user to the LDAP namespace, in groups.
WithKeycloakAdds the OIDC namespace, backed by keycloak, on its network.
Keycloak propertyThe Keycloak behind the OIDC namespace, or null.
Users propertyThe test users, in the order added.
GetUserA test user.
Groups propertyThe test users' groups, in the order first named.
Source propertyWhere Cognos comes from.
Url propertyCognos's web address on the Docker host, http://host:port/bi/.
NetworkUrl propertyThe dispatcher's address on the network, as TM1 reaches it.
CamAuthorizationThe Authorization header that logs user on to TM1 through the LDAP namespace.
CamAuthorizationThe Authorization header that logs user on to TM1 through namespace.
CamAuthorization staticCAMNamespace with user:password:namespace, as TM1 takes it.
PassportAsyncA CAM passport for an OIDC ID token (from KeycloakContainer.IdTokenAsync).
DockerImageName propertyThe image it runs.
EnvMap propertyIts environment variables, so far.
CommandParts propertyThe command it runs, if not the image's.
ExposedPorts propertyThe ports it exposes on the Docker host.
Network propertyThe network it joins, or null for Docker's default bridge.
NetworkAliases propertyIts names on Network.
Dependencies propertyWhat starts before it.
Container propertyThe started container.
IsRunning property
Host propertyThe host its ports are mapped on.
ContainerId propertyThe Docker container's ID.
GetMappedPortThe host port port is mapped to.
WithEnvSets an environment variable.
WithEnvSets environment variables.
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 Network.
DependsOnStarts startables before it.
WithExtraHostAdds an /etc/hosts entry.
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.
WithCopyFileToContainerCopies a host file or folder into the container before it starts.
WithStartupTimeoutHow long to wait for it to be ready.
StartAsync
StopAsync
DisposeAsyncStops it.
GetLogsAsyncIts log, so far.

DefaultImage

static
const string DefaultImage

The image Cognos runs in, without its tag.

ServerImage

static
const string ServerImage

The setting that replaces DefaultImage.

DispatcherPort

static
const int DispatcherPort

The dispatcher's port.

NetworkAlias

static
const string NetworkAlias

Its name on the network.

NamespaceId

static
const string NamespaceId

The LDAP namespace's ID.

CognosContainer

constructor
CognosContainer(CognosSource source)

Cognos from source, in the image for it.

CognosContainer

constructor
CognosContainer(string image, CognosSource source)

Cognos from source, in image.

WithUser

CognosContainer WithUser(string name, string password, params string[] groups)

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

Throws

ArgumentException
A name the image can't take apart, or a user added twice.

WithKeycloak

CognosContainer WithKeycloak(KeycloakContainer keycloak)

Adds the OIDC namespace, backed by keycloak, on its network.

Keycloak

property
KeycloakContainer? Keycloak

The Keycloak behind the OIDC namespace, or null.

Users

property
IReadOnlyList<User> Users

The test users, in the order added.

GetUser

User GetUser(string name)

A test user.

Throws

ArgumentException
There's no such user.

Groups

property
IReadOnlyCollection<string> Groups

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

Source

property
CognosSource Source

Where Cognos comes from.

Url

property
string Url

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

NetworkUrl

property
string NetworkUrl

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

CamAuthorization

string CamAuthorization(string user)

The Authorization header that logs user on to TM1 through the LDAP namespace.

CamAuthorization

string CamAuthorization(string user, Namespace @namespace)

The Authorization header that logs user on to TM1 through namespace.

CamAuthorization

static
string CamAuthorization(string user, string password, string @namespace)

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

PassportAsync

Task<string> PassportAsync(string idToken, CancellationToken cancellationToken = default)

A CAM passport for an OIDC ID token (from KeycloakContainer.IdTokenAsync).

Throws

InvalidOperationException
Cognos refused the token.

DockerImageName

property
string DockerImageName

The image it runs.

EnvMap

property
IReadOnlyDictionary<string, string> EnvMap

Its environment variables, so far.

CommandParts

property
IReadOnlyList<string> CommandParts

The command it runs, if not the image's.

ExposedPorts

property
IReadOnlyList<int> ExposedPorts

The ports it exposes on the Docker host.

Network

property
Network? Network

The network it joins, or null for Docker's default bridge.

NetworkAliases

property
IReadOnlyList<string> NetworkAliases

Its names on Network.

Dependencies

property
IReadOnlyCollection<IStartable> Dependencies

What starts before it.

Container

property
IContainer Container

The started container.

Throws

InvalidOperationException
It isn't started.

IsRunning

property
bool IsRunning

Host

property
string Host

The host its ports are mapped on.

ContainerId

property
string ContainerId

The Docker container's ID.

GetMappedPort

int GetMappedPort(int port)

The host port port is mapped to.

WithEnv

TSelf WithEnv(string name, string value)

Sets an environment variable.

WithEnv

TSelf WithEnv(IReadOnlyDictionary<string, string> variables)

Sets environment variables.

WithCommand

TSelf WithCommand(params string[] commandParts)

Runs commandParts in place of the image's command.

WithExposedPorts

TSelf WithExposedPorts(params int[] exposedPorts)

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

WithNetwork

TSelf WithNetwork(Network? network)

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

WithNetworkAliases

TSelf WithNetworkAliases(params string[] networkAliases)

Adds names it's reached by on Network.

DependsOn

TSelf DependsOn(params IStartable[] startables)

Starts startables before it.

WithExtraHost

TSelf WithExtraHost(string host, string ipAddress)

Adds an /etc/hosts entry.

WithReuse

TSelf WithReuse(bool reusable)

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.

WithCopyFileToContainer

TSelf WithCopyFileToContainer(string hostPath, string containerPath)

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

WithStartupTimeout

TSelf WithStartupTimeout(TimeSpan timeout)

How long to wait for it to be ready.

StartAsync

Task StartAsync(CancellationToken cancellationToken = default)

StopAsync

Task StopAsync(CancellationToken cancellationToken = default)

DisposeAsync

ValueTask DisposeAsync()

Stops it.

GetLogsAsync

Task<string> GetLogsAsync(CancellationToken cancellationToken = default)

Its log, so far.