Files
Komediruzecki 01e5ede600 feat: Add comprehensive E2E test specifications for backend modules
Added 18 E2E test specifications following EARS format for all backend modules:

New Specs Created:
- tags.spec.md (56 tests) - Tag CRUD, hierarchy, filtering, grouping
- receipts.spec.md (57 tests) - Receipts, OCR, splitting, sharing, export
- recurring.spec.md (57 tests) - Recurrence patterns, scheduling, timezone
- reports.spec.md (62 tests) - Custom reports, export, scheduling, comparison
- calculator.spec.md (54 tests) - Financial calculators, conversions, schedules

Existing Specs Reviewed:
- All existing backend specs validated and organized
- Each spec includes Must/Should priorities, test types, steps, validations
- Consistent formatting across all 18 specifications

Each spec covers:
- CRUD operations
- Data validation
- Performance testing
- Error handling
- Integration tests
- Cross-user data isolation
- Acceptance criteria

Format: EARS-compliant with test IDs, priorities, types (Positive/Negative/Integration/Performance), detailed steps, validations, and expected results.
2026-04-25 22:05:36 +00:00

5.7 KiB

Authentication Specification

Module: Authentication Version: 2.0 Status: Active Priority: Must

1. Overview

The Authentication module handles user login, logout, session management, and authorization for the Finance Manager application.

2. Functional Requirements

2.1. Authentication Endpoints

ID Description Type
A-001 Login endpoint must accept username and password Must
A-002 Login endpoint must validate credentials against local storage Must
A-003 Login endpoint must return authentication token on success Must
A-004 Login endpoint must return error on invalid credentials Must
A-005 Login endpoint must enforce rate limiting Must
A-006 Logout endpoint must invalidate current token Must
A-007 Logout endpoint must clear session data Must
A-008 Logout endpoint must enforce rate limiting Must
A-009 Current user endpoint must return authenticated user profile Must
A-010 Current user endpoint must enforce authentication Must

2.2. Token Management

ID Description Type
A-011 API endpoints must require valid authentication token for protected routes Must
A-012 Token must be sent in Authorization header (Bearer scheme) Must
A-013 Tokens must have expiry time for security Should
A-014 Token refresh mechanism must be implemented Should

2.3. Session Management

ID Description Type
A-020 Session must be stored in localStorage for client-side persistence Must
A-021 Session must expire after configured timeout Should
A-022 Application must auto-logout on token expiry Should
A-023 Session must persist across page reloads Should

2.4. Security Features

ID Description Type
A-030 Password storage must use strong hashing (bcrypt/scrypt) Must
A-031 Login attempts must be rate-limited (default: 5 per minute) Must
A-032 Rate limiting must be based on IP address Must
A-033 Rate limit must reset after time period Must
A-034 Rate limit must return 429 status on exceeded Must

2.5. Error Handling

ID Description Type
A-040 Login must return 401 Unauthorized for invalid credentials Must
A-041 Login must return 429 Too Many Requests on rate limit exceeded Must
A-042 Logout must return 401 if token is invalid Must
A-043 API responses must include error message in JSON Must

3. Non-Functional Requirements

3.1. Performance

ID Description Target
NFR-001 Login request must complete within 500ms 500ms
NFR-002 Logout request must complete within 100ms 100ms
NFR-003 Rate limiting must not impact response time 0ms

3.2. Security

ID Description Requirement
NFR-004 Passwords must never be logged Always
NFR-005 Rate limit data must not be logged Always
NFR-006 Failed login attempts must be tracked Should
NFR-007 Brute force protection must be in place Should

3.3. Data Consistency

ID Description Requirement
NFR-008 Session state must be consistent across requests Always
NFR-009 Token validation must be atomic Always

4. API Endpoints

Endpoint Method Description
/api/auth/login POST Authenticate user and return token
/api/auth/logout POST Invalidate current session
/api/auth/me GET Get current authenticated user

5. Data Models

AuthResponse:

  • token: string - JWT authentication token
  • expiresIn: number - Token expiry time in seconds
  • user: UserProfile - User profile information

UserProfile:

  • id: string - User ID
  • username: string - Username
  • fullName: string - Full name
  • email: string - Email address

Error:

  • error: string - Error message
  • code: number - HTTP status code

6. User Flows

6.1. Login Flow

  1. User submits username and password
  2. System validates credentials
  3. System generates JWT token
  4. System returns token and user profile
  5. Frontend stores token in localStorage

6.2. Logout Flow

  1. User clicks logout button
  2. Frontend calls logout endpoint
  3. Frontend clears localStorage
  4. Frontend redirects to login page

6.3. Protected Route Access

  1. User attempts to access protected route
  2. Frontend checks for valid token
  3. If token exists, request includes Authorization header
  4. If no token, redirects to login

7. Exceptional Conditions

Condition Behavior
Invalid username/password Return 401 Unauthorized
Rate limit exceeded Return 429 with retry time
Token expired Return 401, frontend must re-authenticate
No network connection Return connection error to frontend
Hashed password mismatch Treated as invalid credentials

8. Open/Closed Questions

  1. Should 2FA be supported?
  2. Should password reset functionality be implemented?
  3. Should social login (Google, etc.) be supported?
  4. Should sessions be stored server-side for better security?

9. Acceptance Criteria

  • User can successfully login with valid credentials
  • User receives JWT token on successful login
  • User is redirected to dashboard on successful login
  • Invalid credentials show appropriate error message
  • Rate limiting prevents brute force attempts
  • Logout invalidates session
  • Protected routes require authentication
  • Tokens are stored securely in localStorage