()
| 189 | } |
| 190 | |
| 191 | func (ts *MiddlewareTestSuite) TestIsValidExternalHost() { |
| 192 | cases := []struct { |
| 193 | desc string |
| 194 | externalHosts []string |
| 195 | |
| 196 | requestURL string |
| 197 | headers http.Header |
| 198 | |
| 199 | expectedURL string |
| 200 | }{ |
| 201 | { |
| 202 | desc: "no defined external hosts, no headers, no absolute request URL", |
| 203 | requestURL: "/some-path", |
| 204 | expectedURL: ts.API.config.API.ExternalURL, |
| 205 | }, |
| 206 | |
| 207 | { |
| 208 | desc: "no defined external hosts, unauthorized X-Forwarded-Host without any external hosts", |
| 209 | headers: http.Header{ |
| 210 | "X-Forwarded-Host": []string{ |
| 211 | "external-host.com", |
| 212 | }, |
| 213 | }, |
| 214 | requestURL: "/some-path", |
| 215 | expectedURL: ts.API.config.API.ExternalURL, |
| 216 | }, |
| 217 | |
| 218 | { |
| 219 | desc: "defined external hosts, unauthorized X-Forwarded-Host", |
| 220 | externalHosts: []string{"authorized-host.com"}, |
| 221 | headers: http.Header{ |
| 222 | "X-Forwarded-Proto": []string{"https"}, |
| 223 | "X-Forwarded-Host": []string{ |
| 224 | "external-host.com", |
| 225 | }, |
| 226 | }, |
| 227 | requestURL: "/some-path", |
| 228 | expectedURL: ts.API.config.API.ExternalURL, |
| 229 | }, |
| 230 | |
| 231 | { |
| 232 | desc: "no defined external hosts, unauthorized Host", |
| 233 | requestURL: "https://external-host.com/some-path", |
| 234 | expectedURL: ts.API.config.API.ExternalURL, |
| 235 | }, |
| 236 | |
| 237 | { |
| 238 | desc: "defined external hosts, unauthorized Host", |
| 239 | externalHosts: []string{"authorized-host.com"}, |
| 240 | requestURL: "https://external-host.com/some-path", |
| 241 | expectedURL: ts.API.config.API.ExternalURL, |
| 242 | }, |
| 243 | |
| 244 | { |
| 245 | desc: "defined external hosts, authorized X-Forwarded-Host", |
| 246 | externalHosts: []string{"authorized-host.com"}, |
| 247 | headers: http.Header{ |
| 248 | "X-Forwarded-Proto": []string{"http"}, // this should be ignored and default to HTTPS |
nothing calls this directly
no test coverage detected