Skip to content

Infisical is the open-source platform for securing secrets, certificates, access, and AI Agents.

feat: added various module for infisical

=d5bfdbc4a34b
diff --git a/tests/Makefile b/tests/Makefile
index 5c486190cc..29fe2ff1d8 100644
--- a/tests/Makefile
+++ b/tests/Makefile
@@ -3,7 +3,7 @@
# the toolchain's own.
GOFMT := $(shell go env GOROOT)/bin/gofmt
-.PHONY: fmt lint test test-unit
+.PHONY: fmt lint test test-unit test-docker down status
fmt:
$(GOFMT) -w .
@@ -24,5 +24,7 @@ test-docker:
INFRA_DOCKER_TESTS=1 go test ./infra/... -count=1
down:
- @docker rm -f $$(docker ps -aq --filter label=inf.scope) 2>/dev/null || true
- @docker network rm inf-net 2>/dev/null || true
+ go run ./cmd/inf down
+
+status:
+ go run ./cmd/inf status
diff --git a/tests/cmd/inf/main.go b/tests/cmd/inf/main.go
new file mode 100644
index 0000000000..8e325cb5de
--- /dev/null
+++ b/tests/cmd/inf/main.go
@@ -0,0 +1,89 @@
+// Command inf manages the containers the blackbox harness leaves running.
+//
+// Shared containers deliberately outlive a `go test` run, so a second run adopts
+// them and is fast. Reaping is therefore explicit rather than automatic.
+package main
+
+import (
+ "fmt"
+ "os"
+ "os/exec"
+ "strings"
+
+ "github.com/Infisical/infisical/tests/infra"
+)
+
+func main() {
+ cmd := ""
+ if len(os.Args) > 1 {
+ cmd = os.Args[1]
+ }
+
+ switch cmd {
+ case "status":
+ os.Exit(status())
+ case "down":
+ os.Exit(down())
+ default:
+ fmt.Fprintln(os.Stderr, strings.TrimSpace(`
+inf status list harness containers, with the checkout that created each
+inf down stop every harness container and remove the network
+`))
+ os.Exit(2)
+ }
+}
+
+func status() int {
+ out, err := docker("ps", "-a",
+ "--filter", "label="+infra.LabelScope,
+ "--format", "{{.Names}}\t{{.State}}\t{{.Label \""+infra.LabelWorkspace+"\"}}")
+ if err != nil {
+ fmt.Fprintln(os.Stderr, err)
+ return 1
+ }
+ if strings.TrimSpace(out) == "" {
+ fmt.Println("no harness containers")
+ return 0
+ }
+ fmt.Printf("%-52s %-10s %s\n", "NAME", "STATE", "WORKSPACE")
+ for _, line := range strings.Split(strings.TrimSpace(out), "\n") {
+ f := strings.SplitN(line, "\t", 3)
+ for len(f) < 3 {
+ f = append(f, "")
+ }
+ fmt.Printf("%-52s %-10s %s\n", f[0], f[1], f[2])
+ }
+ return 0
+}
+
+// down reaps by label rather than by name, so it works when a run was killed and
+// left nothing behind to read.
+//
+// It is machine-wide on purpose: shared containers are shared across worktrees, so
+// this can stop a run in another checkout. `inf status` shows which one created what.
+func down() int {
+ ids, err := docker("ps", "-aq", "--filter", "label="+infra.LabelScope)
+ if err != nil {
+ fmt.Fprintln(os.Stderr, err)
+ return 1
+ }
+ if list := strings.Fields(ids); len(list) > 0 {
+ if _, err := docker(append([]string{"rm", "-f"}, list...)...); err != nil {
+ fmt.Fprintln(os.Stderr, err)
+ return 1
+ }
+ fmt.Printf("removed %d container(s)\n", len(list))
+ }
+ if _, err := docker("network", "rm", infra.NetworkName); err == nil {
+ fmt.Println("removed network " + infra.NetworkName)
+ }
+ return 0
+}
+
+func docker(args ...string) (string, error) {
+ out, err := exec.Command("docker", args...).CombinedOutput()
+ if err != nil {
+ return "", fmt.Errorf("docker %s: %w: %s", strings.Join(args, " "), err, strings.TrimSpace(string(out)))
+ }
+ return string(out), nil
+}
diff --git a/tests/infra/container.go b/tests/infra/container.go
index 1c7b51276b..734e3102a6 100644
--- a/tests/infra/container.go
+++ b/tests/infra/container.go
@@ -20,7 +20,11 @@ type ContainerSpec struct {
Command []string
Env map[string]string
Ports []int
- Alias string // network alias, which becomes the Internal host
+ Alias string // primary network alias, which becomes the Internal host
+
+ // Aliases are extra network aliases. WireMock uses them to answer for hostnames
+ // that cloud SDKs hardcode and would otherwise never send through a proxy.
+ Aliases []string
Files []File
Labels map[string]string
Ready ReadyFunc
diff --git a/tests/infra/lock.go b/tests/infra/lock.go
new file mode 100644
index 0000000000..5462f3eb7d
--- /dev/null
+++ b/tests/infra/lock.go
@@ -0,0 +1,41 @@
+package infra
+
+import (
+ "fmt"
+ "os"
+ "path/filepath"
+ "syscall"
+)
+
+// Lock serializes an operation across processes, keyed by name.
+//
+// Two races need it, and both are invisible until they bite:
+//
+// - Four test binaries start at once, all find no container of a given name, and
+// all try to create it. Reuse-by-name races here.
+// - The same four all find no image for the current source tree and all start
+// `docker build` on the same context.
+//
+// Returns a release function. Safe to call the release more than once.
+func Lock(name string) (func(), error) {
+ path := filepath.Join(os.TempDir(), Prefix+"-"+Sanitize(name)+".lock")
+
+ f, err := os.OpenFile(path, os.O_CREATE|os.O_RDWR, 0o644)
+ if err != nil {
+ return nil, fmt.Errorf("infra: opening lock %s: %w", path, err)
+ }
+ if err := syscall.Flock(int(f.Fd()), syscall.LOCK_EX); err != nil {
+ _ = f.Close()
+ return nil, fmt.Errorf("infra: acquiring lock %s: %w", path, err)
+ }
+
+ released := false
+ return func() {
+ if released {
+ return
+ }
+ released = true
+ _ = syscall.Flock(int(f.Fd()), syscall.LOCK_UN)
+ _ = f.Close()
+ }, nil
+}
diff --git a/tests/infra/lock_test.go b/tests/infra/lock_test.go
new file mode 100644
index 0000000000..d4cdf03699
--- /dev/null
+++ b/tests/infra/lock_test.go
@@ -0,0 +1,103 @@
+package infra_test
+
+import (
+ "os"
+ "os/exec"
+ "strconv"
+ "strings"
+ "sync"
+ "testing"
+ "time"
+
+ "github.com/Infisical/infisical/tests/infra"
+ "github.com/Infisical/infisical/tests/internal/spec"
+)
+
+func TestLock_SerializesAcrossProcesses(t *testing.T) {
+ spec.Why(t, `The race this guards is between separate test binaries, so a same-process
+ mutex test would pass while the real thing stayed broken. This re-execs itself to
+ get genuinely separate processes.`)
+
+ const workers = 4
+
+ if os.Getenv("INFRA_LOCK_CHILD") != "" {
+ // Child: hold the lock briefly and append a start/end pair. Overlapping
+ // pairs in the file mean the lock did not hold.
+ release, err := infra.Lock("locktest")
+ if err != nil {
+ t.Fatalf("lock: %v", err)
+ }
+ defer release()
+
+ path := os.Getenv("INFRA_LOCK_FILE")
+ appendLine(t, path, "start "+strconv.Itoa(os.Getpid()))
+ time.Sleep(50 * time.Millisecond)
+ appendLine(t, path, "end "+strconv.Itoa(os.Getpid()))
+ return
+ }
+
+ record := filepath(t)
+ var wg sync.WaitGroup
+ for range workers {
+ wg.Add(1)
+ go func() {
+ defer wg.Done()
+ cmd := exec.Command(os.Args[0], "-test.run", "^TestLock_SerializesAcrossProcesses$")
+ cmd.Env = append(os.Environ(), "INFRA_LOCK_CHILD=1", "INFRA_LOCK_FILE="+record)
+ if out, err := cmd.CombinedOutput(); err != nil {
+ t.Errorf("child failed: %v\n%s", err, out)
+ }
+ }()
+ }
+ wg.Wait()
+
+ lines := strings.Fields(strings.ReplaceAll(readFile(t, record), "\n", " "))
+ depth := 0
+ for i := 0; i < len(lines); i += 2 {
+ switch lines[i] {
+ case "start":
+ depth++
+ if depth > 1 {
+ t.Fatalf("two processes held the lock at once:\n%s", readFile(t, record))
+ }
+ case "end":
+ depth--
+ }
+ }
+ if got := strings.Count(readFile(t, record), "start"); got != workers {
+ t.Fatalf("expected %d critical sections, got %d", workers, got)
+ }
+}
+
+func filepath(t *testing.T) string {
+ t.Helper()
+ f, err := os.CreateTemp("", "inf-locktest-*")
+ if err != nil {
+ t.Fatal(err)
+ }
+ name := f.Name()
+ _ = f.Close()
+ t.Cleanup(func() { _ = os.Remove(name) })
+ return name
+}
+
+func appendLine(t *testing.T, path, line string) {
+ t.Helper()
+ f, err := os.OpenFile(path, os.O_APPEND|os.O_WRONLY, 0o644)
+ if err != nil {
+ t.Fatal(err)
+ }
+ defer func() { _ = f.Close() }()
+ if _, err := f.WriteString(line + "\n"); err != nil {
+ t.Fatal(err)
+ }
+}
+
+func readFile(t *testing.T, path string) string {
+ t.Helper()
+ b, err := os.ReadFile(path)
+ if err != nil {
+ t.Fatal(err)
+ }
+ return string(b)
+}
diff --git a/tests/infra/mailpit/mailpit.go b/tests/infra/mailpit/mailpit.go
new file mode 100644
index 0000000000..fb9be0ebcd
--- /dev/null
+++ b/tests/infra/mailpit/mailpit.go
@@ -0,0 +1,64 @@
+// Package mailpit runs a Mailpit container: a fake SMTP server with a search API.
+//
+// Chosen over the dev stack's MailHog for the search API and per-message delete,
+// both of which a parallel suite needs. Isolation between tenants is by address
+// (alice@<orgslug>.test), not by running more than one server.
+package mailpit
+
+import (
+ "context"
+
+ "github.com/Infisical/infisical/tests/infra"
+)
+
+const (
+ Key = infra.Key("mailpit")
+
+ smtpPort = 1025
+ apiPort = 8025
+)
+
+type module struct{ image string }
+
+type Option func(*module)
+
+func WithImage(img string) Option { return func(m *module) { m.image = img } }
+
+func Module(opts ...Option) infra.Module {
+ m := &module{image: "axllent/mailpit:latest"}
+ for _, o := range opts {
+ o(m)
+ }
+ return m
+}
+
+func (m *module) Key() infra.Key { return Key }
+func (m *module) Requires() []infra.Key { return nil }
+func (m *module) Optional() []infra.Key { return nil }
+func (m *module) Name() infra.NameParts { return infra.NameParts{Module: "mailpit"} }
+
+func (m *module) Start(ctx context.Context, d infra.Deps) (infra.Handle, error) {
+ c, err := d.Run(ctx, infra.ContainerSpec{
+ Image: m.image,
+ Ports: []int{smtpPort, apiPort},
+ Ready: infra.HTTPReady(apiPort, "/api/v1/info"),
+ })
+ if err != nil {
+ return nil, err
+ }
+ return &Handle{c: c}, nil
+}
+
+// Handle is a running Mailpit.
+type Handle struct{ c infra.Container }
+
+// Endpoint is the SMTP endpoint, which is what a container needs. The test process
+// wants API instead.
+func (h *Handle) Endpoint(m infra.Mode) infra.Endpoint { return h.c.Endpoint(m, smtpPort) }
+func (h *Handle) Stop(ctx context.Context) error { return h.c.Stop(ctx) }
+
+// API is the HTTP endpoint the harness reads messages from. Almost always External:
+// the Go test process polls it, not a container.
+func (h *Handle) API(m infra.Mode) infra.Endpoint { return h.c.Endpoint(m, apiPort) }
+
+func From(d infra.Deps) (*Handle, bool) { return d.Get[*Handle](Key) }
diff --git a/tests/infra/module_test.go b/tests/infra/module_test.go
index 2c68810d5c..c5ae700fe6 100644
--- a/tests/infra/module_test.go
+++ b/tests/infra/module_test.go
@@ -50,9 +50,6 @@ func TestResolve(t *testing.T) {
t.Run("ok/an optional dependency that is absent is not an error", func(t *testing.T) {
t.Parallel()
- spec.Why(t, `Infisical consumes wiremock and smtp if present and ignores them if not,
- which is what lets a suite opt out of stubbing without a second code path.`)
-
_, err := Resolve(
mods(fakeModule{key: "infisical", optional: []Key{"wiremock"}}),
map[Key]Scope{"infisical": Shared},
@@ -62,11 +59,8 @@ func TestResolve(t *testing.T) {
}
})
- t.Run("invalid/a missing required dependency names the fix", func(t *testing.T) {
+ t.Run("invalid/a missing required dependency fails before any container starts", func(t *testing.T) {
t.Parallel()
- spec.Why(t, `This has to fail before any container starts. Otherwise it surfaces as a
- connection timeout ninety seconds later, pointing at the wrong thing.`)
-
_, err := Resolve(
mods(fakeModule{key: "infisical", requires: []Key{"postgres"}}),
map[Key]Scope{"infisical": Shared},
@@ -102,11 +96,8 @@ func TestResolve(t *testing.T) {
}
})
- t.Run("ok/a shorter lived module may depend on a longer lived one", func(t *testing.T) {
+ t.Run("ok/a package scoped module may depend on a shared one", func(t *testing.T) {
t.Parallel()
- spec.Why(t, `An Isolated package starts its own Infisical but still adopts the shared
- Mailpit, which is the whole reason mixed scopes inside one package must work.`)
-
_, err := Resolve(
mods(
fakeModule{key: "infisical", optional: []Key{"mailpit"}},
@@ -160,10 +151,6 @@ func TestDepsGet(t *testing.T) {
t.Run("notfound/an absent optional module reports false rather than panicking", func(t *testing.T) {
t.Parallel()
- spec.Why(t, `Optional dependencies are the whole reason a suite can opt out of WireMock
- or SMTP without a second code path. If an absent one panicked, every consumer would
- need a nil check and the option would stop being optional.`)
-
if _, ok := deps.Get[pgHandle]("redis"); ok {
t.Fatal("absent module reported as present")
}
diff --git a/tests/infra/names_test.go b/tests/infra/names_test.go
index b78a59c88f..f9dc0b8444 100644
--- a/tests/infra/names_test.go
+++ b/tests/infra/names_test.go
@@ -11,7 +11,6 @@ func TestContainerName(t *testing.T) {
for _, tc := range []struct {
name string
- why string
in NameParts
want string
}{
@@ -22,21 +21,16 @@ func TestContainerName(t *testing.T) {
},
{
name: "ok/a Named instance is distinct from the default",
- why: "The rotation suites need a target database separate from the app's own.",
in: NameParts{Scope: Shared, Module: "postgres", Instance: "rotation"},
want: "inf-shared-postgres-rotation",
},
{
name: "ok/infisical carries its image id",
- why: `A stale app container runs your previous code and every test still passes, ` +
- `so this is the one place staleness is silent and needs a fingerprint.`,
in: NameParts{Scope: Shared, Module: "infisical", Fingerprint: "9f8e7d6c"},
want: "inf-shared-infisical-9f8e7d6c",
},
{
name: "ok/package scope is qualified by package path",
- why: `Two Isolated packages running under -p 4 must not adopt each other's ` +
- `containers, which is the precise opposite of what Isolated means.`,
in: NameParts{Scope: Package, ScopeID: "suites/instance", Module: "postgres"},
want: "inf-pkg-suites-instance-postgres",
},
@@ -47,14 +41,12 @@ func TestContainerName(t *testing.T) {
},
{
name: "ok/unsafe characters fold to hyphens",
- why: "Docker accepts [a-zA-Z0-9][a-zA-Z0-9_.-]* only, so a package path has to fold.",
in: NameParts{Scope: Package, ScopeID: "Suites/PKI v2", Module: "postgres"},
want: "inf-pkg-suites-pki-v2-postgres",
},
} {
t.Run(tc.name, func(t *testing.T) {
t.Parallel()
- spec.Why(t, tc.why)
if got := ContainerName(tc.in); got != tc.want {
t.Fatalf("ContainerName() = %q, want %q", got, tc.want)
}
diff --git a/tests/infra/postgres/postgres_test.go b/tests/infra/postgres/postgres_test.go
index a8417bb2ce..0d9c9b5865 100644
--- a/tests/infra/postgres/postgres_test.go
+++ b/tests/infra/postgres/postgres_test.go
@@ -8,7 +8,6 @@ import (
"github.com/Infisical/infisical/tests/infra"
"github.com/Infisical/infisical/tests/infra/postgres"
- "github.com/Infisical/infisical/tests/internal/spec"
)
// These need Docker. Skipped when INFRA_DOCKER_TESTS is unset so `make test-unit`
@@ -49,12 +48,9 @@ func TestPostgres_Start(t *testing.T) {
requireDocker(t)
t.Parallel()
- t.Run("ok/is accepting connections once Start returns", func(t *testing.T) {
+ t.Run("ok/accepts connections by the time Start returns, not merely running", func(t *testing.T) {
requireDocker(t)
t.Parallel()
- spec.Why(t, `The container being "running" is not the same as Postgres accepting
- connections, which is why readiness is pg_isready rather than a port check.`)
-
pg := start(t)
if got := pg.Endpoint(infra.External).Port; got == 0 || got == 5432 {
t.Fatalf("external port should be an ephemeral mapping, got %d", got)
@@ -64,10 +60,6 @@ func TestPostgres_Start(t *testing.T) {
t.Run("ok/internal and external addresses differ", func(t *testing.T) {
requireDocker(t)
t.Parallel()
- spec.Why(t, `Handing an Internal address to the test process, or an External one to
- another container, is the most common way to misuse a container harness. The two
- must be distinguishable at every call site.`)
-
pg := start(t)
in, ex := pg.Endpoint(infra.Internal), pg.Endpoint(infra.External)
if in.Port != 5432 {
@@ -84,9 +76,6 @@ func TestPostgres_Start(t *testing.T) {
t.Run("ok/a Named instance is a separate container", func(t *testing.T) {
requireDocker(t)
t.Parallel()
- spec.Why(t, `The rotation suites rotate credentials against a target database that
- must not be the application's own.`)
-
app := start(t)
target := start(t, postgres.Named("rotation"), postgres.WithDatabase("rotation_target"))
diff --git a/tests/infra/redis/redis.go b/tests/infra/redis/redis.go
new file mode 100644
index 0000000000..791f05c00c
--- /dev/null
+++ b/tests/infra/redis/redis.go
@@ -0,0 +1,80 @@
+// Package redis runs a Redis container for the harness.
+package redis
+
+import (
+ "context"
+ "fmt"
+
+ "github.com/Infisical/infisical/tests/infra"
+)
+
+const (
+ Key = infra.Key("redis")
+ port = 6379
+)
+
+type module struct {
+ instance string
+ image string
+}
+
+type Option func(*module)
+
+func Named(name string) Option { return func(m *module) { m.instance = name } }
+func WithImage(img string) Option { return func(m *module) { m.image = img } }
+
+func Module(opts ...Option) infra.Module {
+ m := &module{image: "redis:7-alpine"}
+ for _, o := range opts {
+ o(m)
+ }
+ return m
+}
+
+func (m *module) Key() infra.Key {
+ if m.instance == "" {
+ return Key
+ }
+ return Key + infra.Key(":"+m.instance)
+}
+
+func (m *module) Requires() []infra.Key { return nil }
+func (m *module) Optional() []infra.Key { return nil }
+func (m *module) Name() infra.NameParts {
+ return infra.NameParts{Module: "redis", Instance: m.instance}
+}
+
+func (m *module) Start(ctx context.Context, d infra.Deps) (infra.Handle, error) {
+ c, err := d.Run(ctx, infra.ContainerSpec{
+ Image: m.image,
+ Ports: []int{port},
+ Ready: infra.ExecReady("redis-cli", "ping"),
+ })
+ if err != nil {
+ return nil, err
+ }
+ return &Handle{c: c}, nil
+}
+
+// Handle is a running Redis.
+//
+// Deliberately never flushed mid-run. It is shared, so a suite that depends on a
+// clean Redis is a suite that will break another one.
+type Handle struct{ c infra.Container }
+
+func (h *Handle) Endpoint(m infra.Mode) infra.Endpoint { return h.c.Endpoint(m, port) }
+func (h *Handle) Stop(ctx context.Context) error { return h.c.Stop(ctx) }
+
+func (h *Handle) URL(m infra.Mode) string {
+ return fmt.Sprintf("redis://%s", h.Endpoint(m).HostPort())
+}
+
+func From(d infra.Deps) (*Handle, bool) { return d.Get[*Handle](Key) }
+
+func MustFrom(d infra.Deps) *Handle {
+ h, ok := From(d)
+ if !ok {
+ panic("infra/redis: MustFrom called for a module that was not declared")
+ }
+ return h
+}
diff --git a/tests/infra/runner.go b/tests/infra/runner.go
index 2518229d23..03b40fcd95 100644
--- a/tests/infra/runner.go
+++ b/tests/infra/runner.go
@@ -90,7 +90,8 @@ func (r *dockerRunner) Run(ctx context.Context, spec ContainerSpec) (Container,
if alias == "" {
alias = spec.Name
}
- opts = append(opts, network.WithNetworkName([]string{alias}, r.netName))
+ aliases := append([]string{alias}, spec.Aliases...)
+ opts = append(opts, network.WithNetworkName(aliases, r.netName))
}
for _, f := range spec.Files {
mode := f.Mode
@@ -104,6 +105,14 @@ func (r *dockerRunner) Run(ctx context.Context, spec ContainerSpec) (Container,
}))
}
+ // Serialize on the container name. Four binaries starting at once all find no
+ // container and all try to create it, which is the race reuse-by-name has.
+ release, err := Lock("container-" + spec.Name)
+ if err != nil {
+ return Container{}, err
+ }
+ defer release()
+
dc, err := testcontainers.Run(ctx, spec.Image, opts...)
if err != nil {
return Container{}, fmt.Errorf("infra: starting %s (%s): %w", spec.Name, spec.Image, err)
diff --git a/tests/infra/stack_test.go b/tests/infra/stack_test.go
new file mode 100644
index 0000000000..1f8ad28453
--- /dev/null
+++ b/tests/infra/stack_test.go
@@ -0,0 +1,97 @@
+package infra_test
+
+import (
+ "context"
+ "testing"
+
+ "github.com/Infisical/infisical/tests/infra"
+ "github.com/Infisical/infisical/tests/infra/mailpit"
+ "github.com/Infisical/infisical/tests/infra/postgres"
+ "github.com/Infisical/infisical/tests/infra/redis"
+ "github.com/Infisical/infisical/tests/infra/wiremock"
+ "github.com/Infisical/infisical/tests/internal/spec"
+)
+
+// startAll resolves and starts a module set the way the harness will, so this
+// exercises the graph, the runner and every module together rather than one at a
+// time.
+func startAll(t *testing.T, mods []infra.Module, scope infra.Scope) map[infra.Key]infra.Handle {
+ t.Helper()
+ ctx := t.Context()
+
+ scopes := make(map[infra.Key]infra.Scope, len(mods))
+ for _, m := range mods {
+ scopes[m.Key()] = scope
+ }
+ plan, err := infra.Resolve(mods, scopes)
+ if err != nil {
+ t.Fatalf("resolve: %v", err)
+ }
+
+ log := infra.NewLogger()
+ runner := infra.NewRunner(infra.Workspace(), log)
+ if err := runner.Network(ctx, infra.NetworkName); err != nil {
+ t.Fatalf("network: %v", err)
+ }
+
+ handles := map[infra.Key]infra.Handle{}
+ for _, m := range plan.Modules() {
+ name := m.Name()
+ name.Scope = infra.Test
+ name.ScopeID = "m1smoke"
+
+ h, err := m.Start(ctx, infra.NewDeps(handles, infra.NetworkName, infra.Workspace(), name, runner))
+ if err != nil {
+ t.Fatalf("start %s: %v", m.Key(), err)
+ }
+ handles[m.Key()] = h
+ t.Cleanup(func() { _ = h.Stop(context.WithoutCancel(ctx)) })
+ log.Decision("ready", infra.ContainerName(name), h.Endpoint(infra.External), 0, "")
+ }
+ return handles
+}
+
+func TestStack_AllModulesComeUpTogether(t *testing.T) {
+ requireDocker(t)
+ spec.Why(t, `Every module passes on its own. What this proves is that they come up
+ through the real graph on one shared network, which is the only arrangement the
+ harness ever actually uses.`)
+
+ handles := startAll(t, []infra.Module{
+ postgres.Module(),
+ redis.Module(),
+ mailpit.Module(),
+ wiremock.Module(),
+ }, infra.Shared)
+
+ t.Run("ok/every module reports a usable external address", func(t *testing.T) {
+ for key, h := range handles {
+ if e := h.Endpoint(infra.External); e.Host == "" || e.Port == 0 {
+ t.Errorf("%s external endpoint is unusable: %+v", key, e)
+ }
+ }
+ })
+
+ t.Run("ok/internal addresses are container aliases, not host addresses", func(t *testing.T) {
+ for key, h := range handles {
+ in := h.Endpoint(infra.Internal)
+ if in.Host == "localhost" || in.Host == "127.0.0.1" {
+ t.Errorf("%s internal host is a host address: %s", key, in.Host)
+ }
+ }
+ })
+
+ t.Run("ok/mailpit exposes SMTP and its API on different ports", func(t *testing.T) {
+ mp := handles[mailpit.Key].(*mailpit.Handle)
+ if smtp, api := mp.Endpoint(infra.Internal).Port, mp.API(infra.Internal).Port; smtp == api {
+ t.Fatalf("SMTP and API share port %d; the application dials one and the harness reads the other", smtp)
+ }
+ })
+
+ t.Run("ok/wiremock serves its admin API", func(t *testing.T) {
+ wm := handles[wiremock.Key].(*wiremock.Handle)
+ if got := wm.AdminURL(infra.External); got == "" {
+ t.Fatal("no admin URL")
+ }
+ })
+}
diff --git a/tests/infra/wiremock/wiremock.go b/tests/infra/wiremock/wiremock.go
new file mode 100644
index 0000000000..d60ade3d3d
--- /dev/null
+++ b/tests/infra/wiremock/wiremock.go
@@ -0,0 +1,112 @@
+// Package wiremock runs a WireMock container in browser-proxying mode.
+//
+// It intercepts at the network boundary rather than inside the process, which is the
+// point: a Go reimplementation of the API inherits it unchanged, unlike the in-app
+// nock control API the Python BDD suite uses.
+package wiremock
+
+import (
+ "context"
+
+ "github.com/Infisical/infisical/tests/infra"
+)
+
+const (
+ Key = infra.Key("wiremock")
+
+ port = 8080
+
+ // CAPath is where the harness places WireMock's CA inside the application
+ // container, for NODE_EXTRA_CA_CERTS.
+ CAPath = "/wiremock-ca.pem"
+)
+
+type module struct {
+ image string
+ aliases []string
+ flags []string
+}
+
+type Option func(*module)
+
+func WithImage(img string) Option { return func(m *module) { m.image = img } }
+
+// WithHostAliases resolves the given hostnames to WireMock over Docker DNS.
+//
+// The escape hatch for clients that ignore HTTP_PROXY, which is most cloud SDKs.
+// Aliases are fixed at container start, so under a Shared profile this list is
+// run-wide; a package needing a private alias has to take its own stack.
+func WithHostAliases(hosts ...string) Option {
+ return func(m *module) { m.aliases = append(m.aliases, hosts...) }
+}
+
+func WithFlags(flags ...string) Option {
+ return func(m *module) { m.flags = append(m.flags, flags...) }
+}
+
+func Module(opts ...Option) infra.Module {
+ m := &module{
+ image: "wiremock/wiremock:3.13.1",
+ flags: []string{
+ "--enable-browser-proxying",
+ "--trust-all-proxy-targets",
+ // The journal is global and unbounded by default. Every query filters by
+ // tenant, and resetRequests must never be called, so the only bound is
+ // this cap.
+ "--max-request-journal-entries", "20000",
+ },
+ }
+ for _, o := range opts {
+ o(m)
+ }
+ return m
+}
+
+func (m *module) Key() infra.Key { return Key }
+func (m *module) Requires() []infra.Key { return nil }
+func (m *module) Optional() []infra.Key { return nil }
+func (m *module) Name() infra.NameParts { return infra.NameParts{Module: "wiremock"} }
+
+func (m *module) Start(ctx context.Context, d infra.Deps) (infra.Handle, error) {
+ c, err := d.Run(ctx, infra.ContainerSpec{
+ Image: m.image,
+ Command: m.flags,
+ Ports: []int{port},
+ Aliases: m.aliases,
+ Ready: infra.HTTPReady(port, "/__admin/mappings"),
+ })
+ if err != nil {
+ return nil, err
+ }
+ return &Handle{c: c}, nil
+}
+
+// Handle is a running WireMock.
+type Handle struct{ c infra.Container }
+
+func (h *Handle) Endpoint(m infra.Mode) infra.Endpoint { return h.c.Endpoint(m, port) }
+func (h *Handle) Stop(ctx context.Context) error { return h.c.Stop(ctx) }
+
+// AdminURL is where stubs are registered and the journal is queried. External: the
+// Go test process talks to it.
+func (h *Handle) AdminURL(m infra.Mode) string {
+ return h.Endpoint(m).URL("http") + "/__admin"
+}
+
+// ProxyURL is what the application container gets as HTTP_PROXY. Internal: a
+// container talks to it.
+func (h *Handle) ProxyURL(m infra.Mode) string {
+ return h.Endpoint(m).URL("http")
+}
+
+// NoProxy keeps traffic to the harness's own containers off the proxy. Without it,
+// Infisical would try to reach Postgres through WireMock.
+func NoProxy(hosts ...string) string {
+ out := "localhost,127.0.0.1"
+ for _, h := range hosts {
+ out += "," + h
+ }
+ return out
+}
+
+func From(d infra.Deps) (*Handle, bool) { return d.Get[*Handle](Key) }