🧪 test: add JWT edge case scenarios with validation endpoint
- Add expired JWT token scenario - Add wrong secret JWT token scenario - Add malformed JWT token scenario - Implement /api/v1/auth/validate endpoint - Add JWT parsing and validation to BDD steps Generated by Mistral Vibe. Co-Authored-By: Mistral Vibe <vibe@mistral.ai>
This commit is contained in:
@@ -13,6 +13,11 @@ import (
|
||||
"dance-lessons-coach/pkg/version"
|
||||
)
|
||||
|
||||
// NewZerologWriter creates a zerolog writer based on configuration
|
||||
func NewZerologWriter() *os.File {
|
||||
return os.Stderr
|
||||
}
|
||||
|
||||
// Config represents the application configuration
|
||||
type Config struct {
|
||||
Server ServerConfig `mapstructure:"server"`
|
||||
@@ -21,6 +26,7 @@ type Config struct {
|
||||
Telemetry TelemetryConfig `mapstructure:"telemetry"`
|
||||
API APIConfig `mapstructure:"api"`
|
||||
Auth AuthConfig `mapstructure:"auth"`
|
||||
Database DatabaseConfig `mapstructure:"database"`
|
||||
}
|
||||
|
||||
// ServerConfig holds server-related configuration
|
||||
@@ -67,6 +73,19 @@ type AuthConfig struct {
|
||||
AdminMasterPassword string `mapstructure:"admin_master_password"`
|
||||
}
|
||||
|
||||
// DatabaseConfig holds database configuration
|
||||
type DatabaseConfig struct {
|
||||
Host string `mapstructure:"host"`
|
||||
Port int `mapstructure:"port"`
|
||||
User string `mapstructure:"user"`
|
||||
Password string `mapstructure:"password"`
|
||||
Name string `mapstructure:"name"`
|
||||
SSLMode string `mapstructure:"ssl_mode"`
|
||||
MaxOpenConns int `mapstructure:"max_open_conns"`
|
||||
MaxIdleConns int `mapstructure:"max_idle_conns"`
|
||||
ConnMaxLifetime time.Duration `mapstructure:"conn_max_lifetime"`
|
||||
}
|
||||
|
||||
// VersionInfo holds application version information
|
||||
type VersionInfo struct {
|
||||
Version string `mapstructure:"-"` // Set via ldflags
|
||||
@@ -257,6 +276,11 @@ func (c *Config) GetAdminMasterPassword() string {
|
||||
return c.Auth.AdminMasterPassword
|
||||
}
|
||||
|
||||
// GetLoggingJSON returns whether JSON logging is enabled
|
||||
func (c *Config) GetLoggingJSON() bool {
|
||||
return c.Logging.JSON
|
||||
}
|
||||
|
||||
// GetLogLevel returns the logging level
|
||||
func (c *Config) GetLogLevel() string {
|
||||
return c.Logging.Level
|
||||
@@ -267,6 +291,75 @@ func (c *Config) GetLogOutput() string {
|
||||
return c.Logging.Output
|
||||
}
|
||||
|
||||
// GetDatabaseHost returns the database host
|
||||
func (c *Config) GetDatabaseHost() string {
|
||||
if c.Database.Host == "" {
|
||||
return "localhost"
|
||||
}
|
||||
return c.Database.Host
|
||||
}
|
||||
|
||||
// GetDatabasePort returns the database port
|
||||
func (c *Config) GetDatabasePort() int {
|
||||
if c.Database.Port == 0 {
|
||||
return 5432
|
||||
}
|
||||
return c.Database.Port
|
||||
}
|
||||
|
||||
// GetDatabaseUser returns the database user
|
||||
func (c *Config) GetDatabaseUser() string {
|
||||
if c.Database.User == "" {
|
||||
return "postgres"
|
||||
}
|
||||
return c.Database.User
|
||||
}
|
||||
|
||||
// GetDatabasePassword returns the database password
|
||||
func (c *Config) GetDatabasePassword() string {
|
||||
return c.Database.Password
|
||||
}
|
||||
|
||||
// GetDatabaseName returns the database name
|
||||
func (c *Config) GetDatabaseName() string {
|
||||
if c.Database.Name == "" {
|
||||
return "dance_lessons_coach"
|
||||
}
|
||||
return c.Database.Name
|
||||
}
|
||||
|
||||
// GetDatabaseSSLMode returns the database SSL mode
|
||||
func (c *Config) GetDatabaseSSLMode() string {
|
||||
if c.Database.SSLMode == "" {
|
||||
return "disable"
|
||||
}
|
||||
return c.Database.SSLMode
|
||||
}
|
||||
|
||||
// GetDatabaseMaxOpenConns returns the maximum number of open connections
|
||||
func (c *Config) GetDatabaseMaxOpenConns() int {
|
||||
if c.Database.MaxOpenConns == 0 {
|
||||
return 25
|
||||
}
|
||||
return c.Database.MaxOpenConns
|
||||
}
|
||||
|
||||
// GetDatabaseMaxIdleConns returns the maximum number of idle connections
|
||||
func (c *Config) GetDatabaseMaxIdleConns() int {
|
||||
if c.Database.MaxIdleConns == 0 {
|
||||
return 5
|
||||
}
|
||||
return c.Database.MaxIdleConns
|
||||
}
|
||||
|
||||
// GetDatabaseConnMaxLifetime returns the maximum lifetime of connections
|
||||
func (c *Config) GetDatabaseConnMaxLifetime() time.Duration {
|
||||
if c.Database.ConnMaxLifetime == 0 {
|
||||
return time.Hour
|
||||
}
|
||||
return c.Database.ConnMaxLifetime
|
||||
}
|
||||
|
||||
// SetupLogging configures zerolog based on the configuration
|
||||
func (c *Config) SetupLogging() {
|
||||
// Parse log level
|
||||
|
||||
Reference in New Issue
Block a user