TestApplicationProxy checks headers passed to DevURL services are as expected.
(t *testing.T)
| 581 | |
| 582 | // TestApplicationProxy checks headers passed to DevURL services are as expected. |
| 583 | func TestApplicationProxy(t *testing.T) { |
| 584 | t.Parallel() |
| 585 | |
| 586 | tests := []struct { |
| 587 | Name string |
| 588 | Config *httpmw.RealIPConfig |
| 589 | Header http.Header |
| 590 | RemoteAddr string |
| 591 | TLS bool |
| 592 | ExpectedHeader http.Header |
| 593 | ExpectedRemoteAddr string |
| 594 | }{ |
| 595 | { |
| 596 | Name: "untrusted-origin-http", |
| 597 | Config: nil, |
| 598 | Header: http.Header{ |
| 599 | "X-Forwarded-For": []string{"123.45.67.89,10.10.10.10"}, |
| 600 | }, |
| 601 | RemoteAddr: "17.18.19.20", |
| 602 | TLS: false, |
| 603 | ExpectedHeader: http.Header{ |
| 604 | "X-Forwarded-For": []string{"17.18.19.20"}, |
| 605 | "X-Forwarded-Proto": []string{"http"}, |
| 606 | }, |
| 607 | ExpectedRemoteAddr: "17.18.19.20", |
| 608 | }, |
| 609 | { |
| 610 | Name: "untrusted-origin-https", |
| 611 | Config: nil, |
| 612 | Header: http.Header{ |
| 613 | "X-Forwarded-For": []string{"123.45.67.89,10.10.10.10"}, |
| 614 | }, |
| 615 | RemoteAddr: "17.18.19.20", |
| 616 | TLS: true, |
| 617 | ExpectedHeader: http.Header{ |
| 618 | "X-Forwarded-For": []string{"17.18.19.20"}, |
| 619 | "X-Forwarded-Proto": []string{"https"}, |
| 620 | }, |
| 621 | ExpectedRemoteAddr: "17.18.19.20", |
| 622 | }, |
| 623 | { |
| 624 | Name: "trusted-real-ip", |
| 625 | Config: &httpmw.RealIPConfig{ |
| 626 | TrustedOrigins: []*net.IPNet{ |
| 627 | { |
| 628 | IP: net.ParseIP("0.0.0.0"), |
| 629 | Mask: net.CIDRMask(0, 32), |
| 630 | }, |
| 631 | }, |
| 632 | TrustedHeaders: []string{ |
| 633 | "X-Real-Ip", |
| 634 | }, |
| 635 | }, |
| 636 | Header: http.Header{ |
| 637 | "X-Real-Ip": []string{"99.88.77.66"}, |
| 638 | "X-Forwarded-For": []string{"123.45.67.89,10.10.10.10"}, |
| 639 | "X-Forwarded-Proto": []string{"https"}, |
| 640 | }, |
nothing calls this directly
no test coverage detected