package forge import ( "context" "encoding/json" "strings" "testing" "amadan.net/oficina/equipo/internal/equipo/team" ) func TestApprovedBeyondProfilePublisher(t *testing.T) { f := newFixture(t) approval := team.ProfileApproval{QuestionID: "q", RequestID: "7", ItemID: "item", TurnID: "turn", SessionID: "session", Person: "owner@example.com", Label: "approved beyond profile", Request: json.RawMessage(`{"command":"printf hello","cwd":"/workspace"}`)} f.auth.Publication.Isolation.ProfileApprovals = []team.ProfileApproval{approval} for _, label := range []string{"unconfined", "unconfined; approved beyond profile"} { desc := team.PublicationDescription{Version: 1, Label: label, Isolation: f.auth.Publication.Isolation} if !strings.Contains(label, approval.Label) { desc.Isolation.ProfileApprovals = nil } description, _ := json.Marshal(desc) f.auth.Publication.Description = string(description) f.auth.Publication.DescriptionHash = Digest([]byte(f.auth.Publication.Description)) raw, _ := json.Marshal(f.auth.Publication) raw, hash, _ := Canonical(raw) f.auth.Ticket.Dispatch.Payload, f.auth.Ticket.Dispatch.Hash = raw, hash err := f.p.validate(f.auth, f.auth.Ticket.Dispatch) if (err == nil) != strings.Contains(label, approval.Label) { t.Fatal("publisher lost profile label guard", label, err) } } _, err := f.p.Execute(context.Background(), f.auth.Ticket.Dispatch) must(t, err) if !strings.Contains(f.desc.value.Body, approval.Label) { t.Fatal("published branch description lost label") } } func TestPublisherChecksDecodedProfileApproval(t *testing.T) { f := newFixture(t) approval := team.ProfileApproval{QuestionID: "q", RequestID: "7", ItemID: "item", TurnID: "turn", SessionID: "session", Person: "owner@example.com", Label: "approved beyond profile", Request: json.RawMessage(`{"command":"printf hello"}`)} f.auth.Publication.Isolation.ProfileApprovals = []team.ProfileApproval{approval} desc := team.PublicationDescription{Version: 1, Label: "unconfined", Isolation: f.auth.Publication.Isolation} for _, valid := range []bool{false, true} { if !valid { desc.Isolation.ProfileApprovals = nil } else { desc.Isolation = f.auth.Publication.Isolation } raw, _ := json.Marshal(desc) body := string(raw) if !valid { body = strings.Replace(body, `"label":"unconfined"`, `"label":"unconfined; approved beyond profile"`, 1) } else { body = strings.ReplaceAll(body, "approved beyond profile", `approved beyond pro\u0066ile`) } f.auth.Publication.Description = body f.auth.Publication.DescriptionHash = Digest([]byte(body)) payload, _ := json.Marshal(f.auth.Publication) payload, hash, _ := Canonical(payload) f.auth.Ticket.Dispatch.Payload, f.auth.Ticket.Dispatch.Hash = payload, hash err := f.p.validate(f.auth, f.auth.Ticket.Dispatch) if (err == nil) != valid { t.Fatalf("decoded approval valid=%v: %v", valid, err) } } }