Expose permission-checked immutable asset metadata for shared depot adoption
Foundry Go checks / check (push) Failing after 6m24s
Foundry Go checks / check (pull_request) Failing after 4m36s

This commit is contained in:
2026-11-09 15:47:19 +08:00
parent 6a0a2e1912
commit 6b07c19728
3 changed files with 71 additions and 1 deletions
+25 -1
View File
@@ -584,9 +584,33 @@ func TestOnboardingAndSharing(t *testing.T) {
t.Fatal("preview changed small original or privacy headers")
}
}
// Metadata discloses the same immutable identity only after a fresh read permission check.
metadataPath := workspacePath + "/assets/" + uploaded["id"].(string) + "/metadata"
for _, sample := range []struct {
token string
status int
}{{tokens[0], 200}, {tokens[1], 404}, {tokens[2], 404}} {
request := httptest.NewRequest("GET", metadataPath, nil)
request.Header.Set("Authorization", "Bearer "+sample.token)
result := httptest.NewRecorder()
mux.ServeHTTP(result, request)
if result.Code != sample.status {
t.Fatalf("metadata permission got %d want %d: %s", result.Code, sample.status, result.Body.String())
}
if result.Code == 200 {
var metadata response
if err := json.Unmarshal(result.Body.Bytes(), &metadata); err != nil {
t.Fatal(err)
}
digest := sha256.Sum256(assetPNG.Bytes())
if metadata["metadata_version"] != float64(1) || metadata["sha256"] != hex.EncodeToString(digest[:]) || !modelEqual(metadata["asset"], uploaded) || result.Header().Get("Cache-Control") != "private, no-store" {
t.Fatalf("invalid metadata identity: %s", result.Body.String())
}
}
}
// Neither a snapshot nor an asset response may keep the workspace locked
// while a slow downstream consumer is accepting its body.
for _, path := range []string{canvasPath, workspacePath + "/assets/" + uploaded["id"].(string)} {
for _, path := range []string{canvasPath, workspacePath + "/assets/" + uploaded["id"].(string), metadataPath} {
var probeErr error
writer := &readLockProbe{ResponseRecorder: httptest.NewRecorder(), probe: func() {
lockTx, e := db.BeginTx(ctx, nil)