🧪 test: add JWT secret rotation BDD scenarios and step implementations #12
@@ -65,7 +65,7 @@ GODOG_TAGS="@jwt && ~@todo" go test ./features/...
|
||||
DLC_DATABASE_HOST=localhost GODOG_TAGS="@wip" go test ./features/jwt/...
|
||||
```
|
||||
|
||||
**Default Behavior:** If `GODOG_TAGS` is not set, the test uses the default tag filter: `~@flaky && ~@todo && ~@skip && @wip`
|
||||
**Default Behavior:** If `GODOG_TAGS` is not set, the test uses the default tag filter: `~@flaky && ~@todo && ~@skip`
|
||||
|
||||
## Usage Examples
|
||||
|
||||
|
||||
@@ -17,7 +17,7 @@ func TestAuthBDD(t *testing.T) {
|
||||
tags := os.Getenv("GODOG_TAGS")
|
||||
if tags == "" {
|
||||
// Default tags if not overridden
|
||||
tags = "~@flaky && ~@todo && ~@skip && @wip"
|
||||
tags = "~@flaky && ~@todo && ~@skip"
|
||||
}
|
||||
|
||||
suite := godog.TestSuite{
|
||||
@@ -30,7 +30,7 @@ func TestAuthBDD(t *testing.T) {
|
||||
TestingT: t,
|
||||
Strict: true,
|
||||
Randomize: -1,
|
||||
StopOnFailure: true,
|
||||
StopOnFailure: false,
|
||||
Tags: tags,
|
||||
},
|
||||
}
|
||||
|
||||
@@ -32,17 +32,25 @@ func TestBDD(t *testing.T) {
|
||||
paths = []string{feature}
|
||||
}
|
||||
|
||||
// Allow tag override via environment variable
|
||||
tags := os.Getenv("GODOG_TAGS")
|
||||
if tags == "" {
|
||||
// Default tags if not overridden
|
||||
tags = "~@flaky && ~@todo && ~@skip"
|
||||
}
|
||||
|
||||
suite := godog.TestSuite{
|
||||
Name: suiteName,
|
||||
TestSuiteInitializer: bdd.InitializeTestSuite,
|
||||
ScenarioInitializer: bdd.InitializeScenario,
|
||||
Options: &godog.Options{
|
||||
Format: "progress",
|
||||
Paths: paths,
|
||||
TestingT: t,
|
||||
Strict: true,
|
||||
Randomize: -1,
|
||||
// StopOnFailure: true,
|
||||
Format: "progress",
|
||||
Paths: paths,
|
||||
TestingT: t,
|
||||
Strict: true,
|
||||
Randomize: -1,
|
||||
StopOnFailure: false,
|
||||
Tags: tags,
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
@@ -2,12 +2,14 @@
|
||||
Feature: Config Hot Reloading
|
||||
The system should support selective hot reloading of configuration changes
|
||||
|
||||
@flaky
|
||||
Scenario: Hot reloading logging level changes
|
||||
Given the server is running with config file monitoring enabled
|
||||
When I update the logging level to "debug" in the config file
|
||||
Then the logging level should be updated without restart
|
||||
And debug logs should appear in the output
|
||||
|
||||
@flaky
|
||||
Scenario: Hot reloading feature flags
|
||||
Given the server is running with config file monitoring enabled
|
||||
And the v2 API is disabled
|
||||
@@ -15,6 +17,7 @@ Feature: Config Hot Reloading
|
||||
Then the v2 API should become available without restart
|
||||
And v2 API requests should succeed
|
||||
|
||||
@flaky
|
||||
Scenario: Hot reloading telemetry sampling settings
|
||||
Given the server is running with config file monitoring enabled
|
||||
And telemetry is enabled
|
||||
@@ -23,6 +26,7 @@ Feature: Config Hot Reloading
|
||||
Then the telemetry sampling should be updated without restart
|
||||
And the new sampling settings should be applied
|
||||
|
||||
@flaky
|
||||
Scenario: Hot reloading JWT TTL
|
||||
Given the server is running with config file monitoring enabled
|
||||
And JWT TTL is set to 1 hour
|
||||
@@ -30,6 +34,7 @@ Feature: Config Hot Reloading
|
||||
Then the JWT TTL should be updated without restart
|
||||
And new JWT tokens should have the updated expiration
|
||||
|
||||
@flaky
|
||||
Scenario: Attempting to hot reload non-reloadable settings should be ignored
|
||||
Given the server is running with config file monitoring enabled
|
||||
When I update the server port to 9090 in the config file
|
||||
@@ -37,6 +42,7 @@ Feature: Config Hot Reloading
|
||||
And the server should continue running on the original port
|
||||
And a warning should be logged about ignored configuration change
|
||||
|
||||
@flaky
|
||||
Scenario: Invalid configuration changes should be handled gracefully
|
||||
Given the server is running with config file monitoring enabled
|
||||
When I update the logging level to "invalid_level" in the config file
|
||||
@@ -44,12 +50,14 @@ Feature: Config Hot Reloading
|
||||
And an error should be logged about invalid configuration
|
||||
And the server should continue running normally
|
||||
|
||||
@flaky
|
||||
Scenario: Config file monitoring should handle file deletion gracefully
|
||||
Given the server is running with config file monitoring enabled
|
||||
When I delete the config file
|
||||
Then the server should continue running with last known good configuration
|
||||
And a warning should be logged about missing config file
|
||||
|
||||
@flaky
|
||||
Scenario: Config file monitoring should handle file recreation
|
||||
Given the server is running with config file monitoring enabled
|
||||
And I have deleted the config file
|
||||
@@ -57,6 +65,7 @@ Feature: Config Hot Reloading
|
||||
Then the server should reload the configuration
|
||||
And the new configuration should be applied
|
||||
|
||||
@flaky
|
||||
Scenario: Multiple rapid configuration changes should be handled
|
||||
Given the server is running with config file monitoring enabled
|
||||
When I rapidly update the logging level multiple times
|
||||
@@ -64,6 +73,7 @@ Feature: Config Hot Reloading
|
||||
And the final configuration should be applied
|
||||
And no configuration changes should be lost
|
||||
|
||||
@flaky
|
||||
Scenario: Configuration changes should be audited
|
||||
Given the server is running with config file monitoring enabled
|
||||
And audit logging is enabled
|
||||
|
||||
@@ -17,7 +17,7 @@ func TestConfigBDD(t *testing.T) {
|
||||
tags := os.Getenv("GODOG_TAGS")
|
||||
if tags == "" {
|
||||
// Default tags if not overridden
|
||||
tags = "~@flaky && ~@todo && ~@skip && @wip"
|
||||
tags = "~@flaky && ~@todo && ~@skip"
|
||||
}
|
||||
|
||||
suite := godog.TestSuite{
|
||||
|
||||
@@ -17,7 +17,7 @@ func TestGreetBDD(t *testing.T) {
|
||||
tags := os.Getenv("GODOG_TAGS")
|
||||
if tags == "" {
|
||||
// Default tags if not overridden
|
||||
tags = "~@flaky && ~@todo && ~@skip && @wip"
|
||||
tags = "~@flaky && ~@todo && ~@skip"
|
||||
}
|
||||
|
||||
suite := godog.TestSuite{
|
||||
@@ -30,7 +30,7 @@ func TestGreetBDD(t *testing.T) {
|
||||
TestingT: t,
|
||||
Strict: true,
|
||||
Randomize: -1,
|
||||
StopOnFailure: true,
|
||||
StopOnFailure: false,
|
||||
Tags: tags,
|
||||
},
|
||||
}
|
||||
|
||||
@@ -17,7 +17,7 @@ func TestHealthBDD(t *testing.T) {
|
||||
tags := os.Getenv("GODOG_TAGS")
|
||||
if tags == "" {
|
||||
// Default tags if not overridden
|
||||
tags = "~@flaky && ~@todo && ~@skip && @wip"
|
||||
tags = "~@flaky && ~@todo && ~@skip"
|
||||
}
|
||||
|
||||
suite := godog.TestSuite{
|
||||
@@ -30,7 +30,7 @@ func TestHealthBDD(t *testing.T) {
|
||||
TestingT: t,
|
||||
Strict: true,
|
||||
Randomize: -1,
|
||||
StopOnFailure: true,
|
||||
StopOnFailure: false,
|
||||
Tags: tags,
|
||||
},
|
||||
}
|
||||
|
||||
@@ -4,7 +4,6 @@ Feature: JWT Secret Rotation
|
||||
I want to rotate JWT secrets without disrupting users
|
||||
So that we can maintain security while ensuring continuous service
|
||||
|
||||
@wip
|
||||
Scenario: Authentication with multiple valid JWT secrets
|
||||
Given the server is running with multiple JWT secrets
|
||||
And a user "multiuser" exists with password "testpass123"
|
||||
@@ -12,7 +11,6 @@ Feature: JWT Secret Rotation
|
||||
Then the authentication should be successful
|
||||
And I should receive a valid JWT token signed with the primary secret
|
||||
|
||||
@todo
|
||||
Scenario: Token validation with multiple valid secrets
|
||||
Given the server is running with multiple JWT secrets
|
||||
And a user "tokenuser" exists with password "testpass123"
|
||||
@@ -23,7 +21,6 @@ Feature: JWT Secret Rotation
|
||||
Then the token should be valid
|
||||
And it should contain the correct user ID
|
||||
|
||||
@todo
|
||||
Scenario: Secret rotation - adding new secret while keeping old one valid
|
||||
Given the server is running with primary JWT secret
|
||||
And a user "rotateuser" exists with password "testpass123"
|
||||
@@ -37,14 +34,12 @@ Feature: JWT Secret Rotation
|
||||
When I validate the old JWT token signed with primary secret
|
||||
Then the token should still be valid
|
||||
|
||||
@todo
|
||||
Scenario: Token rejection after secret expiration
|
||||
Given the server is running with primary and expired secondary JWT secrets
|
||||
When I use a JWT token signed with the expired secondary secret for authentication
|
||||
Then the authentication should fail
|
||||
And the response should contain error "invalid_token"
|
||||
|
||||
@todo
|
||||
Scenario: Graceful secret rotation with user continuity
|
||||
Given the server is running with primary JWT secret
|
||||
And a user "gracefuluser" exists with password "testpass123"
|
||||
|
||||
@@ -17,7 +17,7 @@ func TestJWTBDD(t *testing.T) {
|
||||
tags := os.Getenv("GODOG_TAGS")
|
||||
if tags == "" {
|
||||
// Default tags if not overridden
|
||||
tags = "~@flaky && ~@todo && ~@skip && @wip"
|
||||
tags = "~@flaky && ~@todo && ~@skip"
|
||||
}
|
||||
|
||||
suite := godog.TestSuite{
|
||||
@@ -30,7 +30,7 @@ func TestJWTBDD(t *testing.T) {
|
||||
TestingT: t,
|
||||
Strict: true,
|
||||
Randomize: -1,
|
||||
StopOnFailure: true,
|
||||
StopOnFailure: false,
|
||||
Tags: tags,
|
||||
},
|
||||
}
|
||||
|
||||
@@ -126,13 +126,13 @@ run_tests_with_tags() {
|
||||
set +e
|
||||
|
||||
if [ -n "$tags" ]; then
|
||||
# Use godog directly for tag filtering with exclusion and WIP inclusion
|
||||
echo "🚀 Running: godog $tags --tags=~@flaky --tags=~@todo --tags=~@skip --tags=@wip features/"
|
||||
test_output=$(godog $tags --tags=~@flaky --tags=~@todo --tags=~@skip --tags=@wip features/ 2>&1)
|
||||
# Use godog directly for tag filtering with exclusion
|
||||
echo "🚀 Running: godog $tags --tags=~@flaky --tags=~@todo --tags=~@skip features/"
|
||||
test_output=$(godog $tags --tags=~@flaky --tags=~@todo --tags=~@skip features/ 2>&1)
|
||||
else
|
||||
# Use go test for full test suite with tag exclusion and WIP inclusion
|
||||
echo "🚀 Running: go test ./features/... -tags=~@flaky,~@todo,~@skip,@wip"
|
||||
test_output=$(go test ./features/... -tags=~@flaky,~@todo,~@skip,@wip -v -cover -coverpkg=./... -coverprofile=coverage.out 2>&1)
|
||||
# Use go test for full test suite with tag exclusion
|
||||
echo "🚀 Running: go test ./features/... -tags=~@flaky,~@todo,~@skip"
|
||||
test_output=$(go test ./features/... -tags=~@flaky,~@todo,~@skip -v -cover -coverpkg=./... -coverprofile=coverage.out 2>&1)
|
||||
fi
|
||||
|
||||
test_exit_code=$?
|
||||
|
||||
@@ -43,9 +43,9 @@ run_feature_test() {
|
||||
docker exec dance-lessons-coach-postgres createdb -U postgres "${DLC_DATABASE_NAME}"
|
||||
fi
|
||||
|
||||
# Run the feature tests with tag exclusion and WIP inclusion
|
||||
# Run the feature tests with tag exclusion
|
||||
cd "features/${feature_name}"
|
||||
FEATURE=${feature_name} DLC_DATABASE_NAME="${DLC_DATABASE_NAME}" go test -v . -tags="~@flaky && ~@todo && ~@skip && @wip" 2>&1 | grep -E "(PASS|FAIL|RUN)" || true
|
||||
FEATURE=${feature_name} DLC_DATABASE_NAME="${DLC_DATABASE_NAME}" go test -v . -tags="~@flaky && ~@todo && ~@skip" 2>&1 | grep -E "(PASS|FAIL|RUN)" || true
|
||||
|
||||
# Cleanup
|
||||
cd ../..
|
||||
|
||||
@@ -110,7 +110,7 @@ run_feature_tests() {
|
||||
|
||||
# Run tests with proper coverage measurement and tag exclusion
|
||||
set +e
|
||||
test_output=$(go test ./features/${FEATURE}/... -tags=~@flaky,~@todo,~@skip,@wip -v -cover -coverpkg=./... -coverprofile=coverage-${FEATURE}.out 2>&1)
|
||||
test_output=$(go test ./features/${FEATURE}/... -tags=~@flaky,~@todo,~@skip -v -cover -coverpkg=./... -coverprofile=coverage-${FEATURE}.out 2>&1)
|
||||
test_exit_code=$?
|
||||
set -e
|
||||
|
||||
|
||||
Reference in New Issue
Block a user