54 lines
2.0 KiB
Go
54 lines
2.0 KiB
Go
package libraryhandoff
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"os"
|
|
"path/filepath"
|
|
"strings"
|
|
"testing"
|
|
"time"
|
|
)
|
|
|
|
// SSH runs its remote shell locally; Docker is an explicit process-boundary
|
|
// fixture. The archive path deliberately does not exist on the SSH host.
|
|
func TestSSHManifestReadUsesExecutorFilesystem(t *testing.T) {
|
|
bin := t.TempDir()
|
|
write := func(name, text string) {
|
|
t.Helper()
|
|
if err := os.WriteFile(filepath.Join(bin, name), []byte(text), 0700); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
}
|
|
write("ssh", "#!/bin/sh\nfor arg do last=$arg; done\nexec /bin/sh -c \"$last\"\n")
|
|
write("docker", `#!/bin/sh
|
|
[ "$1" = exec ] && [ "$2" = fixture-executor ] && [ "$3" = sh ] && [ "$4" = -c ] || exit 91
|
|
case "$5" in *"/executor-only/archive/versions/"*) ;; *) exit 92;; esac
|
|
printf '%s' "$5" > "$MANIFEST_TRACE"
|
|
if [ "$MANIFEST_MODE" = missing ]; then exit 44; fi
|
|
if [ "$MANIFEST_MODE" = denied ]; then exit 13; fi
|
|
printf '%s' '{"container":true}'
|
|
`)
|
|
t.Setenv("PATH", bin+":"+os.Getenv("PATH"))
|
|
trace := filepath.Join(bin, "trace")
|
|
t.Setenv("MANIFEST_TRACE", trace)
|
|
r := &sshRemote{config: Config{SSHTarget: "fixture", SSHConfig: "/unused", ExecutorContainer: "fixture-executor", RemoteArchive: "/executor-only/archive", OpTimeout: time.Second * 5}}
|
|
id := strings.Repeat("a", 64)
|
|
got, err := r.ReadVersionManifest(context.Background(), id)
|
|
if err != nil || string(got) != `{"container":true}` {
|
|
t.Fatalf("must read through executor, got=%s err=%v", got, err)
|
|
}
|
|
cmd, err := os.ReadFile(trace)
|
|
if err != nil || !strings.Contains(string(cmd), id+".json") {
|
|
t.Fatalf("missing exact snapshot read: %s %v", cmd, err)
|
|
}
|
|
t.Setenv("MANIFEST_MODE", "missing")
|
|
if _, err := r.ReadVersionManifest(context.Background(), id); !errors.Is(err, os.ErrNotExist) {
|
|
t.Fatalf("missing manifest: %v", err)
|
|
}
|
|
t.Setenv("MANIFEST_MODE", "denied")
|
|
if _, err := r.ReadVersionManifest(context.Background(), id); err == nil || errors.Is(err, os.ErrNotExist) {
|
|
t.Fatalf("permission failure must not mean absent: %v", err)
|
|
}
|
|
}
|