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 static | The image Cognos runs in, without its tag. |
ServerImage static | The setting that replaces DefaultImage. |
DispatcherPort static | The dispatcher's port. |
NetworkAlias static | Its name on the network. |
NamespaceId static | The LDAP namespace's ID. |
CognosContainer constructor | Cognos from source, in the image for it. |
CognosContainer constructor | Cognos from source, in image. |
WithUser | Adds a test user to the LDAP namespace, in groups. |
WithKeycloak | Adds the OIDC namespace, backed by keycloak, on its network. |
Keycloak property | The Keycloak behind the OIDC namespace, or null. |
Users property | The test users, in the order added. |
GetUser | A test user. |
Groups property | The test users' groups, in the order first named. |
Source property | Where Cognos comes from. |
Url property | Cognos's web address on the Docker host, http://host:port/bi/. |
NetworkUrl property | The dispatcher's address on the network, as TM1 reaches it. |
CamAuthorization | The Authorization header that logs user on to TM1 through the LDAP namespace. |
CamAuthorization | The Authorization header that logs user on to TM1 through namespace. |
CamAuthorization static | CAMNamespace with user:password:namespace, as TM1 takes it. |
PassportAsync | A CAM passport for an OIDC ID token (from KeycloakContainer.IdTokenAsync). |
DockerImageName property | The image it runs. |
EnvMap property | Its environment variables, so far. |
CommandParts property | The command it runs, if not the image's. |
ExposedPorts property | The ports it exposes on the Docker host. |
Network property | The network it joins, or null for Docker's default bridge. |
NetworkAliases property | Its names on Network. |
Dependencies property | What starts before it. |
Container property | The started container. |
IsRunning property | |
Host property | The host its ports are mapped on. |
ContainerId property | The Docker container's ID. |
GetMappedPort | The host port port is mapped to. |
WithEnv | Sets an environment variable. |
WithEnv | Sets environment variables. |
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 Network. |
DependsOn | Starts startables before it. |
WithExtraHost | Adds an /etc/hosts entry. |
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. |
WithCopyFileToContainer | Copies a host file or folder into the container before it starts. |
WithStartupTimeout | How long to wait for it to be ready. |
StartAsync | |
StopAsync | |
DisposeAsync | Stops it. |
GetLogsAsync | Its log, so far. |
DefaultImage
staticconst string DefaultImageThe image Cognos runs in, without its tag.
ServerImage
staticconst string ServerImageThe setting that replaces DefaultImage.
DispatcherPort
staticconst int DispatcherPortThe dispatcher's port.
NetworkAlias
staticconst string NetworkAliasIts name on the network.
NamespaceId
staticconst string NamespaceIdThe LDAP namespace's ID.
CognosContainer
constructorCognosContainer(CognosSource source)Cognos from source, in the image for it.
CognosContainer
constructorCognosContainer(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
propertyKeycloakContainer? KeycloakThe Keycloak behind the OIDC namespace, or null.
Users
propertyIReadOnlyList<User> UsersThe test users, in the order added.
GetUser
User GetUser(string name)A test user.
Throws
ArgumentException- There's no such user.
Groups
propertyIReadOnlyCollection<string> GroupsThe test users' groups, in the order first named.
Source
propertyCognosSource SourceWhere Cognos comes from.
Url
propertystring UrlCognos's web address on the Docker host, http://host:port/bi/.
NetworkUrl
propertystring NetworkUrlThe 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
staticstring 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
propertystring DockerImageNameThe image it runs.
EnvMap
propertyIReadOnlyDictionary<string, string> EnvMapIts environment variables, so far.
CommandParts
propertyIReadOnlyList<string> CommandPartsThe command it runs, if not the image's.
ExposedPorts
propertyIReadOnlyList<int> ExposedPortsThe ports it exposes on the Docker host.
Network
propertyNetwork? NetworkThe network it joins, or null for Docker's default bridge.
NetworkAliases
propertyIReadOnlyList<string> NetworkAliasesIts names on Network.
Dependencies
propertyIReadOnlyCollection<IStartable> DependenciesWhat starts before it.
Container
propertyIContainer ContainerThe started container.
Throws
InvalidOperationException- It isn't started.
IsRunning
propertybool IsRunningHost
propertystring HostThe host its ports are mapped on.
ContainerId
propertystring ContainerIdThe 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.