6 "github.com/oauth2-proxy/oauth2-proxy/v7/pkg/apis/options"
7 "github.com/oauth2-proxy/oauth2-proxy/v7/pkg/util/ptr"
8 . "github.com/onsi/ginkgo/v2"
9 . "github.com/onsi/gomega"
12var _ = Describe("Upstreams", func() {
13 type validateUpstreamTableInput struct {
14 upstreams options.UpstreamConfig
18 flushInterval := 5 * time.Second
21 validHTTPUpstream := options.Upstream{
22 ID: "validHTTPUpstream",
23 Path: "/validHTTPUpstream",
24 URI: "http://localhost:8080",
26 validStaticUpstream := options.Upstream{
27 ID: "validStaticUpstream",
28 Path: "/validStaticUpstream",
31 validFileUpstream := options.Upstream{
32 ID: "validFileUpstream",
33 Path: "/validFileUpstream",
34 URI: "file://var/lib/foo",
37 emptyIDMsg := "upstream has empty id: ids are required for all upstreams"
38 emptyPathMsg := "upstream \"foo\" has empty path: paths are required for all upstreams"
39 emptyURIMsg := "upstream \"foo\" has empty uri: uris are required for all non-static upstreams"
40 invalidURIMsg := "upstream \"foo\" has invalid uri: parse \":\": missing protocol scheme"
41 invalidURISchemeMsg := "upstream \"foo\" has invalid scheme: \"ftp\""
42 staticWithURIMsg := "upstream \"foo\" has uri, but is a static upstream, this will have no effect."
43 staticWithInsecureMsg := "upstream \"foo\" has insecureSkipTLSVerify, but is a static upstream, this will have no effect."
44 staticWithFlushIntervalMsg := "upstream \"foo\" has flushInterval, but is a static upstream, this will have no effect."
45 staticWithPassHostHeaderMsg := "upstream \"foo\" has passHostHeader, but is a static upstream, this will have no effect."
46 staticWithProxyWebSocketsMsg := "upstream \"foo\" has proxyWebSockets, but is a static upstream, this will have no effect."
47 multipleIDsMsg := "multiple upstreams found with id \"foo\": upstream ids must be unique"
48 multiplePathsMsg := "multiple upstreams found with path \"/foo\": upstream paths must be unique"
49 staticCodeMsg := "upstream \"foo\" has staticCode (200), but is not a static upstream, set 'static' for a static response"
51 DescribeTable("validateUpstreams",
52 func(o *validateUpstreamTableInput) {
53 Expect(validateUpstreams(o.upstreams)).To(ConsistOf(o.errStrings))
55 Entry("with no upstreams", &validateUpstreamTableInput{
56 upstreams: options.UpstreamConfig{},
57 errStrings: []string{},
59 Entry("with valid upstreams", &validateUpstreamTableInput{
60 upstreams: options.UpstreamConfig{
61 Upstreams: []options.Upstream{
67 errStrings: []string{},
69 Entry("with an empty ID", &validateUpstreamTableInput{
70 upstreams: options.UpstreamConfig{
71 Upstreams: []options.Upstream{
75 URI: "http://localhost:8080",
79 errStrings: []string{emptyIDMsg},
81 Entry("with an empty Path", &validateUpstreamTableInput{
82 upstreams: options.UpstreamConfig{
83 Upstreams: []options.Upstream{
87 URI: "http://localhost:8080",
91 errStrings: []string{emptyPathMsg},
93 Entry("with an empty Path", &validateUpstreamTableInput{
94 upstreams: options.UpstreamConfig{
95 Upstreams: []options.Upstream{
99 URI: "http://localhost:8080",
103 errStrings: []string{emptyPathMsg},
105 Entry("with an empty URI", &validateUpstreamTableInput{
106 upstreams: options.UpstreamConfig{
107 Upstreams: []options.Upstream{
115 errStrings: []string{emptyURIMsg},
117 Entry("with an invalid URI", &validateUpstreamTableInput{
118 upstreams: options.UpstreamConfig{
119 Upstreams: []options.Upstream{
127 errStrings: []string{invalidURIMsg},
129 Entry("with an invalid URI scheme", &validateUpstreamTableInput{
130 upstreams: options.UpstreamConfig{
131 Upstreams: []options.Upstream{
139 errStrings: []string{invalidURISchemeMsg},
141 Entry("with a static upstream and invalid options", &validateUpstreamTableInput{
142 upstreams: options.UpstreamConfig{
143 Upstreams: []options.Upstream{
148 Static: ptr.To(true),
149 FlushInterval: &flushInterval,
150 PassHostHeader: ptr.To(true),
151 ProxyWebSockets: ptr.To(true),
152 InsecureSkipTLSVerify: ptr.To(true),
156 errStrings: []string{
158 staticWithInsecureMsg,
159 staticWithFlushIntervalMsg,
160 staticWithPassHostHeaderMsg,
161 staticWithProxyWebSocketsMsg,
164 Entry("with a static upstream and sane default options", &validateUpstreamTableInput{
165 upstreams: options.UpstreamConfig{
166 Upstreams: []options.Upstream{
171 Static: ptr.To(true),
172 PassHostHeader: ptr.To(false),
173 ProxyWebSockets: ptr.To(false),
174 InsecureSkipTLSVerify: ptr.To(false),
178 errStrings: []string{
182 Entry("with duplicate IDs", &validateUpstreamTableInput{
183 upstreams: options.UpstreamConfig{
184 Upstreams: []options.Upstream{
197 errStrings: []string{multipleIDsMsg},
199 Entry("with duplicate Paths", &validateUpstreamTableInput{
200 upstreams: options.UpstreamConfig{
201 Upstreams: []options.Upstream{
214 errStrings: []string{multiplePathsMsg},
216 Entry("when a static code is supplied without static", &validateUpstreamTableInput{
217 upstreams: options.UpstreamConfig{
218 Upstreams: []options.Upstream{
222 StaticCode: &staticCode200,
226 errStrings: []string{emptyURIMsg, staticCodeMsg},
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list