diff --git a/middleware_test.go b/middleware_test.go index 2c1012f4ab74f0e07c12d7b03b17a1834882dabb..7ff44cd6eb1fa295a516465f401a9ba7a1d05c19 100644 --- a/middleware_test.go +++ b/middleware_test.go @@ -326,6 +326,57 @@ func TestOauthRequests(t *testing.T) { newFakeProxy(cfg).RunTests(t, requests) } +func TestStrangeRoutingError(t *testing.T) { + cfg := newFakeKeycloakConfig() + cfg.Resources = []*Resource{ + { + URL: "/api/v1/event/123456789", + Methods: allHTTPMethods, + Roles: []string{"user"}, + }, + { + URL: "/api/v1/event/404", + Methods: allHTTPMethods, + Roles: []string{"monitoring"}, + }, + { + URL: "/api/v1/audit/*", + Methods: allHTTPMethods, + Roles: []string{"auditor", "dev"}, + }, + { + URL: "/*", + Methods: allHTTPMethods, + Roles: []string{"dev"}, + }, + } + requests := []fakeRequest{ + { // should work + URI: "/api/v1/event/123456789", + HasToken: true, + Redirects: true, + Roles: []string{"user"}, + ExpectedProxy: true, + ExpectedCode: http.StatusOK, + }, + { // good + URI: "/api/v1/event/404", + HasToken: true, + Redirects: false, + Roles: []string{"monitoring"}, + ExpectedProxy: true, + ExpectedCode: http.StatusOK, + }, + { // this should fail here + URI: "/api/v1/event/1000", + Redirects: false, + ExpectedCode: http.StatusUnauthorized, + }, + } + + newFakeProxy(cfg).RunTests(t, requests) +} + func TestNoProxyingRequests(t *testing.T) { c := newFakeKeycloakConfig() c.Resources = []*Resource{