132 lines
6.3 KiB
Go
132 lines
6.3 KiB
Go
package api
|
|
|
|
import (
|
|
"encoding/json"
|
|
"net/http/httptest"
|
|
"strings"
|
|
"testing"
|
|
|
|
"droboticflow/internal/domain"
|
|
)
|
|
|
|
func TestExecutionArtifactResponseScrubsStorageLocatorsAndDerivesCollectionReference(t *testing.T) {
|
|
item := domain.ExecutionArtifact{
|
|
ID: "manifest-1", RunID: "run-1", NodeID: "node-1", Name: "orbbec-normalized-manifest.json", Type: domain.PortTypeJSON,
|
|
Path: "bos://private-bucket/internal/manifests/normalized.json",
|
|
Data: map[string]any{
|
|
"schemaVersion": "droboticflow.orbbec.normalized/v1",
|
|
"dataRef": map[string]any{"payloadPath": "/workspace/system/runs/run-1/private.json", "connectionId": "conn-private"},
|
|
"source": map[string]any{"previewURL": "https://signed.example.test/private?authorization=secret"},
|
|
},
|
|
Payload: &domain.ArtifactPayload{Mode: domain.ArtifactTransferModeInline, Type: domain.PortTypeJSON, Inline: map[string]any{"items": []any{map[string]any{"path": "bos://private-bucket/private.mp4"}}}},
|
|
}
|
|
response := executionArtifactForResponseAtNode(httptest.NewRequest("GET", "/api/runs/run-1", nil), "run-1", "node-1", item)
|
|
if response.TransferMode != domain.ArtifactTransferModeRef || response.Presentation != artifactPresentationCollection {
|
|
t.Fatalf("historical inline manifest presentation=%q transfer=%q", response.Presentation, response.TransferMode)
|
|
}
|
|
if response.Path != "" || response.Payload != nil {
|
|
t.Fatalf("collection response must not expose historical inline/path payload: %#v", response)
|
|
}
|
|
raw, err := json.Marshal(response)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
for _, forbidden := range []string{"private-bucket", "/workspace/", "connectionId", "authorization=", "previewURL", "dataRef"} {
|
|
if strings.Contains(string(raw), forbidden) {
|
|
t.Fatalf("response leaked %q: %s", forbidden, raw)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestExecutionArtifactResponseKeepsPureInlineValueAndRedactsRefLocator(t *testing.T) {
|
|
inline := executionArtifactForResponseAtNode(httptest.NewRequest("GET", "/api/runs/run-1", nil), "run-1", "node-1", domain.ExecutionArtifact{
|
|
ID: "value-1", RunID: "run-1", NodeID: "node-1", Name: "metrics.json", Type: domain.PortTypeJSON,
|
|
Payload: &domain.ArtifactPayload{Mode: domain.ArtifactTransferModeInline, Type: domain.PortTypeJSON, Inline: map[string]any{"threshold": 0.5, "count": 2}},
|
|
})
|
|
if inline.TransferMode != domain.ArtifactTransferModeInline || inline.Presentation != artifactPresentationValue || inline.Payload == nil || inline.Payload.Inline == nil {
|
|
t.Fatalf("pure inline value was not retained: %#v", inline)
|
|
}
|
|
|
|
ref := executionArtifactForResponseAtNode(httptest.NewRequest("GET", "/api/runs/run-1", nil), "run-1", "node-1", domain.ExecutionArtifact{
|
|
ID: "video-1", RunID: "run-1", NodeID: "node-1", Name: "video.mp4", Type: domain.PortTypeVideo, Path: "bos://private-bucket/private/video.mp4",
|
|
Payload: &domain.ArtifactPayload{Mode: domain.ArtifactTransferModeRef, Type: domain.PortTypeVideo, Ref: &domain.ArtifactReference{Provider: domain.StorageProviderBOS, ConnectionID: "connection-private", Bucket: "private-bucket", Key: "private/video.mp4", SHA256: "hash", SizeBytes: 42, Kind: domain.ArtifactRefKindObject}},
|
|
})
|
|
if ref.TransferMode != domain.ArtifactTransferModeRef || ref.Presentation != artifactPresentationReference || ref.Payload == nil || ref.Payload.Ref == nil {
|
|
t.Fatalf("ref presentation missing: %#v", ref)
|
|
}
|
|
if ref.Path != "" || ref.Payload.Ref.ConnectionID != "" || ref.Payload.Ref.Bucket != "" || ref.Payload.Ref.Key != "" || ref.Payload.Ref.SHA256 != "hash" || ref.Payload.Ref.SizeBytes != 42 {
|
|
t.Fatalf("ref locator was not scrubbed while metadata was retained: %#v", ref)
|
|
}
|
|
}
|
|
|
|
func TestExecutionArtifactResponseKeepsSchemaAnnotatedVideoPreviewable(t *testing.T) {
|
|
item := domain.ExecutionArtifact{
|
|
ID: "rectified-video-1", RunID: "run-1", NodeID: "undistort", PortID: "rectifiedVideos",
|
|
Name: "camera_left_part0001.mp4", Type: domain.PortTypeVideo,
|
|
Data: map[string]any{
|
|
"schemaVersion": "droboticflow.orbbec.rectified-video/v1",
|
|
"collectionId": "capture-1",
|
|
"rectification": map[string]any{"applied": true, "opencvVersion": "4.11.0"},
|
|
},
|
|
Payload: &domain.ArtifactPayload{
|
|
Mode: domain.ArtifactTransferModeRef,
|
|
Type: domain.PortTypeVideo,
|
|
Ref: &domain.ArtifactReference{
|
|
Provider: domain.StorageProviderBOS,
|
|
Kind: domain.ArtifactRefKindObject,
|
|
Bucket: "private-bucket",
|
|
Key: "runs/run-1/rectified/camera_left_part0001.mp4",
|
|
MimeType: "video/mp4",
|
|
},
|
|
},
|
|
}
|
|
|
|
response := executionArtifactForResponseAtNode(
|
|
httptest.NewRequest("GET", "/api/runs/run-1", nil),
|
|
"run-1",
|
|
"undistort",
|
|
item,
|
|
)
|
|
if response.TransferMode != domain.ArtifactTransferModeRef || response.Presentation != artifactPresentationReference {
|
|
t.Fatalf("schema-annotated video presentation=%q transfer=%q", response.Presentation, response.TransferMode)
|
|
}
|
|
if response.Payload == nil || response.Payload.Ref == nil || response.Payload.Ref.MimeType != "video/mp4" {
|
|
t.Fatalf("video reference metadata missing: %#v", response)
|
|
}
|
|
if response.Payload.Ref.Bucket != "" || response.Payload.Ref.Key != "" {
|
|
t.Fatalf("video response leaked storage locator: %#v", response.Payload.Ref)
|
|
}
|
|
}
|
|
|
|
func TestExecutionArtifactResponseKeepsSingleHeadposeManifestPreviewable(t *testing.T) {
|
|
item := domain.ExecutionArtifact{
|
|
ID: "headpose-manifest", RunID: "run-1", NodeID: "headpose", PortID: "out-1",
|
|
Name: "headpose-manifest.json", Type: domain.PortTypeJSON,
|
|
Data: map[string]any{"schemaVersion": "droboticflow.headpose/v1", "frameCount": 105},
|
|
Payload: &domain.ArtifactPayload{
|
|
Mode: domain.ArtifactTransferModeRef,
|
|
Type: domain.PortTypeJSON,
|
|
Ref: &domain.ArtifactReference{
|
|
Provider: domain.StorageProviderBOS,
|
|
Kind: domain.ArtifactRefKindObject,
|
|
Bucket: "private-bucket",
|
|
Key: "runs/run-1/headpose-manifest.json",
|
|
MimeType: "application/json",
|
|
},
|
|
},
|
|
}
|
|
|
|
response := executionArtifactForResponseAtNode(
|
|
httptest.NewRequest("GET", "/api/runs/run-1", nil),
|
|
"run-1",
|
|
"headpose",
|
|
item,
|
|
)
|
|
if response.TransferMode != domain.ArtifactTransferModeRef || response.Presentation != artifactPresentationReference {
|
|
t.Fatalf("HeadPose manifest presentation=%q transfer=%q", response.Presentation, response.TransferMode)
|
|
}
|
|
if response.Payload == nil || response.Payload.Ref == nil || response.Payload.Ref.MimeType != "application/json" {
|
|
t.Fatalf("HeadPose manifest reference metadata missing: %#v", response)
|
|
}
|
|
}
|