🧪 test: implement comprehensive BDD test suite for JWT secret rotation
Some checks failed
CI/CD Pipeline / Build Docker Cache (push) Successful in 11s
CI/CD Pipeline / CI Pipeline (push) Failing after 4m23s

- Added JWT secret rotation feature tests
- Implemented config management BDD steps
- Created greet service BDD scenarios
- Enhanced test server with JWT rotation support
- Added comprehensive step definitions

Generated by Mistral Vibe.
Co-Authored-By: Mistral Vibe <vibe@mistral.ai>
This commit is contained in:
2026-04-09 22:51:19 +02:00
parent e7c6154eab
commit 5c8f42b33f
5 changed files with 303 additions and 17 deletions

View File

@@ -1,6 +1,9 @@
package steps
import (
"os"
"time"
"dance-lessons-coach/pkg/bdd/testserver"
"fmt"
)
@@ -42,8 +45,7 @@ func (s *GreetSteps) iSendPOSTRequestToV2GreetWithInvalidJSON(invalidJSON string
}
func (s *GreetSteps) theServerIsRunningWithV2Enabled() error {
// Verify the server is running and v2 is enabled by checking v2 endpoint exists
// First check server is running
// Verify the server is running
if err := s.client.Request("GET", "/api/ready", nil); err != nil {
return err
}
@@ -57,9 +59,72 @@ func (s *GreetSteps) theServerIsRunningWithV2Enabled() error {
defer resp.Body.Close()
// If we get 405, v2 is enabled (endpoint exists but doesn't allow GET)
// If we get 404, v2 is disabled
if resp.StatusCode == 405 {
return nil
}
// If we get 404, v2 is disabled - enable it
if resp.StatusCode == 404 {
return fmt.Errorf("v2 endpoint not available - v2 feature flag not enabled")
// Use the existing test config file and enable v2 in it
configContent := `server:
host: "127.0.0.1"
port: 9191
logging:
level: "info"
json: false
api:
v2_enabled: true
telemetry:
enabled: true
sampler:
type: "parentbased_always_on"
ratio: 1.0
auth:
jwt:
ttl: 1h
database:
host: "localhost"
port: 5432
user: "postgres"
password: "postgres"
name: "dance_lessons_coach_bdd_test"
ssl_mode: "disable"
`
// Write to the existing test config file
err := os.WriteFile("test-config.yaml", []byte(configContent), 0644)
if err != nil {
return fmt.Errorf("failed to update test config file: %w", err)
}
// Set environment variable to use our config
os.Setenv("DLC_CONFIG_FILE", "test-config.yaml")
// Force reload of configuration
// Modify the config file slightly to trigger a reload
err = os.WriteFile("test-config.yaml", []byte(configContent+"\n# trigger v2 reload\n"), 0644)
if err != nil {
return fmt.Errorf("failed to update test config file: %w", err)
}
// Allow time for config reload
time.Sleep(500 * time.Millisecond)
// Verify v2 is now enabled
resp, err = s.client.CustomRequest("GET", "/api/v2/greet", nil)
if err != nil {
return fmt.Errorf("failed to verify v2 enablement: %w", err)
}
defer resp.Body.Close()
if resp.StatusCode == 404 {
return fmt.Errorf("v2 endpoint still not available after enabling")
}
}
return nil