@@ -333,18 +333,19 @@ func TestMetricsMiddleware(t *testing.T) {
333333 cfg .EnableMetrics = true
334334 cfg .LocalhostMetrics = true
335335 requests := []fakeRequest {
336- {
337- URI : cfg .WithOAuthURI (metricsURL ),
338- ExpectedCode : http .StatusOK ,
339- ExpectedContentContains : "proxy_request_status_total" ,
340- },
341336 {
342337 URI : cfg .WithOAuthURI (metricsURL ),
343338 Headers : map [string ]string {
344339 "X-Forwarded-For" : "10.0.0.1" ,
345340 },
346341 ExpectedCode : http .StatusForbidden ,
347342 },
343+ // Some request must run before this one to generate request status numbers
344+ {
345+ URI : cfg .WithOAuthURI (metricsURL ),
346+ ExpectedCode : http .StatusOK ,
347+ ExpectedContentContains : "proxy_request_status_total" ,
348+ },
348349 }
349350 newFakeProxy (cfg ).RunTests (t , requests )
350351}
@@ -433,6 +434,100 @@ func TestMethodExclusions(t *testing.T) {
433434 newFakeProxy (cfg ).RunTests (t , requests )
434435}
435436
437+ func TestPreserveURLEncoding (t * testing.T ) {
438+ cfg := newFakeKeycloakConfig ()
439+ cfg .EnableLogging = true
440+ cfg .Resources = []* Resource {
441+ {
442+ URL : "/api/v2/*" ,
443+ Methods : allHTTPMethods ,
444+ Roles : []string {"dev" },
445+ },
446+ {
447+ URL : "/api/v1/auth*" ,
448+ Methods : allHTTPMethods ,
449+ Roles : []string {"admin" },
450+ },
451+ {
452+ URL : "/api/v1/*" ,
453+ Methods : allHTTPMethods ,
454+ WhiteListed : true ,
455+ },
456+ {
457+ URL : "/*" ,
458+ Methods : allHTTPMethods ,
459+ Roles : []string {"user" },
460+ },
461+ }
462+ requests := []fakeRequest {
463+ {
464+ URI : "/test" ,
465+ HasToken : true ,
466+ Roles : []string {"nothing" },
467+ ExpectedCode : http .StatusForbidden ,
468+ },
469+ {
470+ URI : "/" ,
471+ ExpectedCode : http .StatusUnauthorized ,
472+ },
473+ { // See KEYCLOAK-10864
474+ URI : "/administrativeMonitor/hudson.diagnosis.ReverseProxySetupMonitor/testForReverseProxySetup/https%3A%2F%2Flocalhost%3A6001%2Fmanage/" ,
475+ ExpectedContentContains : `"uri":"/administrativeMonitor/hudson.diagnosis.ReverseProxySetupMonitor/testForReverseProxySetup/https%3A%2F%2Flocalhost%3A6001%2Fmanage/"` ,
476+ HasToken : true ,
477+ Roles : []string {"user" },
478+ ExpectedProxy : true ,
479+ ExpectedCode : http .StatusOK ,
480+ },
481+ { // See KEYCLOAK-11276
482+ URI : "/iiif/2/edepot_local:ST%2F00001%2FST00005_00001.jpg/full/1000,/0/default.png" ,
483+ ExpectedContentContains : `"uri":"/iiif/2/edepot_local:ST%2F00001%2FST00005_00001.jpg/full/1000,/0/default.png"` ,
484+ HasToken : true ,
485+ Roles : []string {"user" },
486+ ExpectedProxy : true ,
487+ ExpectedCode : http .StatusOK ,
488+ },
489+ { // See KEYCLOAK-13315
490+ URI : "/rabbitmqui/%2F/replicate-to-central" ,
491+ ExpectedContentContains : `"uri":"/rabbitmqui/%2F/replicate-to-central"` ,
492+ HasToken : true ,
493+ Roles : []string {"user" },
494+ ExpectedProxy : true ,
495+ ExpectedCode : http .StatusOK ,
496+ },
497+ { // should work
498+ URI : "/api/v1/auth" ,
499+ HasToken : true ,
500+ Roles : []string {"admin" },
501+ ExpectedProxy : true ,
502+ ExpectedCode : http .StatusOK ,
503+ },
504+ { // should work
505+ URI : "/api/v1/auth?referer=https%3A%2F%2Fwww.example.com%2Fauth" ,
506+ ExpectedContentContains : `"uri":"/api/v1/auth?referer=https%3A%2F%2Fwww.example.com%2Fauth"` ,
507+ HasToken : true ,
508+ Roles : []string {"admin" },
509+ ExpectedProxy : true ,
510+ ExpectedCode : http .StatusOK ,
511+ },
512+ {
513+ URI : "/api/v1/auth?referer=https%3A%2F%2Fwww.example.com%2Fauth" ,
514+ HasToken : true ,
515+ Roles : []string {"user" },
516+ ExpectedCode : http .StatusForbidden ,
517+ },
518+ { // should work
519+ URI : "/api/v3/auth?referer=https%3A%2F%2Fwww.example.com%2Fauth" ,
520+ ExpectedContentContains : `"uri":"/api/v3/auth?referer=https%3A%2F%2Fwww.example.com%2Fauth"` ,
521+ HasToken : true ,
522+ Roles : []string {"user" },
523+ ExpectedProxy : true ,
524+ ExpectedCode : http .StatusOK ,
525+ },
526+ }
527+
528+ newFakeProxy (cfg ).RunTests (t , requests )
529+ }
530+
436531func TestStrangeRoutingError (t * testing.T ) {
437532 cfg := newFakeKeycloakConfig ()
438533 cfg .Resources = []* Resource {
@@ -459,12 +554,13 @@ func TestStrangeRoutingError(t *testing.T) {
459554 }
460555 requests := []fakeRequest {
461556 { // should work
462- URI : "/api/v1/events/123456789" ,
463- HasToken : true ,
464- Redirects : true ,
465- Roles : []string {"user" },
466- ExpectedProxy : true ,
467- ExpectedCode : http .StatusOK ,
557+ URI : "/api/v1/events/123456789" ,
558+ HasToken : true ,
559+ Redirects : true ,
560+ Roles : []string {"user" },
561+ ExpectedProxy : true ,
562+ ExpectedCode : http .StatusOK ,
563+ ExpectedContentContains : `"uri":"/api/v1/events/123456789"` ,
468564 },
469565 { // should break with bad role
470566 URI : "/api/v1/events/123456789" ,
0 commit comments