git.iko.soy/typeable/oauth2-proxy
on master help sign in
Merge pull request #502 from talam/update_options_parsing
6ddbb2cHeather Hendy
options.go+2−2
@@ -180,8 +180,8 @@ func (o *Options) Validate() error {
180 for _, u := range o.SkipAuthRegex {
180 for _, u := range o.SkipAuthRegex {
181 CompiledRegex, err := regexp.Compile(u)
181 CompiledRegex, err := regexp.Compile(u)
182 if err != nil {
182 if err != nil {
183− msgs = append(msgs, fmt.Sprintf(
184− "error compiling regex=%q %s", u, err))
183+ msgs = append(msgs, fmt.Sprintf("error compiling regex=%q %s", u, err))
184+ continue
185 }
185 }
186 o.CompiledRegex = append(o.CompiledRegex, CompiledRegex)
186 o.CompiledRegex = append(o.CompiledRegex, CompiledRegex)
187 }
187 }
options_test.go+21
@@ -95,6 +95,18 @@ func TestProxyURLs(t *testing.T) {
95 assert.Equal(t, expected, o.proxyURLs)
95 assert.Equal(t, expected, o.proxyURLs)
96}
96}
97
97
98+func TestProxyURLsError(t *testing.T) {
99+ o := testOptions()
100+ o.Upstreams = append(o.Upstreams, "127.0.0.1:8081")
101+ err := o.Validate()
102+ assert.NotEqual(t, nil, err)
103+
104+ expected := errorMsg([]string{
105+ "error parsing upstream: parse 127.0.0.1:8081: " +
106+ "first path segment in URL cannot contain colon"})
107+ assert.Equal(t, expected, err.Error())
108+}
109+
98func TestCompiledRegex(t *testing.T) {
110func TestCompiledRegex(t *testing.T) {
99 o := testOptions()
111 o := testOptions()
100 regexps := []string{"/foo/.*", "/ba[rz]/quux"}
112 regexps := []string{"/foo/.*", "/ba[rz]/quux"}
@@ -119,6 +131,15 @@ func TestCompiledRegexError(t *testing.T) {
119 "error compiling regex=\"barquux)\" error parsing regexp: " +
131 "error compiling regex=\"barquux)\" error parsing regexp: " +
120 "unexpected ): `barquux)`"})
132 "unexpected ): `barquux)`"})
121 assert.Equal(t, expected, err.Error())
133 assert.Equal(t, expected, err.Error())
134+
135+ o.SkipAuthRegex = []string{"foobaz", "barquux)"}
136+ err = o.Validate()
137+ assert.NotEqual(t, nil, err)
138+
139+ expected = errorMsg([]string{
140+ "error compiling regex=\"barquux)\" error parsing regexp: " +
141+ "unexpected ): `barquux)`"})
142+ assert.Equal(t, expected, err.Error())
122}
143}
123
144
124func TestDefaultProviderApiSettings(t *testing.T) {
145func TestDefaultProviderApiSettings(t *testing.T) {