@@ -36,64 +36,70 @@ import (
36
36
var (
37
37
// TODO: add tests for secure endpoints
38
38
tmplFuncTestcases = map [string ]struct {
39
- Path string
40
- Target string
41
- Location string
42
- ProxyPass string
43
- AddBaseURL bool
44
- BaseURLScheme string
45
- Sticky bool
39
+ Path string
40
+ Target string
41
+ Location string
42
+ ProxyPass string
43
+ AddBaseURL bool
44
+ BaseURLScheme string
45
+ Sticky bool
46
+ XForwardedPrefix bool
46
47
}{
47
- "invalid redirect / to /" : {"/" , "/" , "/" , "proxy_pass http://upstream-name;" , false , "" , false },
48
+ "invalid redirect / to /" : {"/" , "/" , "/" , "proxy_pass http://upstream-name;" , false , "" , false , false },
48
49
"redirect / to /jenkins" : {"/" , "/jenkins" , "~* /" ,
49
50
`
50
51
rewrite /(.*) /jenkins/$1 break;
51
52
proxy_pass http://upstream-name;
52
- ` , false , "" , false },
53
+ ` , false , "" , false , false },
53
54
"redirect /something to /" : {"/something" , "/" , `~* ^/something\/?(?<baseuri>.*)` , `
54
55
rewrite /something/(.*) /$1 break;
55
56
rewrite /something / break;
56
57
proxy_pass http://upstream-name;
57
- ` , false , "" , false },
58
+ ` , false , "" , false , false },
58
59
"redirect /end-with-slash/ to /not-root" : {"/end-with-slash/" , "/not-root" , "~* ^/end-with-slash/(?<baseuri>.*)" , `
59
60
rewrite /end-with-slash/(.*) /not-root/$1 break;
60
61
proxy_pass http://upstream-name;
61
- ` , false , "" , false },
62
+ ` , false , "" , false , false },
62
63
"redirect /something-complex to /not-root" : {"/something-complex" , "/not-root" , `~* ^/something-complex\/?(?<baseuri>.*)` , `
63
64
rewrite /something-complex/(.*) /not-root/$1 break;
64
65
proxy_pass http://upstream-name;
65
- ` , false , "" , false },
66
+ ` , false , "" , false , false },
66
67
"redirect / to /jenkins and rewrite" : {"/" , "/jenkins" , "~* /" , `
67
68
rewrite /(.*) /jenkins/$1 break;
68
69
proxy_pass http://upstream-name;
69
70
subs_filter '(<(?:H|h)(?:E|e)(?:A|a)(?:D|d)(?:[^">]|"[^"]*")*>)' '$1<base href="$scheme://$http_host/$baseuri">' ro;
70
- ` , true , "" , false },
71
+ ` , true , "" , false , false },
71
72
"redirect /something to / and rewrite" : {"/something" , "/" , `~* ^/something\/?(?<baseuri>.*)` , `
72
73
rewrite /something/(.*) /$1 break;
73
74
rewrite /something / break;
74
75
proxy_pass http://upstream-name;
75
76
subs_filter '(<(?:H|h)(?:E|e)(?:A|a)(?:D|d)(?:[^">]|"[^"]*")*>)' '$1<base href="$scheme://$http_host/something/$baseuri">' ro;
76
- ` , true , "" , false },
77
+ ` , true , "" , false , false },
77
78
"redirect /end-with-slash/ to /not-root and rewrite" : {"/end-with-slash/" , "/not-root" , `~* ^/end-with-slash/(?<baseuri>.*)` , `
78
79
rewrite /end-with-slash/(.*) /not-root/$1 break;
79
80
proxy_pass http://upstream-name;
80
81
subs_filter '(<(?:H|h)(?:E|e)(?:A|a)(?:D|d)(?:[^">]|"[^"]*")*>)' '$1<base href="$scheme://$http_host/end-with-slash/$baseuri">' ro;
81
- ` , true , "" , false },
82
+ ` , true , "" , false , false },
82
83
"redirect /something-complex to /not-root and rewrite" : {"/something-complex" , "/not-root" , `~* ^/something-complex\/?(?<baseuri>.*)` , `
83
84
rewrite /something-complex/(.*) /not-root/$1 break;
84
85
proxy_pass http://upstream-name;
85
86
subs_filter '(<(?:H|h)(?:E|e)(?:A|a)(?:D|d)(?:[^">]|"[^"]*")*>)' '$1<base href="$scheme://$http_host/something-complex/$baseuri">' ro;
86
- ` , true , "" , false },
87
+ ` , true , "" , false , false },
87
88
"redirect /something to / and rewrite with specific scheme" : {"/something" , "/" , `~* ^/something\/?(?<baseuri>.*)` , `
88
89
rewrite /something/(.*) /$1 break;
89
90
rewrite /something / break;
90
91
proxy_pass http://upstream-name;
91
92
subs_filter '(<(?:H|h)(?:E|e)(?:A|a)(?:D|d)(?:[^">]|"[^"]*")*>)' '$1<base href="http://$http_host/something/$baseuri">' ro;
92
- ` , true , "http" , false },
93
+ ` , true , "http" , false , false },
93
94
"redirect / to /something with sticky enabled" : {"/" , "/something" , `~* /` , `
94
95
rewrite /(.*) /something/$1 break;
95
96
proxy_pass http://sticky-upstream-name;
96
- ` , false , "http" , true },
97
+ ` , false , "http" , true , false },
98
+ "add the X-Forwarded-Prefix header" : {"/there" , "/something" , `~* ^/there\/?(?<baseuri>.*)` , `
99
+ rewrite /there/(.*) /something/$1 break;
100
+ proxy_set_header X-Forwarded-Prefix "/there/";
101
+ proxy_pass http://sticky-upstream-name;
102
+ ` , false , "http" , true , true },
97
103
}
98
104
)
99
105
@@ -136,9 +142,10 @@ func TestBuildProxyPass(t *testing.T) {
136
142
137
143
for k , tc := range tmplFuncTestcases {
138
144
loc := & ingress.Location {
139
- Path : tc .Path ,
140
- Rewrite : rewrite.Config {Target : tc .Target , AddBaseURL : tc .AddBaseURL , BaseURLScheme : tc .BaseURLScheme },
141
- Backend : defaultBackend ,
145
+ Path : tc .Path ,
146
+ Rewrite : rewrite.Config {Target : tc .Target , AddBaseURL : tc .AddBaseURL , BaseURLScheme : tc .BaseURLScheme },
147
+ Backend : defaultBackend ,
148
+ XForwardedPrefix : tc .XForwardedPrefix ,
142
149
}
143
150
144
151
backends := []* ingress.Backend {}
0 commit comments