Skip to content
This repository was archived by the owner on Jan 24, 2019. It is now read-only.

Commit e955d2b

Browse files
virusdavetalam
authored andcommitted
options: update options parsing for better handling of incorrect values
* don't add in failed compiled regexes for skip auth regex option * improve test coverage for skip auth regex option to handle partial success case * add tests for incorrect upstream options parsing errors
1 parent a7c5d9c commit e955d2b

File tree

2 files changed

+23
-2
lines changed

2 files changed

+23
-2
lines changed

options.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -180,8 +180,8 @@ func (o *Options) Validate() error {
180180
for _, u := range o.SkipAuthRegex {
181181
CompiledRegex, err := regexp.Compile(u)
182182
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
185185
}
186186
o.CompiledRegex = append(o.CompiledRegex, CompiledRegex)
187187
}

options_test.go

+21
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,18 @@ func TestProxyURLs(t *testing.T) {
9595
assert.Equal(t, expected, o.proxyURLs)
9696
}
9797

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+
98110
func TestCompiledRegex(t *testing.T) {
99111
o := testOptions()
100112
regexps := []string{"/foo/.*", "/ba[rz]/quux"}
@@ -119,6 +131,15 @@ func TestCompiledRegexError(t *testing.T) {
119131
"error compiling regex=\"barquux)\" error parsing regexp: " +
120132
"unexpected ): `barquux)`"})
121133
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())
122143
}
123144

124145
func TestDefaultProviderApiSettings(t *testing.T) {

0 commit comments

Comments
 (0)