Skip to content

Commit 0b7eaa6

Browse files
committed
RBAC tests: parameterise RBAC_FORCE_FALLBACK in testcontainers (TRI-8859)
Replace the hardcoded `RBAC_FORCE_FALLBACK: "1"` env var with an optional `forceRbacFallback` parameter on `startWebapp` and `startTestServer`. Default `true` preserves OSS suite behaviour (every existing call site keeps fallback-pinned semantics). Cloud's enterprise variant of the e2e suite passes `false` so the spawned webapp loads the real `@triggerdotdev/plugins/rbac` instead of the OSS fallback. Same harness, different RBAC implementation under test. Verification: OSS e2e.full suite still 162/162 passes.
1 parent 3d19d40 commit 0b7eaa6

1 file changed

Lines changed: 31 additions & 6 deletions

File tree

  • internal-packages/testcontainers/src

internal-packages/testcontainers/src/webapp.ts

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,30 @@ export interface WebappInstance {
3737
fetch(path: string, init?: RequestInit): Promise<Response>;
3838
}
3939

40+
export interface StartWebappOptions {
41+
/**
42+
* When true (default), the spawned webapp runs with `RBAC_FORCE_FALLBACK=1`
43+
* so the OSS fallback handles all auth checks. The OSS comprehensive suite
44+
* (`*.e2e.full.test.ts`) relies on this — it's pinned to fallback so
45+
* results don't depend on whether `@triggerdotdev/plugins/rbac` happens
46+
* to be installed in the local node_modules.
47+
*
48+
* The cloud repo's parallel enterprise variant (TRI-8859) overrides this
49+
* to `false`, spawning a webapp that loads the linked enterprise plugin
50+
* instead. Same harness, different RBAC implementation under test.
51+
*/
52+
forceRbacFallback?: boolean;
53+
}
54+
4055
export async function startWebapp(
4156
databaseUrl: string,
42-
redis: { host: string; port: number }
57+
redis: { host: string; port: number },
58+
options: StartWebappOptions = {}
4359
): Promise<{
4460
instance: WebappInstance;
4561
stop: () => Promise<void>;
4662
}> {
63+
const forceRbacFallback = options.forceRbacFallback ?? true;
4764
const port = await findFreePort();
4865

4966
// Merge NODE_PATH so transitive pnpm deps (hoisted to .pnpm/node_modules) are resolvable
@@ -86,9 +103,11 @@ export async function startWebapp(
86103
RUN_ENGINE_TTL_SYSTEM_DISABLED: "true", // disables TTL expiry system (BoolEnv)
87104
RUN_ENGINE_TTL_CONSUMERS_DISABLED: "true", // disables TTL consumers (BoolEnv)
88105
RUN_REPLICATION_ENABLED: "0",
89-
// Force the RBAC plugin to use the OSS fallback in e2e tests so auth behavior is
90-
// deterministic regardless of whether the enterprise plugin is installed.
91-
RBAC_FORCE_FALLBACK: "1",
106+
// Force the RBAC plugin to use the OSS fallback in e2e tests so auth
107+
// behavior is deterministic regardless of whether the enterprise
108+
// plugin is installed. Cloud's enterprise-variant suite (TRI-8859)
109+
// sets this to "0" / undefined to exercise the real CASL controller.
110+
...(forceRbacFallback ? { RBAC_FORCE_FALLBACK: "1" } : {}),
92111
NODE_PATH: nodePath,
93112
},
94113
stdio: ["ignore", "pipe", "pipe"],
@@ -162,7 +181,9 @@ export interface TestServer {
162181
}
163182

164183
/** Convenience helper: starts a postgres + redis container + webapp and returns both for testing. */
165-
export async function startTestServer(): Promise<TestServer> {
184+
export async function startTestServer(
185+
options: StartWebappOptions = {}
186+
): Promise<TestServer> {
166187
const network = await new Network().start();
167188

168189
// Track each resource as we acquire it so we can tear it down if a later step fails.
@@ -183,7 +204,11 @@ export async function startTestServer(): Promise<TestServer> {
183204

184205
prisma = new PrismaClient({ datasources: { db: { url: pg.url } } });
185206
await prisma.$connect(); // pre-warm pool; surface connection failures before tests start
186-
const started = await startWebapp(pg.url, { host: rc.getHost(), port: rc.getPort() });
207+
const started = await startWebapp(
208+
pg.url,
209+
{ host: rc.getHost(), port: rc.getPort() },
210+
options
211+
);
187212
webapp = started.instance;
188213
stopWebapp = started.stop;
189214
} catch (err) {

0 commit comments

Comments
 (0)