Fix conversion of static responses in upstreams

This commit is contained in:
Joel Speed
2020-08-31 16:54:01 +01:00
parent 73f0094486
commit b40517bbe3
5 changed files with 33 additions and 16 deletions
+5 -4
View File
@@ -97,17 +97,18 @@ func (l *LegacyUpstreams) convert() (Upstreams, error) {
upstream.Static = true
upstream.StaticCode = &responseCode
// These are not allowed to be empty and must be unique
// This is not allowed to be empty and must be unique
upstream.ID = upstreamString
upstream.Path = upstreamString
// We only support the root path in the legacy config
upstream.Path = "/"
// Force defaults compatible with static responses
upstream.URI = ""
upstream.InsecureSkipTLSVerify = false
upstream.PassHostHeader = nil
upstream.ProxyWebSockets = nil
flush := 1 * time.Second
upstream.FlushInterval = &flush
upstream.FlushInterval = nil
}
upstreams = append(upstreams, upstream)
+17 -7
View File
@@ -21,9 +21,10 @@ var _ = Describe("Legacy Options", func() {
legacyOpts.LegacyUpstreams.PassHostHeader = true
legacyOpts.LegacyUpstreams.ProxyWebSockets = true
legacyOpts.LegacyUpstreams.SSLUpstreamInsecureSkipVerify = true
legacyOpts.LegacyUpstreams.Upstreams = []string{"http://foo.bar/baz", "file://var/lib/website#/bar"}
legacyOpts.LegacyUpstreams.Upstreams = []string{"http://foo.bar/baz", "file://var/lib/website#/bar", "static://204"}
truth := true
staticCode := 204
opts.UpstreamServers = Upstreams{
{
ID: "/baz",
@@ -43,6 +44,17 @@ var _ = Describe("Legacy Options", func() {
PassHostHeader: &truth,
ProxyWebSockets: &truth,
},
{
ID: "static://204",
Path: "/",
URI: "",
Static: true,
StaticCode: &staticCode,
FlushInterval: nil,
InsecureSkipTLSVerify: false,
PassHostHeader: nil,
ProxyWebSockets: nil,
},
}
converted, err := legacyOpts.ToOptions()
@@ -58,8 +70,6 @@ var _ = Describe("Legacy Options", func() {
errMsg string
}
defaultFlushInterval := 1 * time.Second
// Non defaults for these options
skipVerify := true
passHostHeader := false
@@ -105,28 +115,28 @@ var _ = Describe("Legacy Options", func() {
validStaticCode := 204
validStaticUpstream := Upstream{
ID: validStatic,
Path: validStatic,
Path: "/",
URI: "",
Static: true,
StaticCode: &validStaticCode,
InsecureSkipTLSVerify: false,
PassHostHeader: nil,
ProxyWebSockets: nil,
FlushInterval: &defaultFlushInterval,
FlushInterval: nil,
}
invalidStatic := "static://abc"
invalidStaticCode := 200
invalidStaticUpstream := Upstream{
ID: invalidStatic,
Path: invalidStatic,
Path: "/",
URI: "",
Static: true,
StaticCode: &invalidStaticCode,
InsecureSkipTLSVerify: false,
PassHostHeader: nil,
ProxyWebSockets: nil,
FlushInterval: &defaultFlushInterval,
FlushInterval: nil,
}
invalidHTTP := ":foo"