Skip to content

Commit 280217b

Browse files
committed
BUG: Allows httpsPort and srcPort to work together
1 parent 27ae3ba commit 280217b

2 files changed

Lines changed: 38 additions & 1 deletion

File tree

proxy/ha_proxy_test.go

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1861,6 +1861,43 @@ func (s HaProxyTestSuite) Test_CreateConfigFromTemplates_AddsContentFrontEndWith
18611861
s.Equal(expectedData, actualData)
18621862
}
18631863

1864+
func (s HaProxyTestSuite) Test_CreateConfigFromTemplates_AddsContentFrontEndWithHttpsPort_WithSrcPort() {
1865+
var actualData string
1866+
tmpl := s.TemplateContent
1867+
expectedData := fmt.Sprintf(
1868+
`%s
1869+
acl url_my-service1111_0 path_beg /path
1870+
acl srcPort_my-service8080_0 dst_port 8080
1871+
acl http_my-service_0 dst_port 8080
1872+
acl https_my-service_0 dst_port 443
1873+
use_backend my-service-be1111_0 if url_my-service1111_0 srcPort_my-service8080_0 http_my-service_0
1874+
use_backend https-my-service-be1111_0 if url_my-service1111_0 https_my-service_0%s`,
1875+
tmpl,
1876+
s.ServicesContent,
1877+
)
1878+
writeFile = func(filename string, data []byte, perm os.FileMode) error {
1879+
actualData = string(data)
1880+
return nil
1881+
}
1882+
p := NewHaProxy(s.TemplatesPath, s.ConfigsPath)
1883+
service1 := Service{
1884+
ServiceName: "my-service",
1885+
PathType: "path_beg",
1886+
HttpsPort: 2222,
1887+
AclName: "my-service",
1888+
ServiceDest: []ServiceDest{
1889+
{Port: "1111", ServicePath: []string{"/path"},
1890+
SrcPort: 8080},
1891+
},
1892+
}
1893+
p.AddService(service1)
1894+
1895+
FormatServiceForTemplates(&service1)
1896+
p.CreateConfigFromTemplates()
1897+
1898+
s.Equal(expectedData, actualData)
1899+
}
1900+
18641901
func (s HaProxyTestSuite) Test_CreateConfigFromTemplates_ForwardsToHttps_WhenRedirectWhenHttpProtoIsTrue() {
18651902
var actualData string
18661903
tmpl := s.TemplateContent

proxy/template.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ func getFrontTemplate(s Service) string {
3838
{{- end}}
3939
{{- end}}
4040
{{- if gt $.HttpsPort 0 }}
41-
acl http_{{$.ServiceName}}_{{.Index}} dst_port 80
41+
acl http_{{$.ServiceName}}_{{.Index}} dst_port {{ if gt .SrcPort 0 }}{{.SrcPort}}{{ else }}80{{ end }}
4242
acl https_{{$.ServiceName}}_{{.Index}} dst_port 443
4343
{{- end}}
4444
{{- range $rd := $sd.RedirectFromDomain}}

0 commit comments

Comments
 (0)