@@ -36,7 +36,7 @@ func TokenValidationMiddleware(config auth.ConfigProvider) echo.MiddlewareFunc {
|
||||
config.GetAuthLogger().Debug("Processing request", "path", requestPath, "method", c.Request().Method)
|
||||
|
||||
// Skip token validation for specified public paths
|
||||
publicPaths := []string{config.GetAuthHomePath(), config.GetAuthLogoutPath()}
|
||||
publicPaths := []string{config.GetAuthHomePath(), config.GetAuthLogoutPath(), config.GetHealthPath()}
|
||||
for _, path := range publicPaths {
|
||||
if requestPath == path {
|
||||
config.GetAuthLogger().Debug("Skipping token validation for public path", "path", requestPath)
|
||||
|
||||
@@ -44,6 +44,8 @@ func (m *mockConfigProvider) GetAuthHomePath() string { return "/home" }
|
||||
func (m *mockConfigProvider) SetAuthHomePath(s string) {}
|
||||
func (m *mockConfigProvider) GetAuthLogoutPath() string { return "/logout" }
|
||||
func (m *mockConfigProvider) SetAuthLogoutPath(s string) {}
|
||||
func (m *mockConfigProvider) GetHealthPath() string { return "/health" }
|
||||
func (m *mockConfigProvider) SetHealthPath(s string) {}
|
||||
func (m *mockConfigProvider) GetAuthLogger() *slog.Logger { return slog.Default() }
|
||||
func (m *mockConfigProvider) SetAuthLogger(*slog.Logger) {}
|
||||
func (m *mockConfigProvider) GetAuthRoutePermissions() map[string][]string {
|
||||
|
||||
@@ -29,6 +29,7 @@ type CognitoConfig struct {
|
||||
AuthCallbackPath string `env:"COGNITO_CALLBACK_PATH" envDefault:"/login-callback"`
|
||||
AuthHomePath string `env:"COGNITO_HOME_PATH" envDefault:"/home"`
|
||||
AuthLogoutPath string `env:"COGNITO_LOGOUT_PATH" envDefault:"/logout"`
|
||||
HealthPath string `env:"HEALTH_PATH" envDefault:"/health"`
|
||||
AuthLogger *slog.Logger // Logger instance ( normally just the same logger as main)
|
||||
AuthRoutePermissions map[string][]string // Map of routes to required permissions
|
||||
}
|
||||
@@ -63,6 +64,8 @@ type ConfigProvider interface {
|
||||
SetAuthHomePath(string)
|
||||
GetAuthLogoutPath() string
|
||||
SetAuthLogoutPath(string)
|
||||
GetHealthPath() string
|
||||
SetHealthPath(string)
|
||||
GetAuthLogger() *slog.Logger
|
||||
SetAuthLogger(*slog.Logger)
|
||||
GetAuthRoutePermissions() map[string][]string
|
||||
@@ -159,6 +162,7 @@ func (c *CognitoConfig) PrettyPrintDebugOnly() {
|
||||
"AuthCallbackPath", c.AuthCallbackPath,
|
||||
"AuthHomePath", c.AuthHomePath,
|
||||
"AuthLogoutPath", c.AuthLogoutPath,
|
||||
"HealthPath", c.HealthPath,
|
||||
"DisableAuth", c.DisableAuth,
|
||||
"AuthDomain", c.AuthDomain)
|
||||
|
||||
@@ -276,6 +280,14 @@ func (c *CognitoConfig) SetAuthLogoutPath(val string) {
|
||||
c.AuthLogoutPath = val
|
||||
}
|
||||
|
||||
func (c *CognitoConfig) GetHealthPath() string {
|
||||
return c.HealthPath
|
||||
}
|
||||
|
||||
func (c *CognitoConfig) SetHealthPath(val string) {
|
||||
c.HealthPath = val
|
||||
}
|
||||
|
||||
func (c *CognitoConfig) GetAuthLogger() *slog.Logger {
|
||||
return c.AuthLogger
|
||||
}
|
||||
|
||||
@@ -21,6 +21,7 @@ func TestInitializeAuthConfig(t *testing.T) {
|
||||
"COGNITO_CALLBACK_PATH": "/custom-callback",
|
||||
"COGNITO_HOME_PATH": "/custom-home",
|
||||
"COGNITO_LOGOUT_PATH": "/custom-logout",
|
||||
"HEALTH_PATH": "/custom-health",
|
||||
"DEBUG": "true",
|
||||
}
|
||||
|
||||
@@ -67,6 +68,7 @@ func TestInitializeAuthConfig(t *testing.T) {
|
||||
{"AuthCallbackPath", cfg.AuthCallbackPath, "/custom-callback"},
|
||||
{"AuthHomePath", cfg.AuthHomePath, "/custom-home"},
|
||||
{"AuthLogoutPath", cfg.AuthLogoutPath, "/custom-logout"},
|
||||
{"HealthPath", cfg.HealthPath, "/custom-health"},
|
||||
{"AuthRedirectURI", cfg.AuthRedirectURI, "https://example.com/custom-callback"},
|
||||
{"AuthTokenURL", cfg.AuthTokenURL, "test-domain.auth.us-east-2.amazoncognito.com/oauth2/token"},
|
||||
{"AuthURL", cfg.AuthURL, "test-domain.auth.us-east-2.amazoncognito.com/oauth2/authorize"},
|
||||
@@ -134,6 +136,7 @@ func TestInitializeAuthConfigWithDefaults(t *testing.T) {
|
||||
{"AuthCallbackPath", cfg.AuthCallbackPath, "/login-callback"},
|
||||
{"AuthHomePath", cfg.AuthHomePath, "/home"},
|
||||
{"AuthLogoutPath", cfg.AuthLogoutPath, "/logout"},
|
||||
{"HealthPath", cfg.HealthPath, "/health"},
|
||||
}
|
||||
|
||||
for _, tt := range defaults {
|
||||
@@ -246,6 +249,12 @@ func TestGettersAndSetters(t *testing.T) {
|
||||
getter: func() interface{} { return cfg.GetAuthLogoutPath() },
|
||||
expected: "/custom-logout",
|
||||
},
|
||||
{
|
||||
name: "HealthPath",
|
||||
setter: func() { cfg.SetHealthPath("/custom-health") },
|
||||
getter: func() interface{} { return cfg.GetHealthPath() },
|
||||
expected: "/custom-health",
|
||||
},
|
||||
{
|
||||
name: "AuthLogger",
|
||||
setter: func() { cfg.SetAuthLogger(testLogger) },
|
||||
|
||||
@@ -120,6 +120,9 @@ func New(ctx context.Context, config MetricsConfig) (*Metrics, error) {
|
||||
if config.ServeHttp {
|
||||
mux := http.NewServeMux()
|
||||
mux.Handle("/metrics", promhttp.Handler())
|
||||
mux.HandleFunc("/health", func(w http.ResponseWriter, r *http.Request) {
|
||||
w.WriteHeader(http.StatusOK)
|
||||
})
|
||||
|
||||
m.server = &http.Server{
|
||||
Addr: fmt.Sprintf(":%d", config.Port),
|
||||
|
||||
@@ -83,9 +83,10 @@ func createContainer(t testing.TB, ctx context.Context, network string, cfg *con
|
||||
}
|
||||
|
||||
req := testcontainers.ContainerRequest{
|
||||
Image: imageTag,
|
||||
Env: env,
|
||||
WaitingFor: wait.ForLog(cfg.WaitForMsg),
|
||||
Image: imageTag,
|
||||
Env: env,
|
||||
//WaitingFor: wait.ForLog(cfg.WaitForMsg),
|
||||
WaitingFor: wait.ForHealthCheck(),
|
||||
Entrypoint: []string{fmt.Sprintf("./%s", cfg.Name)},
|
||||
Networks: []string{network},
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user