package forward import ( "net/http" "testing" ) func TestCopyAllowedHeaders_supervise(t *testing.T) { src := http.Header{} src.Set("Content-Type", "application/json") src.Set("X-Ca-Signature", "sig123") src.Set("requestBody", "cipher") src.Set("Cookie", "junk") src.Set("User-Agent", "Go-http-client/1.1") src.Set("X-Forwarded-For", "1.2.3.4") dst := make(http.Header) copyAllowedHeaders(dst, src, "supervise") if dst.Get("Cookie") != "" || dst.Get("User-Agent") != "" || dst.Get("X-Forwarded-For") != "" { t.Fatalf("junk headers must be stripped: %v", dst) } if dst.Get("Content-Type") != "application/json" { t.Fatalf("Content-Type: %v", dst) } if dst.Get("X-Ca-Signature") != "sig123" { t.Fatalf("X-Ca-Signature: %v", dst) } if dst.Get("Requestbody") != "cipher" { t.Fatalf("requestBody: %v", dst) } } func TestCopyAllowedHeaders_file(t *testing.T) { src := http.Header{} src.Set("Content-Type", "multipart/form-data; boundary=abc") src.Set("X-Authorization", "token") src.Set("Cookie", "x") dst := make(http.Header) copyAllowedHeaders(dst, src, "file") if dst.Get("Cookie") != "" { t.Fatal("cookie must be stripped") } if dst.Get("Content-Type") == "" || dst.Get("X-Authorization") == "" { t.Fatalf("missing required headers: %v", dst) } }