Validate portable workspace identifiers

This commit is contained in:
2026-08-10 17:35:52 +00:00
parent 0b40cf8026
commit 1dccf5f140
31 changed files with 490 additions and 48 deletions

View File

@@ -0,0 +1,36 @@
package manifest
import (
"context"
"os"
"path/filepath"
"strings"
"testing"
"time"
)
func TestLocalStoreRejectsUnsafeLegacyIdentity(t *testing.T) {
now := time.Now().UTC()
path := filepath.Join(t.TempDir(), "manifest.json")
data := []byte(`{"session_id":"../escape","campaign":"campaign","created_at":"` + now.Format(time.RFC3339Nano) + `","updated_at":"` + now.Format(time.RFC3339Nano) + `","stages":{}}`)
if err := os.WriteFile(path, data, 0o600); err != nil {
t.Fatalf("WriteFile() error = %v", err)
}
_, err := (&LocalStore{}).Load(context.Background(), path)
if err == nil || !strings.Contains(err.Error(), "migrate the legacy manifest") {
t.Fatalf("Load() error = %v, want migration guidance", err)
}
}
func TestLocalStoreRefusesUnsafeIdentityOnSave(t *testing.T) {
now := time.Now().UTC()
m := New("session", now)
m.Campaign = "../outside"
path := filepath.Join(t.TempDir(), "manifest.json")
err := (&LocalStore{}).Save(context.Background(), path, m)
if err == nil || !strings.Contains(err.Error(), "migrate the legacy manifest") {
t.Fatalf("Save() error = %v, want migration guidance", err)
}
}