Expose permission-checked immutable asset metadata for shared depot adoption
This commit is contained in:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user