Each run step goes through mesh-sdk's buildstep.Isolated: no network, none of the account, the workspace read-write, the Go caches beneath a throwaway layer unless the build step is told publish (a trunk build). The integration level runs its store, its bus and its tests in one shut-off process (this program again, level <spec>), so they reach each other and nothing else. build_go_test takes a -run pattern (a try's tests). The module declares the bubblewrap package and refuses a step, unhealthy, while bwrap is missing or older than 0.10. The proof test runs a probe test through the real unit level.
85 lines
2.6 KiB
Go
85 lines
2.6 KiB
Go
//go:build integration
|
|
|
|
package main
|
|
|
|
import (
|
|
"context"
|
|
"encoding/json"
|
|
"net"
|
|
"os"
|
|
"path/filepath"
|
|
"testing"
|
|
)
|
|
|
|
// 1309-S6 (ADR 0448's check): a test of the change, run by the unit level, reads no key and no login of the account,
|
|
// resolves no name, reaches no socket of the machine (a TCP port on its loopback, a unix socket) and leaves the shared
|
|
// caches unchanged. The probe is testdata/repos/probe.
|
|
func TestARunStepReachesNoKeyLoginNameOrSocketAndLeavesTheCachesUnchanged(t *testing.T) {
|
|
needTools(t, "the shut-off unit level", "go", "git", "bwrap")
|
|
tree := repository(t, "probe")
|
|
work, err := os.MkdirTemp("", "w")
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
t.Cleanup(func() { os.RemoveAll(work) })
|
|
if err := os.MkdirAll(filepath.Join(work, "ws1"), 0o755); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if err := os.Rename(tree, filepath.Join(work, "ws1", "tree")); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
home := t.TempDir()
|
|
key, login := filepath.Join(home, ".ssh", "mesh_ed25519"), filepath.Join(home, "broker")
|
|
for _, f := range []string{key, login} {
|
|
if err := os.MkdirAll(filepath.Dir(f), 0o700); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if err := os.WriteFile(f, []byte("secret"), 0o600); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
}
|
|
tcp, err := net.Listen("tcp", "127.0.0.1:0")
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
defer tcp.Close()
|
|
sockDir := t.TempDir()
|
|
unix, err := net.Listen("unix", filepath.Join(sockDir, "s"))
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
defer unix.Close()
|
|
m := &Module{Recipe: Current(), Home: home, Work: work, Cache: t.TempDir()}
|
|
m.Run = StepRunner(home)
|
|
for _, c := range m.caches() {
|
|
if err := os.MkdirAll(c, 0o700); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
}
|
|
res, err := m.runLevel(context.Background(), filepath.Join(work, "ws1", "tree"), levelOpts{workspace: "ws1", level: LevelUnit,
|
|
bounds: Bounds{Run: UnitBound * 100}, env: []string{"PROBE_KEY=" + key, "PROBE_LOGIN=" + login,
|
|
"PROBE_TCP=" + tcp.Addr().String(), "PROBE_SOCKET=" + filepath.Join(sockDir, "s"), "PROBE_CACHE=" + m.caches()[1]}})
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if !res.Passed {
|
|
t.Fatalf("the probe did not run: %+v", res)
|
|
}
|
|
raw, err := os.ReadFile(filepath.Join(work, "ws1", "tree", "seen.json"))
|
|
if err != nil {
|
|
t.Fatalf("the probe wrote nothing: %v", err)
|
|
}
|
|
var seen map[string]bool
|
|
if err := json.Unmarshal(raw, &seen); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
for what, reached := range seen {
|
|
if reached && what != "wroteCache" {
|
|
t.Errorf("the run step reached %s: %s", what, raw)
|
|
}
|
|
}
|
|
if _, err := os.Stat(filepath.Join(m.caches()[1], "written-by-a-candidate")); err == nil {
|
|
t.Errorf("a candidate's step changed the shared cache")
|
|
}
|
|
}
|