Files
seaweedfs/seaweed-block/scripts/release_gate_artifact_root_test.go
T
Ping QiuandClaude Opus 5.5 e17e30b4aa seaweed-block: keep only the runner scenarios this tree uses (#13418)
Removes lab-only runner scenarios and suites from seaweed-block/, keeps the scenarios this tree's CI uses with environment placeholders, and guards every artifact-root use before any cleanup. Includes the maintainer's follow-ups from #13419 and #13423.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-12-05 03:20:55 -08:00

74 lines
2.3 KiB
Go

package scripts_test
import (
"os"
"os/exec"
"path/filepath"
"runtime"
"strings"
"testing"
)
func TestReleaseGateRefusesArtifactRootOutsideAllowlist(t *testing.T) {
if runtime.GOOS == "windows" {
t.Skip("bash script")
}
bash, err := exec.LookPath("bash")
if err != nil {
t.Skip("bash not available")
}
script := filepath.Join(repoRoot(t), "scripts", "testops-run-protocol-release-gate.sh")
run := func(root string) (string, string, error) {
artifacts := filepath.Join(t.TempDir(), "gate")
cmd := exec.Command(bash, script, t.TempDir())
cmd.Env = append(os.Environ(),
"SW_BLOCK_SSH_KEY=/k",
"SW_BLOCK_NODE_HOST=192.0.2.10",
"SW_BLOCK_NODE_USER=tester",
"SW_BLOCK_NODE_ARTIFACT_ROOT="+root,
"SW_BLOCK_ARTIFACT_DIR="+artifacts,
"SWBLOCK_CMD=/nonexistent-swblock",
)
out, err := cmd.CombinedOutput()
return string(out), artifacts, err
}
const refusal = "must be an absolute path other than /"
marker := filepath.Join(t.TempDir(), "substituted")
for _, root := range []string{
"/srv/test artifacts",
"/srv/test\tartifacts",
"/",
"relative/dir",
"/srv/*",
"/srv/'$(touch " + marker + ")'",
"/srv/x\n",
} {
out, artifacts, err := run(root)
if err == nil {
t.Fatalf("artifact root %q accepted; output:\n%s", root, out)
}
if !strings.Contains(out, refusal) {
t.Fatalf("artifact root %q: unexpected output:\n%s", root, out)
}
if _, err := os.Stat(artifacts); !os.IsNotExist(err) {
t.Fatalf("artifact root %q: %s created before the check (stat err %v)", root, artifacts, err)
}
}
if _, err := os.Stat(marker); !os.IsNotExist(err) {
t.Fatalf("a command substitution in the artifact root ran (stat err %v)", err)
}
if out, _, _ := run("/srv/evidence-2/block_v1.1"); strings.Contains(out, refusal) {
t.Fatalf("plain absolute artifact root refused:\n%s", out)
}
ps, err := os.ReadFile(filepath.Join(repoRoot(t), "scripts", "testops-run-protocol-release-gate.ps1"))
if err != nil {
t.Fatal(err)
}
check := strings.Index(string(ps), `$NodeArtifactRoot -cnotmatch '^/[A-Za-z0-9._/-]+\z'`)
mkdir := strings.Index(string(ps), "New-Item -ItemType Directory")
if check < 0 || mkdir < 0 || check > mkdir {
t.Fatalf(".ps1 must refuse a NodeArtifactRoot outside the allowlist before it creates directories (check at %d, New-Item at %d)", check, mkdir)
}
}