1
0
mirror of https://github.com/oauth2-proxy/oauth2-proxy.git synced 2025-03-23 21:50:48 +02:00

Make the Upstreams mux configurable

This commit changes Upstreams from []Upstream to a struct{}
moving the previous []Upstream into .Configs and adjusts all uses of it.
This commit is contained in:
Fabian Stelzer 2021-08-09 13:32:15 +00:00
parent ae72beb24e
commit 12ab4ef529
No known key found for this signature in database
11 changed files with 283 additions and 231 deletions

@ -25,6 +25,7 @@ client_secret="b2F1dGgyLXByb3h5LWNsaWVudC1zZWNyZXQK"
const testAlphaConfig = ` const testAlphaConfig = `
upstreams: upstreams:
configs:
- id: / - id: /
path: / path: /
uri: http://httpbin uri: http://httpbin
@ -101,6 +102,7 @@ redirect_url="http://localhost:4180/oauth2/callback"
opts.RawRedirectURL = "http://localhost:4180/oauth2/callback" opts.RawRedirectURL = "http://localhost:4180/oauth2/callback"
opts.UpstreamServers = options.Upstreams{ opts.UpstreamServers = options.Upstreams{
Configs: []options.Upstream{
{ {
ID: "/", ID: "/",
Path: "/", Path: "/",
@ -109,6 +111,7 @@ redirect_url="http://localhost:4180/oauth2/callback"
PassHostHeader: boolPtr(true), PassHostHeader: boolPtr(true),
ProxyWebSockets: boolPtr(true), ProxyWebSockets: boolPtr(true),
}, },
},
} }
authHeader := options.Header{ authHeader := options.Header{
@ -130,7 +133,7 @@ redirect_url="http://localhost:4180/oauth2/callback"
opts.InjectResponseHeaders = append(opts.InjectResponseHeaders, authHeader) opts.InjectResponseHeaders = append(opts.InjectResponseHeaders, authHeader)
opts.Providers = options.Providers{ opts.Providers = options.Providers{
{ options.Provider{
ID: "google=oauth2-proxy", ID: "google=oauth2-proxy",
Type: "google", Type: "google",
ClientSecret: "b2F1dGgyLXByb3h5LWNsaWVudC1zZWNyZXQK", ClientSecret: "b2F1dGgyLXByb3h5LWNsaWVudC1zZWNyZXQK",
@ -230,7 +233,7 @@ redirect_url="http://localhost:4180/oauth2/callback"
configContent: testCoreConfig, configContent: testCoreConfig,
alphaConfigContent: testAlphaConfig + ":", alphaConfigContent: testAlphaConfig + ":",
expectedOptions: func() *options.Options { return nil }, expectedOptions: func() *options.Options { return nil },
expectedErr: errors.New("failed to load alpha options: error unmarshalling config: error converting YAML to JSON: yaml: line 49: did not find expected key"), expectedErr: errors.New("failed to load alpha options: error unmarshalling config: error converting YAML to JSON: yaml: line 50: did not find expected key"),
}), }),
Entry("with alpha configuration and bad core configuration", loadConfigurationTableInput{ Entry("with alpha configuration and bad core configuration", loadConfigurationTableInput{
configContent: testCoreConfig + "unknown_field=\"something\"", configContent: testCoreConfig + "unknown_field=\"something\"",

@ -198,11 +198,13 @@ func TestBasicAuthPassword(t *testing.T) {
basicAuthPassword := "This is a secure password" basicAuthPassword := "This is a secure password"
opts := baseTestOptions() opts := baseTestOptions()
opts.UpstreamServers = options.Upstreams{ opts.UpstreamServers = options.Upstreams{
Configs: []options.Upstream{
{ {
ID: providerServer.URL, ID: providerServer.URL,
Path: "/", Path: "/",
URI: providerServer.URL, URI: providerServer.URL,
}, },
},
} }
opts.Cookie.Secure = false opts.Cookie.Secure = false
@ -347,14 +349,16 @@ func NewPassAccessTokenTest(opts PassAccessTokenTestOptions) (*PassAccessTokenTe
patt.opts = baseTestOptions() patt.opts = baseTestOptions()
patt.opts.UpstreamServers = options.Upstreams{ patt.opts.UpstreamServers = options.Upstreams{
Configs: []options.Upstream{
{ {
ID: patt.providerServer.URL, ID: patt.providerServer.URL,
Path: "/", Path: "/",
URI: patt.providerServer.URL, URI: patt.providerServer.URL,
}, },
},
} }
if opts.ProxyUpstream.ID != "" { if opts.ProxyUpstream.ID != "" {
patt.opts.UpstreamServers = append(patt.opts.UpstreamServers, opts.ProxyUpstream) patt.opts.UpstreamServers.Configs = append(patt.opts.UpstreamServers.Configs, opts.ProxyUpstream)
} }
patt.opts.Cookie.Secure = false patt.opts.Cookie.Secure = false
@ -1270,11 +1274,13 @@ func TestAuthSkippedForPreflightRequests(t *testing.T) {
opts := baseTestOptions() opts := baseTestOptions()
opts.UpstreamServers = options.Upstreams{ opts.UpstreamServers = options.Upstreams{
Configs: []options.Upstream{
{ {
ID: upstreamServer.URL, ID: upstreamServer.URL,
Path: "/", Path: "/",
URI: upstreamServer.URL, URI: upstreamServer.URL,
}, },
},
} }
opts.SkipAuthPreflight = true opts.SkipAuthPreflight = true
err := validation.Validate(opts) err := validation.Validate(opts)
@ -1345,11 +1351,13 @@ func NewSignatureTest() (*SignatureTest, error) {
return nil, err return nil, err
} }
opts.UpstreamServers = options.Upstreams{ opts.UpstreamServers = options.Upstreams{
Configs: []options.Upstream{
{ {
ID: upstreamServer.URL, ID: upstreamServer.URL,
Path: "/", Path: "/",
URI: upstreamServer.URL, URI: upstreamServer.URL,
}, },
},
} }
providerHandler := func(w http.ResponseWriter, r *http.Request) { providerHandler := func(w http.ResponseWriter, r *http.Request) {
@ -1781,11 +1789,13 @@ func Test_noCacheHeaders(t *testing.T) {
opts := baseTestOptions() opts := baseTestOptions()
opts.UpstreamServers = options.Upstreams{ opts.UpstreamServers = options.Upstreams{
Configs: []options.Upstream{
{ {
ID: upstreamServer.URL, ID: upstreamServer.URL,
Path: "/", Path: "/",
URI: upstreamServer.URL, URI: upstreamServer.URL,
}, },
},
} }
opts.SkipAuthRegex = []string{".*"} opts.SkipAuthRegex = []string{".*"}
err := validation.Validate(opts) err := validation.Validate(opts)
@ -2051,11 +2061,13 @@ func TestTrustedIPs(t *testing.T) {
t.Run(tt.name, func(t *testing.T) { t.Run(tt.name, func(t *testing.T) {
opts := baseTestOptions() opts := baseTestOptions()
opts.UpstreamServers = options.Upstreams{ opts.UpstreamServers = options.Upstreams{
Configs: []options.Upstream{
{ {
ID: "static", ID: "static",
Path: "/", Path: "/",
Static: true, Static: true,
}, },
},
} }
opts.TrustedIPs = tt.trustedIPs opts.TrustedIPs = tt.trustedIPs
opts.ReverseProxy = tt.reverseProxy opts.ReverseProxy = tt.reverseProxy
@ -2244,11 +2256,13 @@ func TestAllowedRequest(t *testing.T) {
opts := baseTestOptions() opts := baseTestOptions()
opts.UpstreamServers = options.Upstreams{ opts.UpstreamServers = options.Upstreams{
Configs: []options.Upstream{
{ {
ID: upstreamServer.URL, ID: upstreamServer.URL,
Path: "/", Path: "/",
URI: upstreamServer.URL, URI: upstreamServer.URL,
}, },
},
} }
opts.SkipAuthRegex = []string{ opts.SkipAuthRegex = []string{
"^/skip/auth/regex$", "^/skip/auth/regex$",
@ -2359,11 +2373,13 @@ func TestProxyAllowedGroups(t *testing.T) {
test, err := NewProcessCookieTestWithOptionsModifiers(func(opts *options.Options) { test, err := NewProcessCookieTestWithOptionsModifiers(func(opts *options.Options) {
opts.Providers[0].AllowedGroups = tt.allowedGroups opts.Providers[0].AllowedGroups = tt.allowedGroups
opts.UpstreamServers = options.Upstreams{ opts.UpstreamServers = options.Upstreams{
Configs: []options.Upstream{
{ {
ID: upstreamServer.URL, ID: upstreamServer.URL,
Path: "/", Path: "/",
URI: upstreamServer.URL, URI: upstreamServer.URL,
}, },
},
} }
}) })
if err != nil { if err != nil {

@ -120,7 +120,7 @@ func (l *LegacyUpstreams) convert() (Upstreams, error) {
for _, upstreamString := range l.Upstreams { for _, upstreamString := range l.Upstreams {
u, err := url.Parse(upstreamString) u, err := url.Parse(upstreamString)
if err != nil { if err != nil {
return nil, fmt.Errorf("could not parse upstream %q: %v", upstreamString, err) return Upstreams{}, fmt.Errorf("could not parse upstream %q: %v", upstreamString, err)
} }
if u.Path == "" { if u.Path == "" {
@ -169,7 +169,7 @@ func (l *LegacyUpstreams) convert() (Upstreams, error) {
upstream.FlushInterval = nil upstream.FlushInterval = nil
} }
upstreams = append(upstreams, upstream) upstreams.Configs = append(upstreams.Configs, upstream)
} }
return upstreams, nil return upstreams, nil

@ -27,6 +27,7 @@ var _ = Describe("Legacy Options", func() {
truth := true truth := true
staticCode := 204 staticCode := 204
opts.UpstreamServers = Upstreams{ opts.UpstreamServers = Upstreams{
Configs: []Upstream{
{ {
ID: "/baz", ID: "/baz",
Path: "/baz", Path: "/baz",
@ -56,6 +57,7 @@ var _ = Describe("Legacy Options", func() {
PassHostHeader: nil, PassHostHeader: nil,
ProxyWebSockets: nil, ProxyWebSockets: nil,
}, },
},
} }
opts.InjectRequestHeaders = []Header{ opts.InjectRequestHeaders = []Header{
@ -124,7 +126,7 @@ var _ = Describe("Legacy Options", func() {
Context("Legacy Upstreams", func() { Context("Legacy Upstreams", func() {
type convertUpstreamsTableInput struct { type convertUpstreamsTableInput struct {
upstreamStrings []string upstreamStrings []string
expectedUpstreams Upstreams expectedUpstreams []Upstream
errMsg string errMsg string
} }
@ -219,51 +221,51 @@ var _ = Describe("Legacy Options", func() {
Expect(err).ToNot(HaveOccurred()) Expect(err).ToNot(HaveOccurred())
} }
Expect(upstreams).To(ConsistOf(in.expectedUpstreams)) Expect(upstreams.Configs).To(ConsistOf(in.expectedUpstreams))
}, },
Entry("with no upstreams", &convertUpstreamsTableInput{ Entry("with no upstreams", &convertUpstreamsTableInput{
upstreamStrings: []string{}, upstreamStrings: []string{},
expectedUpstreams: Upstreams{}, expectedUpstreams: []Upstream{},
errMsg: "", errMsg: "",
}), }),
Entry("with a valid HTTP upstream", &convertUpstreamsTableInput{ Entry("with a valid HTTP upstream", &convertUpstreamsTableInput{
upstreamStrings: []string{validHTTP}, upstreamStrings: []string{validHTTP},
expectedUpstreams: Upstreams{validHTTPUpstream}, expectedUpstreams: []Upstream{validHTTPUpstream},
errMsg: "", errMsg: "",
}), }),
Entry("with a HTTP upstream with an empty path", &convertUpstreamsTableInput{ Entry("with a HTTP upstream with an empty path", &convertUpstreamsTableInput{
upstreamStrings: []string{emptyPathHTTP}, upstreamStrings: []string{emptyPathHTTP},
expectedUpstreams: Upstreams{emptyPathHTTPUpstream}, expectedUpstreams: []Upstream{emptyPathHTTPUpstream},
errMsg: "", errMsg: "",
}), }),
Entry("with a valid File upstream with a fragment", &convertUpstreamsTableInput{ Entry("with a valid File upstream with a fragment", &convertUpstreamsTableInput{
upstreamStrings: []string{validFileWithFragment}, upstreamStrings: []string{validFileWithFragment},
expectedUpstreams: Upstreams{validFileWithFragmentUpstream}, expectedUpstreams: []Upstream{validFileWithFragmentUpstream},
errMsg: "", errMsg: "",
}), }),
Entry("with a valid static upstream", &convertUpstreamsTableInput{ Entry("with a valid static upstream", &convertUpstreamsTableInput{
upstreamStrings: []string{validStatic}, upstreamStrings: []string{validStatic},
expectedUpstreams: Upstreams{validStaticUpstream}, expectedUpstreams: []Upstream{validStaticUpstream},
errMsg: "", errMsg: "",
}), }),
Entry("with an invalid static upstream, code is 200", &convertUpstreamsTableInput{ Entry("with an invalid static upstream, code is 200", &convertUpstreamsTableInput{
upstreamStrings: []string{invalidStatic}, upstreamStrings: []string{invalidStatic},
expectedUpstreams: Upstreams{invalidStaticUpstream}, expectedUpstreams: []Upstream{invalidStaticUpstream},
errMsg: "", errMsg: "",
}), }),
Entry("with an invalid HTTP upstream", &convertUpstreamsTableInput{ Entry("with an invalid HTTP upstream", &convertUpstreamsTableInput{
upstreamStrings: []string{invalidHTTP}, upstreamStrings: []string{invalidHTTP},
expectedUpstreams: Upstreams{}, expectedUpstreams: []Upstream{},
errMsg: invalidHTTPErrMsg, errMsg: invalidHTTPErrMsg,
}), }),
Entry("with an invalid HTTP upstream and other upstreams", &convertUpstreamsTableInput{ Entry("with an invalid HTTP upstream and other upstreams", &convertUpstreamsTableInput{
upstreamStrings: []string{validHTTP, invalidHTTP}, upstreamStrings: []string{validHTTP, invalidHTTP},
expectedUpstreams: Upstreams{}, expectedUpstreams: []Upstream{},
errMsg: invalidHTTPErrMsg, errMsg: invalidHTTPErrMsg,
}), }),
Entry("with multiple valid upstreams", &convertUpstreamsTableInput{ Entry("with multiple valid upstreams", &convertUpstreamsTableInput{
upstreamStrings: []string{validHTTP, validFileWithFragment, validStatic}, upstreamStrings: []string{validHTTP, validFileWithFragment, validStatic},
expectedUpstreams: Upstreams{validHTTPUpstream, validFileWithFragmentUpstream, validStaticUpstream}, expectedUpstreams: []Upstream{validHTTPUpstream, validFileWithFragmentUpstream, validStaticUpstream},
errMsg: "", errMsg: "",
}), }),
) )

@ -470,6 +470,7 @@ sub:
It("should load a full example AlphaOptions", func() { It("should load a full example AlphaOptions", func() {
config := []byte(` config := []byte(`
upstreams: upstreams:
configs:
- id: httpbin - id: httpbin
path: / path: /
uri: http://httpbin uri: http://httpbin
@ -502,7 +503,8 @@ injectResponseHeaders:
flushInterval := Duration(500 * time.Millisecond) flushInterval := Duration(500 * time.Millisecond)
Expect(into).To(Equal(&AlphaOptions{ Expect(into).To(Equal(&AlphaOptions{
Upstreams: []Upstream{ Upstreams: Upstreams{
Configs: []Upstream{
{ {
ID: "httpbin", ID: "httpbin",
Path: "/", Path: "/",
@ -510,6 +512,7 @@ injectResponseHeaders:
FlushInterval: &flushInterval, FlushInterval: &flushInterval,
}, },
}, },
},
InjectRequestHeaders: []Header{ InjectRequestHeaders: []Header{
{ {
Name: "X-Forwarded-User", Name: "X-Forwarded-User",

@ -8,7 +8,11 @@ const (
) )
// Upstreams is a collection of definitions for upstream servers. // Upstreams is a collection of definitions for upstream servers.
type Upstreams []Upstream type Upstreams struct {
// Upstream represents the configuration for an upstream server.
// Requests will be proxied to this upstream if the path matches the request path.
Configs []Upstream `json:"configs,omitempty"`
}
// Upstream represents the configuration for an upstream server. // Upstream represents the configuration for an upstream server.
// Requests will be proxied to this upstream if the path matches the request path. // Requests will be proxied to this upstream if the path matches the request path.

@ -27,7 +27,7 @@ func NewProxy(upstreams options.Upstreams, sigData *options.SignatureData, write
serveMux: mux.NewRouter(), serveMux: mux.NewRouter(),
} }
for _, upstream := range sortByPathLongest(upstreams) { for _, upstream := range sortByPathLongest(upstreams.Configs) {
if upstream.Static { if upstream.Static {
if err := m.registerStaticResponseHandler(upstream, writer); err != nil { if err := m.registerStaticResponseHandler(upstream, writer); err != nil {
return nil, fmt.Errorf("could not register static upstream %q: %v", upstream.ID, err) return nil, fmt.Errorf("could not register static upstream %q: %v", upstream.ID, err)
@ -153,7 +153,7 @@ func registerTrailingSlashHandler(serveMux *mux.Router) {
// precedence (note this is the input to the rewrite logic). // precedence (note this is the input to the rewrite logic).
// This does not account for when a rewrite would actually make the path shorter. // This does not account for when a rewrite would actually make the path shorter.
// This should maintain the sorting behaviour of the standard go serve mux. // This should maintain the sorting behaviour of the standard go serve mux.
func sortByPathLongest(in options.Upstreams) options.Upstreams { func sortByPathLongest(in []options.Upstream) []options.Upstream {
sort.Slice(in, func(i, j int) bool { sort.Slice(in, func(i, j int) bool {
iRW := in[i].RewriteTarget iRW := in[i].RewriteTarget
jRW := in[j].RewriteTarget jRW := in[j].RewriteTarget

@ -33,6 +33,7 @@ var _ = Describe("Proxy Suite", func() {
accepted := http.StatusAccepted accepted := http.StatusAccepted
upstreams := options.Upstreams{ upstreams := options.Upstreams{
Configs: []options.Upstream{
{ {
ID: "http-backend", ID: "http-backend",
Path: "/http/", Path: "/http/",
@ -89,6 +90,7 @@ var _ = Describe("Proxy Suite", func() {
RewriteTarget: "/double-match/rewrite/$1", RewriteTarget: "/double-match/rewrite/$1",
URI: serverAddr, URI: serverAddr,
}, },
},
} }
var err error var err error
@ -315,8 +317,8 @@ var _ = Describe("Proxy Suite", func() {
Context("sortByPathLongest", func() { Context("sortByPathLongest", func() {
type sortByPathLongestTableInput struct { type sortByPathLongestTableInput struct {
input options.Upstreams input []options.Upstream
expectedOutput options.Upstreams expectedOutput []options.Upstream
} }
var httpPath = options.Upstream{ var httpPath = options.Upstream{
@ -346,40 +348,40 @@ var _ = Describe("Proxy Suite", func() {
Expect(sortByPathLongest(in.input)).To(Equal(in.expectedOutput)) Expect(sortByPathLongest(in.input)).To(Equal(in.expectedOutput))
}, },
Entry("with a mix of paths registered", sortByPathLongestTableInput{ Entry("with a mix of paths registered", sortByPathLongestTableInput{
input: options.Upstreams{httpPath, httpSubPath, shortSubPathWithRewrite, longerPath, shortPathWithRewrite}, input: []options.Upstream{httpPath, httpSubPath, shortSubPathWithRewrite, longerPath, shortPathWithRewrite},
expectedOutput: options.Upstreams{shortSubPathWithRewrite, shortPathWithRewrite, longerPath, httpSubPath, httpPath}, expectedOutput: []options.Upstream{shortSubPathWithRewrite, shortPathWithRewrite, longerPath, httpSubPath, httpPath},
}), }),
Entry("when a subpath is registered (in order)", sortByPathLongestTableInput{ Entry("when a subpath is registered (in order)", sortByPathLongestTableInput{
input: options.Upstreams{httpSubPath, httpPath}, input: []options.Upstream{httpSubPath, httpPath},
expectedOutput: options.Upstreams{httpSubPath, httpPath}, expectedOutput: []options.Upstream{httpSubPath, httpPath},
}), }),
Entry("when a subpath is registered (out of order)", sortByPathLongestTableInput{ Entry("when a subpath is registered (out of order)", sortByPathLongestTableInput{
input: options.Upstreams{httpPath, httpSubPath}, input: []options.Upstream{httpPath, httpSubPath},
expectedOutput: options.Upstreams{httpSubPath, httpPath}, expectedOutput: []options.Upstream{httpSubPath, httpPath},
}), }),
Entry("when longer paths are registered (in order)", sortByPathLongestTableInput{ Entry("when longer paths are registered (in order)", sortByPathLongestTableInput{
input: options.Upstreams{longerPath, httpPath}, input: []options.Upstream{longerPath, httpPath},
expectedOutput: options.Upstreams{longerPath, httpPath}, expectedOutput: []options.Upstream{longerPath, httpPath},
}), }),
Entry("when longer paths are registered (out of order)", sortByPathLongestTableInput{ Entry("when longer paths are registered (out of order)", sortByPathLongestTableInput{
input: options.Upstreams{httpPath, longerPath}, input: []options.Upstream{httpPath, longerPath},
expectedOutput: options.Upstreams{longerPath, httpPath}, expectedOutput: []options.Upstream{longerPath, httpPath},
}), }),
Entry("when a rewrite target is registered (in order)", sortByPathLongestTableInput{ Entry("when a rewrite target is registered (in order)", sortByPathLongestTableInput{
input: options.Upstreams{shortPathWithRewrite, longerPath}, input: []options.Upstream{shortPathWithRewrite, longerPath},
expectedOutput: options.Upstreams{shortPathWithRewrite, longerPath}, expectedOutput: []options.Upstream{shortPathWithRewrite, longerPath},
}), }),
Entry("when a rewrite target is registered (out of order)", sortByPathLongestTableInput{ Entry("when a rewrite target is registered (out of order)", sortByPathLongestTableInput{
input: options.Upstreams{longerPath, shortPathWithRewrite}, input: []options.Upstream{longerPath, shortPathWithRewrite},
expectedOutput: options.Upstreams{shortPathWithRewrite, longerPath}, expectedOutput: []options.Upstream{shortPathWithRewrite, longerPath},
}), }),
Entry("with multiple rewrite targets registered (in order)", sortByPathLongestTableInput{ Entry("with multiple rewrite targets registered (in order)", sortByPathLongestTableInput{
input: options.Upstreams{shortSubPathWithRewrite, shortPathWithRewrite}, input: []options.Upstream{shortSubPathWithRewrite, shortPathWithRewrite},
expectedOutput: options.Upstreams{shortSubPathWithRewrite, shortPathWithRewrite}, expectedOutput: []options.Upstream{shortSubPathWithRewrite, shortPathWithRewrite},
}), }),
Entry("with multiple rewrite targets registered (out of order)", sortByPathLongestTableInput{ Entry("with multiple rewrite targets registered (out of order)", sortByPathLongestTableInput{
input: options.Upstreams{shortPathWithRewrite, shortSubPathWithRewrite}, input: []options.Upstream{shortPathWithRewrite, shortSubPathWithRewrite},
expectedOutput: options.Upstreams{shortSubPathWithRewrite, shortPathWithRewrite}, expectedOutput: []options.Upstream{shortSubPathWithRewrite, shortPathWithRewrite},
}), }),
) )
}) })

@ -22,7 +22,7 @@ const (
func testOptions() *options.Options { func testOptions() *options.Options {
o := options.NewOptions() o := options.NewOptions()
o.UpstreamServers = append(o.UpstreamServers, options.Upstream{ o.UpstreamServers.Configs = append(o.UpstreamServers.Configs, options.Upstream{
ID: "upstream", ID: "upstream",
Path: "/", Path: "/",
URI: "http://127.0.0.1:8080/", URI: "http://127.0.0.1:8080/",

@ -12,7 +12,7 @@ func validateUpstreams(upstreams options.Upstreams) []string {
ids := make(map[string]struct{}) ids := make(map[string]struct{})
paths := make(map[string]struct{}) paths := make(map[string]struct{})
for _, upstream := range upstreams { for _, upstream := range upstreams.Configs {
msgs = append(msgs, validateUpstream(upstream, ids, paths)...) msgs = append(msgs, validateUpstream(upstream, ids, paths)...)
} }

@ -59,74 +59,89 @@ var _ = Describe("Upstreams", func() {
}), }),
Entry("with valid upstreams", &validateUpstreamTableInput{ Entry("with valid upstreams", &validateUpstreamTableInput{
upstreams: options.Upstreams{ upstreams: options.Upstreams{
Configs: []options.Upstream{
validHTTPUpstream, validHTTPUpstream,
validStaticUpstream, validStaticUpstream,
validFileUpstream, validFileUpstream,
}, },
},
errStrings: []string{}, errStrings: []string{},
}), }),
Entry("with an empty ID", &validateUpstreamTableInput{ Entry("with an empty ID", &validateUpstreamTableInput{
upstreams: options.Upstreams{ upstreams: options.Upstreams{
Configs: []options.Upstream{
{ {
ID: "", ID: "",
Path: "/foo", Path: "/foo",
URI: "http://localhost:8080", URI: "http://localhost:8080",
}, },
}, },
},
errStrings: []string{emptyIDMsg}, errStrings: []string{emptyIDMsg},
}), }),
Entry("with an empty Path", &validateUpstreamTableInput{ Entry("with an empty Path", &validateUpstreamTableInput{
upstreams: options.Upstreams{ upstreams: options.Upstreams{
Configs: []options.Upstream{
{ {
ID: "foo", ID: "foo",
Path: "", Path: "",
URI: "http://localhost:8080", URI: "http://localhost:8080",
}, },
}, },
},
errStrings: []string{emptyPathMsg}, errStrings: []string{emptyPathMsg},
}), }),
Entry("with an empty Path", &validateUpstreamTableInput{ Entry("with an empty Path", &validateUpstreamTableInput{
upstreams: options.Upstreams{ upstreams: options.Upstreams{
Configs: []options.Upstream{
{ {
ID: "foo", ID: "foo",
Path: "", Path: "",
URI: "http://localhost:8080", URI: "http://localhost:8080",
}, },
}, },
},
errStrings: []string{emptyPathMsg}, errStrings: []string{emptyPathMsg},
}), }),
Entry("with an empty URI", &validateUpstreamTableInput{ Entry("with an empty URI", &validateUpstreamTableInput{
upstreams: options.Upstreams{ upstreams: options.Upstreams{
Configs: []options.Upstream{
{ {
ID: "foo", ID: "foo",
Path: "/foo", Path: "/foo",
URI: "", URI: "",
}, },
}, },
},
errStrings: []string{emptyURIMsg}, errStrings: []string{emptyURIMsg},
}), }),
Entry("with an invalid URI", &validateUpstreamTableInput{ Entry("with an invalid URI", &validateUpstreamTableInput{
upstreams: options.Upstreams{ upstreams: options.Upstreams{
Configs: []options.Upstream{
{ {
ID: "foo", ID: "foo",
Path: "/foo", Path: "/foo",
URI: ":", URI: ":",
}, },
}, },
},
errStrings: []string{invalidURIMsg}, errStrings: []string{invalidURIMsg},
}), }),
Entry("with an invalid URI scheme", &validateUpstreamTableInput{ Entry("with an invalid URI scheme", &validateUpstreamTableInput{
upstreams: options.Upstreams{ upstreams: options.Upstreams{
Configs: []options.Upstream{
{ {
ID: "foo", ID: "foo",
Path: "/foo", Path: "/foo",
URI: "ftp://foo", URI: "ftp://foo",
}, },
}, },
},
errStrings: []string{invalidURISchemeMsg}, errStrings: []string{invalidURISchemeMsg},
}), }),
Entry("with a static upstream and invalid optons", &validateUpstreamTableInput{ Entry("with a static upstream and invalid optons", &validateUpstreamTableInput{
upstreams: options.Upstreams{ upstreams: options.Upstreams{
Configs: []options.Upstream{
{ {
ID: "foo", ID: "foo",
Path: "/foo", Path: "/foo",
@ -138,6 +153,7 @@ var _ = Describe("Upstreams", func() {
InsecureSkipTLSVerify: true, InsecureSkipTLSVerify: true,
}, },
}, },
},
errStrings: []string{ errStrings: []string{
staticWithURIMsg, staticWithURIMsg,
staticWithInsecureMsg, staticWithInsecureMsg,
@ -148,6 +164,7 @@ var _ = Describe("Upstreams", func() {
}), }),
Entry("with duplicate IDs", &validateUpstreamTableInput{ Entry("with duplicate IDs", &validateUpstreamTableInput{
upstreams: options.Upstreams{ upstreams: options.Upstreams{
Configs: []options.Upstream{
{ {
ID: "foo", ID: "foo",
Path: "/foo1", Path: "/foo1",
@ -159,10 +176,12 @@ var _ = Describe("Upstreams", func() {
URI: "http://foo", URI: "http://foo",
}, },
}, },
},
errStrings: []string{multipleIDsMsg}, errStrings: []string{multipleIDsMsg},
}), }),
Entry("with duplicate Paths", &validateUpstreamTableInput{ Entry("with duplicate Paths", &validateUpstreamTableInput{
upstreams: options.Upstreams{ upstreams: options.Upstreams{
Configs: []options.Upstream{
{ {
ID: "foo1", ID: "foo1",
Path: "/foo", Path: "/foo",
@ -174,16 +193,19 @@ var _ = Describe("Upstreams", func() {
URI: "http://foo", URI: "http://foo",
}, },
}, },
},
errStrings: []string{multiplePathsMsg}, errStrings: []string{multiplePathsMsg},
}), }),
Entry("when a static code is supplied without static", &validateUpstreamTableInput{ Entry("when a static code is supplied without static", &validateUpstreamTableInput{
upstreams: options.Upstreams{ upstreams: options.Upstreams{
Configs: []options.Upstream{
{ {
ID: "foo", ID: "foo",
Path: "/foo", Path: "/foo",
StaticCode: &staticCode200, StaticCode: &staticCode200,
}, },
}, },
},
errStrings: []string{emptyURIMsg, staticCodeMsg}, errStrings: []string{emptyURIMsg, staticCodeMsg},
}), }),
) )