Files
Pulse/internal/api/log_bundle_authority_test.go
pulse-triage[bot] b4c317d0ae Withhold report downloads after credential withdrawal
Keep single-resource GET/POST, fleet and VM-inventory downloads bound to their admitted token or session at each output write, including extension renderers. Reuse the synchronous response guard without adding instance-wide administration or cancelling background schedules. Keep report PDF/CSV and JSON errors separate from Assistant JSON and diagnostic ZIP media policies.

Cover persisted token deletion and logout through all four native HTTP journeys, independent readers, prefix withholding, expiry, identity, scope and organization changes, closed media choices and returned-writer closure.

Contract-Neutral: Enforce existing report confidentiality during credential withdrawal; preserve routes, organization-admin/settings-read grants, licensing, PDF/CSV data and background work.
Change-source: pulse-maintainer
2026-11-01 13:49:41 +00:00

39 lines
1.4 KiB
Go

package api
import (
"net/http/httptest"
"testing"
)
func TestSupportBundleMediaDoesNotWidenAssistantResults(t *testing.T) {
for _, policy := range []struct {
name, media string
policy responseMediaPolicy
}{{"json", "application/json", responseMediaJSON}, {"zip", "application/zip", responseMediaZIP}} {
for _, provided := range []string{"", "application/json", "application/zip", "text/html", "image/svg+xml", "application/json; invalid"} {
t.Run(policy.name+"/"+provided, func(t *testing.T) {
base := httptest.NewRecorder()
writer := &tokenResponseWriter{writer: base, header: base.Header().Clone(), allowed: func() bool { return true }, media: policy.policy}
writer.Header()["content-type"] = []string{"text/html"}
writer.Header().Set("Content-Type", provided)
if _, err := writer.Write([]byte("synthetic bytes")); err != nil {
t.Fatal(err)
}
want := "text/plain; charset=utf-8"
if provided == policy.media {
want = policy.media
}
if base.Header().Get("Content-Type") != want || base.Header().Get("X-Content-Type-Options") != "nosniff" {
t.Fatalf("media = %v", base.Header())
}
if _, exists := base.Header()["content-type"]; exists {
t.Fatal("alternate-case media bypassed boundary")
}
if base.Body.String() != "synthetic bytes" {
t.Fatal("media selection changed body bytes")
}
})
}
}
}