@@ -2242,21 +2242,24 @@ func TestTrustedIPs(t *testing.T) {
22422242}
22432243
22442244func Test_buildRoutesAllowlist(t *testing.T) {
2245+ type expectedAllowedRoute struct {
2246+ method string
2247+ regexString string
2248+ }
2249+
22452250 testCases := []struct {
2246− name string
2247− skipAuthRegex []string
2248− skipAuthRoutes []string
2249− expectedMethods []string
2250− expectedRegexes []string
2251− shouldError bool
2251+ name string
2252+ skipAuthRegex []string
2253+ skipAuthRoutes []string
2254+ expectedRoutes []expectedAllowedRoute
2255+ shouldError bool
22522256 }{
22532257 {
2254− name: "No skip auth configured",
2255− skipAuthRegex: []string{},
2256− skipAuthRoutes: []string{},
2257− expectedMethods: []string{},
2258− expectedRegexes: []string{},
2259− shouldError: false,
2258+ name: "No skip auth configured",
2259+ skipAuthRegex: []string{},
2260+ skipAuthRoutes: []string{},
2261+ expectedRoutes: []expectedAllowedRoute{},
2262+ shouldError: false,
22602263 },
22612264 {
22622265 name: "Only skipAuthRegex configured",
@@ -2265,13 +2268,15 @@ func Test_buildRoutesAllowlist(t *testing.T) {
22652268 "^/baz/[0-9]+/thing",
22662269 },
22672270 skipAuthRoutes: []string{},
2268− expectedMethods: []string{
2269− "",
2270− "",
2271− },
2272− expectedRegexes: []string{
2273− "^/foo/bar",
2274− "^/baz/[0-9]+/thing",
2271+ expectedRoutes: []expectedAllowedRoute{
2272+ {
2273+ method: "",
2274+ regexString: "^/foo/bar",
2275+ },
2276+ {
2277+ method: "",
2278+ regexString: "^/baz/[0-9]+/thing",
2279+ },
22752280 },
22762281 shouldError: false,
22772282 },
@@ -2285,19 +2290,27 @@ func Test_buildRoutesAllowlist(t *testing.T) {
22852290 "WEIRD=^/methods/are/allowed",
22862291 "PATCH=/second/equals?are=handled&just=fine",
22872292 },
2288− expectedMethods: []string{
2289− "GET",
2290− "POST",
2291− "",
2292− "WEIRD",
2293− "PATCH",
2294− },
2295− expectedRegexes: []string{
2296− "^/foo/bar",
2297− "^/baz/[0-9]+/thing",
2298− "^/all/methods$",
2299− "^/methods/are/allowed",
2300− "/second/equals?are=handled&just=fine",
2293+ expectedRoutes: []expectedAllowedRoute{
2294+ {
2295+ method: "GET",
2296+ regexString: "^/foo/bar",
2297+ },
2298+ {
2299+ method: "POST",
2300+ regexString: "^/baz/[0-9]+/thing",
2301+ },
2302+ {
2303+ method: "",
2304+ regexString: "^/all/methods$",
2305+ },
2306+ {
2307+ method: "WEIRD",
2308+ regexString: "^/methods/are/allowed",
2309+ },
2310+ {
2311+ method: "PATCH",
2312+ regexString: "/second/equals?are=handled&just=fine",
2313+ },
23012314 },
23022315 shouldError: false,
23032316 },
@@ -2312,19 +2325,27 @@ func Test_buildRoutesAllowlist(t *testing.T) {
23122325 "POST=^/baz/[0-9]+/thing",
23132326 "^/all/methods$",
23142327 },
2315− expectedMethods: []string{
2316− "",
2317− "",
2318− "GET",
2319− "POST",
2320− "",
2321− },
2322− expectedRegexes: []string{
2323− "^/foo/bar/regex",
2324− "^/baz/[0-9]+/thing/regex",
2325− "^/foo/bar",
2326− "^/baz/[0-9]+/thing",
2327− "^/all/methods$",
2328+ expectedRoutes: []expectedAllowedRoute{
2329+ {
2330+ method: "",
2331+ regexString: "^/foo/bar/regex",
2332+ },
2333+ {
2334+ method: "",
2335+ regexString: "^/baz/[0-9]+/thing/regex",
2336+ },
2337+ {
2338+ method: "GET",
2339+ regexString: "^/foo/bar",
2340+ },
2341+ {
2342+ method: "POST",
2343+ regexString: "^/baz/[0-9]+/thing",
2344+ },
2345+ {
2346+ method: "",
2347+ regexString: "^/all/methods$",
2348+ },
23282349 },
23292350 shouldError: false,
23302351 },
@@ -2335,10 +2356,9 @@ func Test_buildRoutesAllowlist(t *testing.T) {
23352356 "^/baz/[0-9]+/thing",
23362357 "(bad[regex",
23372358 },
2338− skipAuthRoutes: []string{},
2339− expectedMethods: []string{},
2340− expectedRegexes: []string{},
2341− shouldError: true,
2359+ skipAuthRoutes: []string{},
2360+ expectedRoutes: []expectedAllowedRoute{},
2361+ shouldError: true,
23422362 },
23432363 {
23442364 name: "Invalid skipAuthRoutes entry",
@@ -2349,9 +2369,8 @@ func Test_buildRoutesAllowlist(t *testing.T) {
23492369 "^/all/methods$",
23502370 "PUT=(bad[regex",
23512371 },
2352− expectedMethods: []string{},
2353− expectedRegexes: []string{},
2354− shouldError: true,
2372+ expectedRoutes: []expectedAllowedRoute{},
2373+ shouldError: true,
23552374 },
23562375 }
23572376
@@ -2369,10 +2388,9 @@ func Test_buildRoutesAllowlist(t *testing.T) {
23692388 assert.NoError(t, err)
23702389
23712390 for i, route := range routes {
2372− assert.Greater(t, len(tc.expectedMethods), i)
2373− assert.Equal(t, route.method, tc.expectedMethods[i])
2374− assert.Greater(t, len(tc.expectedRegexes), i)
2375− assert.Equal(t, route.pathRegex.String(), tc.expectedRegexes[i])
2391+ assert.Greater(t, len(tc.expectedRoutes), i)
2392+ assert.Equal(t, route.method, tc.expectedRoutes[i].method)
2393+ assert.Equal(t, route.pathRegex.String(), tc.expectedRoutes[i].regexString)
23762394 }
23772395 })
23782396 }