Implemented complete user authentication system following ADR-0018: **Core Features:** - User model with SQLite persistence (in-memory) - JWT-based authentication with bcrypt hashing - Admin master password authentication (non-persisted) - Password reset workflow - RESTful API endpoints **API Endpoints:** - POST /api/v1/auth/register - User registration - POST /api/v1/auth/login - User login - POST /api/v1/auth/admin/login - Admin login - POST /api/v1/auth/password-reset/request - Request password reset - POST /api/v1/auth/password-reset/complete - Complete password reset **Technical Implementation:** - SQLite in-memory database (file::memory:?cache=shared) - GORM ORM for data access - JWT with HS256 signing - Bcrypt password hashing - Context-aware services - Interface-based design **Testing:** - All BDD tests passing (14 scenarios, 55 steps) - Unit tests for repository, auth service, password reset - No regression in existing functionality **Configuration:** - JWT secret via config/auth.jwt_secret - Admin master password via config/auth.admin_master_password - Environment variables: DLC_AUTH_JWT_SECRET, DLC_AUTH_ADMIN_MASTER_PASSWORD Generated by Mistral Vibe. Co-Authored-By: Mistral Vibe <vibe@mistral.ai>
BDD Testing with Godog
This package implements Behavior-Driven Development (BDD) testing using the Godog framework.
Important Requirements for Step Definitions
Step Pattern Matching
Godog has very specific requirements for step pattern matching. To avoid "undefined" warnings:
- Use the exact regex pattern that Godog suggests in its error messages
- Use the exact parameter names that Godog suggests (
arg1, arg2, etc.) - Match the feature file syntax exactly including quotes and JSON formatting
Example
Feature file step:
Then the response should be "{\"message\":\"Hello world!\"}"
Correct step definition:
ctx.Step(`^the response should be "{\"([^"]*)\":\"([^"]*)\"}"$`, func(arg1, arg2 string) error {
// Implementation here
return nil
})
Incorrect patterns that cause "undefined" warnings:
// Wrong: Different regex pattern
ctx.Step(`^the response should be "{\"message\":\"([^"]*)\"}"$`, func(message string) error {
// ...
})
// Wrong: Different parameter names
ctx.Step(`^the response should be "{\"([^"]*)\":\"([^"]*)\"}"$`, func(key, value string) error {
// ...
})
Current Implementation
Step Definition Strategy
- First eliminate "undefined" warnings by using Godog's exact suggested patterns
- Return
godog.ErrPendinginitially to confirm pattern matching works - Then implement actual validation logic
Files
suite.go: Test suite initialization and server managementtestserver/: Test server and client implementationsteps/: Step definitions for each feature
Debugging "Undefined" Steps
If you see "undefined" warnings:
-
Run the tests to see Godog's suggested pattern:
go test ./features/... -v -
Copy the exact regex pattern from the error message
-
Copy the exact parameter names (
arg1, arg2, etc.) -
Update your step definition to match exactly
Common Mistakes
The "undefined" warnings are not a Godog bug - they occur when step definitions don't match Godog's expected patterns exactly:
- Using different regex patterns than what Godog suggests
- Using descriptive parameter names instead of
arg1, arg2 - Not escaping quotes properly in JSON patterns
- Trying to be "clever" with regex optimization
Solution: Always use the exact pattern and parameter names that Godog suggests in its error messages.
Best Practices
- Follow Godog's suggestions exactly - Copy-paste the pattern and parameter names
- Test pattern matching first - Use
godog.ErrPendingto verify patterns work - Then implement logic - Replace
godog.ErrPendingwith actual validation - Don't over-optimize regex - Use the patterns Godog provides, even if they seem verbose
- One pattern per step type - Use generic patterns to cover similar steps
Why This Matters
Godog's step matching is very specific by design:
- It needs to reliably match feature file steps to code
- It provides exact patterns to ensure consistency
- Following its suggestions guarantees your steps will be recognized
Remember: The "undefined" warnings are Godog telling you exactly how to fix your step definitions!