|
1 | | -import { TaskRunProcess, type TaskRunProcessOptions } from "./taskRunProcess.js"; |
| 1 | +import { TaskRunProcess, trustStoreEnv, type TaskRunProcessOptions } from "./taskRunProcess.js"; |
2 | 2 | import { describe, it, expect, vi } from "vitest"; |
3 | 3 | import { UncaughtExceptionError, UnexpectedExitError } from "@trigger.dev/core/v3/errors"; |
4 | 4 | import type { |
@@ -58,6 +58,50 @@ function createExecution(runId: string, attemptNumber: number): TaskRunExecution |
58 | 58 | } as unknown as TaskRunExecution; |
59 | 59 | } |
60 | 60 |
|
| 61 | +describe("trustStoreEnv", () => { |
| 62 | + const controllerEnv = { |
| 63 | + SSL_CERT_FILE: "/etc/ssl/certs/ca-certificates.crt", |
| 64 | + REQUESTS_CA_BUNDLE: "/etc/ssl/certs/ca-certificates.crt", |
| 65 | + PIP_CERT: "/etc/ssl/certs/ca-certificates.crt", |
| 66 | + PATH: "/usr/bin", |
| 67 | + }; |
| 68 | + |
| 69 | + it("forwards the controller's trust store variables to the task process", () => { |
| 70 | + expect(trustStoreEnv(controllerEnv, {})).toEqual({ |
| 71 | + SSL_CERT_FILE: "/etc/ssl/certs/ca-certificates.crt", |
| 72 | + REQUESTS_CA_BUNDLE: "/etc/ssl/certs/ca-certificates.crt", |
| 73 | + PIP_CERT: "/etc/ssl/certs/ca-certificates.crt", |
| 74 | + }); |
| 75 | + }); |
| 76 | + |
| 77 | + it("lets the run's own variables win", () => { |
| 78 | + expect(trustStoreEnv(controllerEnv, { REQUESTS_CA_BUNDLE: "/app/corp.pem" })).toEqual({ |
| 79 | + SSL_CERT_FILE: "/etc/ssl/certs/ca-certificates.crt", |
| 80 | + REQUESTS_CA_BUNDLE: "/app/corp.pem", |
| 81 | + PIP_CERT: "/etc/ssl/certs/ca-certificates.crt", |
| 82 | + }); |
| 83 | + }); |
| 84 | + |
| 85 | + it("sets nothing when neither side defines them", () => { |
| 86 | + expect(trustStoreEnv({ PATH: "/usr/bin" }, {})).toEqual({}); |
| 87 | + }); |
| 88 | + |
| 89 | + it("lets the run's NODE_EXTRA_CA_CERTS win over the image's empty value", () => { |
| 90 | + expect( |
| 91 | + trustStoreEnv( |
| 92 | + { NODE_EXTRA_CA_CERTS: "" }, |
| 93 | + { NODE_EXTRA_CA_CERTS: "/app/certs/corp-root.pem" } |
| 94 | + ) |
| 95 | + ).toEqual({ NODE_EXTRA_CA_CERTS: "/app/certs/corp-root.pem" }); |
| 96 | + }); |
| 97 | + |
| 98 | + it("forwards NODE_EXTRA_CA_CERTS baked into the image when the run sets none", () => { |
| 99 | + expect(trustStoreEnv({ NODE_EXTRA_CA_CERTS: "/app/certs/corp-root.pem" }, {})).toEqual({ |
| 100 | + NODE_EXTRA_CA_CERTS: "/app/certs/corp-root.pem", |
| 101 | + }); |
| 102 | + }); |
| 103 | +}); |
| 104 | + |
61 | 105 | describe("TaskRunProcess", () => { |
62 | 106 | describe("execute() on a dead child process", () => { |
63 | 107 | it("should reject when child process has already exited and IPC send is skipped", async () => { |
|
0 commit comments