@@ -21,10 +21,34 @@ func (s *ProxyProtocolSuite) TestProxyProtocolTrusted(c *check.C) {
21
21
gatewayIP := s .composeProject .Container (c , "haproxy" ).NetworkSettings .Gateway
22
22
haproxyIP := s .composeProject .Container (c , "haproxy" ).NetworkSettings .IPAddress
23
23
whoamiIP := s .composeProject .Container (c , "whoami" ).NetworkSettings .IPAddress
24
+
25
+ file := s .adaptFile (c , "fixtures/proxy-protocol/with.toml" , struct {
26
+ HaproxyIP string
27
+ WhoamiIP string
28
+ }{HaproxyIP : haproxyIP , WhoamiIP : whoamiIP })
29
+ defer os .Remove (file )
30
+
31
+ cmd , display := s .traefikCmd (withConfigFile (file ))
32
+ defer display (c )
33
+ err := cmd .Start ()
34
+ c .Assert (err , checker .IsNil )
35
+ defer cmd .Process .Kill ()
36
+
37
+ err = try .GetRequest ("http://" + haproxyIP + "/whoami" , 500 * time .Millisecond ,
38
+ try .StatusCodeIs (http .StatusOK ),
39
+ try .BodyContains ("X-Forwarded-For: " + gatewayIP ))
40
+ c .Assert (err , checker .IsNil )
41
+ }
42
+
43
+ func (s * ProxyProtocolSuite ) TestProxyProtocolV2Trusted (c * check.C ) {
44
+ gatewayIP := s .composeProject .Container (c , "haproxy" ).NetworkSettings .Gateway
45
+ haproxyIP := s .composeProject .Container (c , "haproxy" ).NetworkSettings .IPAddress
46
+ whoamiIP := s .composeProject .Container (c , "whoami" ).NetworkSettings .IPAddress
47
+
24
48
file := s .adaptFile (c , "fixtures/proxy-protocol/with.toml" , struct {
25
49
HaproxyIP string
26
50
WhoamiIP string
27
- }{haproxyIP , whoamiIP })
51
+ }{HaproxyIP : haproxyIP , WhoamiIP : whoamiIP })
28
52
defer os .Remove (file )
29
53
30
54
cmd , display := s .traefikCmd (withConfigFile (file ))
@@ -33,18 +57,42 @@ func (s *ProxyProtocolSuite) TestProxyProtocolTrusted(c *check.C) {
33
57
c .Assert (err , checker .IsNil )
34
58
defer cmd .Process .Kill ()
35
59
36
- err = try .GetRequest ("http://" + haproxyIP + "/whoami" , 500 * time .Millisecond , try .StatusCodeIs (http .StatusOK ), try .BodyContains ("X-Forwarded-For: " + gatewayIP ))
37
- display (c )
60
+ err = try .GetRequest ("http://" + haproxyIP + ":81/whoami" , 500 * time .Millisecond ,
61
+ try .StatusCodeIs (http .StatusOK ),
62
+ try .BodyContains ("X-Forwarded-For: " + gatewayIP ))
38
63
c .Assert (err , checker .IsNil )
39
64
}
40
65
41
66
func (s * ProxyProtocolSuite ) TestProxyProtocolNotTrusted (c * check.C ) {
42
67
haproxyIP := s .composeProject .Container (c , "haproxy" ).NetworkSettings .IPAddress
43
68
whoamiIP := s .composeProject .Container (c , "whoami" ).NetworkSettings .IPAddress
69
+
70
+ file := s .adaptFile (c , "fixtures/proxy-protocol/without.toml" , struct {
71
+ HaproxyIP string
72
+ WhoamiIP string
73
+ }{HaproxyIP : haproxyIP , WhoamiIP : whoamiIP })
74
+ defer os .Remove (file )
75
+
76
+ cmd , display := s .traefikCmd (withConfigFile (file ))
77
+ defer display (c )
78
+ err := cmd .Start ()
79
+ c .Assert (err , checker .IsNil )
80
+ defer cmd .Process .Kill ()
81
+
82
+ err = try .GetRequest ("http://" + haproxyIP + "/whoami" , 500 * time .Millisecond ,
83
+ try .StatusCodeIs (http .StatusOK ),
84
+ try .BodyContains ("X-Forwarded-For: " + haproxyIP ))
85
+ c .Assert (err , checker .IsNil )
86
+ }
87
+
88
+ func (s * ProxyProtocolSuite ) TestProxyProtocolV2NotTrusted (c * check.C ) {
89
+ haproxyIP := s .composeProject .Container (c , "haproxy" ).NetworkSettings .IPAddress
90
+ whoamiIP := s .composeProject .Container (c , "whoami" ).NetworkSettings .IPAddress
91
+
44
92
file := s .adaptFile (c , "fixtures/proxy-protocol/without.toml" , struct {
45
93
HaproxyIP string
46
94
WhoamiIP string
47
- }{haproxyIP , whoamiIP })
95
+ }{HaproxyIP : haproxyIP , WhoamiIP : whoamiIP })
48
96
defer os .Remove (file )
49
97
50
98
cmd , display := s .traefikCmd (withConfigFile (file ))
@@ -53,7 +101,8 @@ func (s *ProxyProtocolSuite) TestProxyProtocolNotTrusted(c *check.C) {
53
101
c .Assert (err , checker .IsNil )
54
102
defer cmd .Process .Kill ()
55
103
56
- err = try .GetRequest ("http://" + haproxyIP + "/whoami" , 500 * time .Millisecond , try .StatusCodeIs (http .StatusOK ), try .BodyContains ("X-Forwarded-For: " + haproxyIP ))
57
- display (c )
104
+ err = try .GetRequest ("http://" + haproxyIP + ":81/whoami" , 500 * time .Millisecond ,
105
+ try .StatusCodeIs (http .StatusOK ),
106
+ try .BodyContains ("X-Forwarded-For: " + haproxyIP ))
58
107
c .Assert (err , checker .IsNil )
59
108
}
0 commit comments