fix(server/auth): return 404 or 405 depending on route

- Fix #3275
This commit is contained in:
Quentin McGaw
2026-04-07 19:41:05 +00:00
parent 11883aa830
commit 3b9c9b24bd
3 changed files with 69 additions and 42 deletions
@@ -32,28 +32,28 @@ func Test_authHandler_ServeHTTP(t *testing.T) {
},
makeLogger: func(ctrl *gomock.Controller) *MockDebugLogger {
logger := NewMockDebugLogger(ctrl)
logger.EXPECT().Debugf("no authentication role defined for route %s", "GET /b")
logger.EXPECT().Debugf("url path %s is not a valid route", "/b")
return logger
},
requestMethod: http.MethodGet,
requestPath: "/b",
statusCode: http.StatusUnauthorized,
responseBody: "Unauthorized\n",
statusCode: http.StatusNotFound,
responseBody: "Not Found\n",
},
"authorized_none": {
settings: Settings{
Roles: []Role{
{Name: "role1", Auth: AuthNone, Routes: []string{"GET /a"}},
{Name: "role1", Auth: AuthNone, Routes: []string{"GET /v1/portforward"}},
},
},
makeLogger: func(ctrl *gomock.Controller) *MockDebugLogger {
logger := NewMockDebugLogger(ctrl)
logger.EXPECT().Debugf("access to route %s authorized for role %s",
"GET /a", "role1")
"GET /v1/portforward", "role1")
return logger
},
requestMethod: http.MethodGet,
requestPath: "/a",
requestPath: "/v1/portforward",
statusCode: http.StatusOK,
},
}