From e955d2be0e14fbd9bc1bfcee8388712ec60d7ab6 Mon Sep 17 00:00:00 2001 From: Dave Nicponski Date: Fri, 5 May 2017 15:47:40 -0400 Subject: [PATCH] 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 --- options.go | 4 ++-- options_test.go | 21 +++++++++++++++++++++ 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/options.go b/options.go index 0633725..214c815 100644 --- a/options.go +++ b/options.go @@ -180,8 +180,8 @@ func (o *Options) Validate() error { for _, u := range o.SkipAuthRegex { CompiledRegex, err := regexp.Compile(u) if err != nil { - msgs = append(msgs, fmt.Sprintf( - "error compiling regex=%q %s", u, err)) + msgs = append(msgs, fmt.Sprintf("error compiling regex=%q %s", u, err)) + continue } o.CompiledRegex = append(o.CompiledRegex, CompiledRegex) } diff --git a/options_test.go b/options_test.go index e1fed8a..23ae9fb 100644 --- a/options_test.go +++ b/options_test.go @@ -95,6 +95,18 @@ func TestProxyURLs(t *testing.T) { assert.Equal(t, expected, o.proxyURLs) } +func TestProxyURLsError(t *testing.T) { + o := testOptions() + o.Upstreams = append(o.Upstreams, "127.0.0.1:8081") + err := o.Validate() + assert.NotEqual(t, nil, err) + + expected := errorMsg([]string{ + "error parsing upstream: parse 127.0.0.1:8081: " + + "first path segment in URL cannot contain colon"}) + assert.Equal(t, expected, err.Error()) +} + func TestCompiledRegex(t *testing.T) { o := testOptions() regexps := []string{"/foo/.*", "/ba[rz]/quux"} @@ -119,6 +131,15 @@ func TestCompiledRegexError(t *testing.T) { "error compiling regex=\"barquux)\" error parsing regexp: " + "unexpected ): `barquux)`"}) assert.Equal(t, expected, err.Error()) + + o.SkipAuthRegex = []string{"foobaz", "barquux)"} + err = o.Validate() + assert.NotEqual(t, nil, err) + + expected = errorMsg([]string{ + "error compiling regex=\"barquux)\" error parsing regexp: " + + "unexpected ): `barquux)`"}) + assert.Equal(t, expected, err.Error()) } func TestDefaultProviderApiSettings(t *testing.T) {