forked from longtao.wu/droboticflow
49 lines
1.7 KiB
Go
49 lines
1.7 KiB
Go
package api
|
|
|
|
import (
|
|
"net/http"
|
|
"os"
|
|
"path/filepath"
|
|
"testing"
|
|
|
|
"droboticflow/internal/domain"
|
|
)
|
|
|
|
func TestHumanSubjectMediaHeadSupportsBothCamerasAndRetry(t *testing.T) {
|
|
f := continuousFixture(t)
|
|
root := t.TempDir()
|
|
artifacts := []domain.ExecutionArtifact{}
|
|
for _, side := range []string{"left", "right"} {
|
|
path := filepath.Join(root, side+".mp4")
|
|
if err := os.WriteFile(path, []byte("synthetic-media"), 0600); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
artifacts = append(artifacts, domain.ExecutionArtifact{ID: side, Name: side + ".mp4", Path: path, Type: domain.PortTypeVideo})
|
|
}
|
|
if err := f.store.UpsertRun(f.ctx, domain.RunRecord{ID: f.task.RunID, OrganizationID: f.task.OrganizationID, ProjectID: f.task.ProjectID, Artifacts: artifacts}); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
item := f.item
|
|
item.Subject.ArtifactID = "left"
|
|
item.Subject.Payload["rightArtifactId"] = "right"
|
|
if err := f.store.UpsertHumanItem(f.ctx, item); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
for _, side := range []string{"left", "right"} {
|
|
url := "/api/human-items/" + item.ID + "/subject-content?side=" + side + "&_mediaRetry=synthetic"
|
|
get := f.request(http.MethodGet, url, f.annotator, nil)
|
|
if get.Code != 200 {
|
|
t.Fatalf("GET %s: %d %s", side, get.Code, get.Body.String())
|
|
}
|
|
head := f.request(http.MethodHead, url, f.annotator, nil)
|
|
if head.Code != 200 || head.Body.Len() != 0 || head.Header().Get("Content-Length") != get.Header().Get("Content-Length") {
|
|
t.Fatalf("HEAD %s: status=%d body=%q headers=%v", side, head.Code, head.Body.String(), head.Header())
|
|
}
|
|
foreign := f.annotator
|
|
foreign.ID = "unassigned-media-reader"
|
|
if r := f.request(http.MethodHead, url, foreign, nil); r.Code == 200 {
|
|
t.Fatal("HEAD bypassed subject access control")
|
|
}
|
|
}
|
|
}
|