mirror of
https://github.com/lukaszraczylo/traefikoidc.git
synced 2026-06-05 22:44:17 +00:00
1b49e133da
* Fix bug affecting Azure OIDC authentication ( and most likely others ) * Fixes issue #51 * Ensure that appended roles are unique. Update the documentation. * Improvements targetting possible memory usage spikes. * Additional fixes and cleanup * Refactoring code to fix the issues identified by the users. * Modernize run * Fieldalignment * Multiple changes to improve performance and reduce complexity. - Optimise the errors and recovery. - Deduplicate code in metadata cache. - Remove unused performance monitoring code. - Simplify session management and settings handling. * Fix claims issue. * Add ability to overwrite the default scopes in the settings file * Well.. that escalated quickly. Completely forgot that Traefik uses outdated Yaegi and requires compatibility with 1.20 ( pre-generic Go code ). * Bugfix #51: Ensures that user provided scopes overrides work. * fixup! Bugfix #51: Ensures that user provided scopes overrides work. * fixup! fixup! Bugfix #51: Ensures that user provided scopes overrides work. * Abstract the provider logic into a separate package. * Additional micro fixes and cleanups. * Simplify all the things. * fixup! Simplify all the things. * fixup! fixup! Simplify all the things. * fixup! fixup! fixup! Simplify all the things. * fixup! fixup! fixup! fixup! Simplify all the things. * ... * Cleanup tests. * fixup! Cleanup tests. * fixup! fixup! fixup! Cleanup tests. * fixup! fixup! fixup! fixup! Cleanup tests. * fixup! fixup! fixup! fixup! fixup! Cleanup tests. * Issue #53: Fix CSRF token handling in reverse proxy 1. ✅ HTTPS Detection Fixed (session.go:723) - Now uses X-Forwarded-Proto header instead of r.URL.Scheme - Properly detects HTTPS in reverse proxy environments 2. ✅ SameSite Cookie Attribute Fixed - Removed automatic SameSiteStrictMode for HTTPS (would break OAuth) - Keeps SameSiteLaxMode to allow OAuth callbacks from external domains - Only uses Strict for AJAX requests which don't involve OAuth redirects 3. ✅ Cookie Domain Handling Fixed - Now respects X-Forwarded-Host header for cookie domain - Ensures cookies are set for the public domain, not internal proxy domain 4. ✅ EnhanceSessionSecurity Properly Integrated - Function is now actually called during session save - Applies security enhancements without breaking OAuth flow Why Issue #53 Failed Before: 1. Cookies were not marked Secure in HTTPS environments (browser wouldn't send them back) 2. If they had been Secure with SameSite=Strict, Azure callbacks would still fail 3. Cookie domain might have been wrong (internal vs public domain) Why It Works Now: 1. Cookies are properly marked Secure for HTTPS 2. Uses SameSite=Lax to allow OAuth provider callbacks 3. Cookie domain uses public domain from X-Forwarded-Host 4. CSRF token persists through the entire OAuth flow * Next set of enhancements together with memory usage improvements. * Memory leak fixes and optimisations. * CSRF and Cookie Domain fixes * fixup! CSRF and Cookie Domain fixes * Metadata cache leak fix + profiling * fixup! Metadata cache leak fix + profiling * Memory leaks hunting, part 1337. * Further pursue of perfection. * fixup! Further pursue of perfection. * fixup! fixup! Further pursue of perfection. * fixup! fixup! fixup! Further pursue of perfection. * fixup! fixup! fixup! fixup! Further pursue of perfection. * fixup! fixup! fixup! fixup! fixup! Further pursue of perfection. * fixup! fixup! fixup! fixup! fixup! fixup! Further pursue of perfection. * fixup! fixup! fixup! fixup! fixup! fixup! fixup! Further pursue of perfection. * fixup! fixup! fixup! fixup! fixup! fixup! fixup! fixup! Further pursue of perfection. * fixup! fixup! fixup! fixup! fixup! fixup! fixup! fixup! fixup! Further pursue of perfection. * Clear race conditions * fixup! Clear race conditions * Weekend fun with memory leaks * Splitting code into multiple files with reasonable testing coverage. ``` ok github.com/lukaszraczylo/traefikoidc 117.017s coverage: 72.6% of statements ok github.com/lukaszraczylo/traefikoidc/auth 0.505s coverage: 87.1% of statements ok github.com/lukaszraczylo/traefikoidc/circuit_breaker 0.283s coverage: 99.0% of statements github.com/lukaszraczylo/traefikoidc/config coverage: 0.0% of statements ok github.com/lukaszraczylo/traefikoidc/handlers 0.349s coverage: 98.2% of statements ok github.com/lukaszraczylo/traefikoidc/internal/providers (cached) coverage: 94.3% of statements ok github.com/lukaszraczylo/traefikoidc/middleware 0.808s coverage: 78.0% of statements ok github.com/lukaszraczylo/traefikoidc/recovery 0.653s coverage: 100.0% of statements ok github.com/lukaszraczylo/traefikoidc/session/chunking (cached) coverage: 87.8% of statements ok github.com/lukaszraczylo/traefikoidc/session/core (cached) coverage: 85.6% of statements ok github.com/lukaszraczylo/traefikoidc/session/crypto (cached) coverage: 81.8% of statements ok github.com/lukaszraczylo/traefikoidc/session/storage (cached) coverage: 93.5% of statements ok github.com/lukaszraczylo/traefikoidc/session/validators (cached) coverage: 98.8% of statements ```` * fixup! Splitting code into multiple files with reasonable testing coverage. * fixup! fixup! Splitting code into multiple files with reasonable testing coverage. * Weekend fun with further optimisations. * fixup! Weekend fun with further optimisations. * fixup! fixup! Weekend fun with further optimisations. * fixup! fixup! fixup! Weekend fun with further optimisations. * fixup! fixup! fixup! fixup! Weekend fun with further optimisations. * fixup! fixup! fixup! fixup! fixup! Weekend fun with further optimisations. * Pre-release cleanup. * Enhance test coverage. * fixup! Enhance test coverage. * fixup! fixup! Enhance test coverage. * fixup! fixup! fixup! Enhance test coverage.
308 lines
7.8 KiB
Markdown
308 lines
7.8 KiB
Markdown
# Test Execution Guide
|
|
|
|
This guide explains how to run tests efficiently with the new test categorization and optimization system.
|
|
|
|
## Quick Start
|
|
|
|
### Fast Development Testing (Default - Target: < 30 seconds)
|
|
```bash
|
|
# Run quick smoke tests only
|
|
go test ./...
|
|
|
|
# Or explicitly run in short mode
|
|
go test ./... -short
|
|
```
|
|
|
|
### Extended Testing (Target: 2-5 minutes)
|
|
```bash
|
|
# Enable extended tests with more iterations and concurrency
|
|
RUN_EXTENDED_TESTS=1 go test ./...
|
|
|
|
# Or use the flag equivalent (if using test runner that supports it)
|
|
go test ./... -extended
|
|
```
|
|
|
|
### Long-Running Performance Tests (Target: 5-15 minutes)
|
|
```bash
|
|
# Enable comprehensive performance and stress tests
|
|
RUN_LONG_TESTS=1 go test ./...
|
|
```
|
|
|
|
### Full Stress Testing (Target: 10-30 minutes)
|
|
```bash
|
|
# Enable all stress tests with maximum parameters
|
|
RUN_STRESS_TESTS=1 go test ./...
|
|
```
|
|
|
|
## Test Categories
|
|
|
|
### 1. Quick Tests (Default)
|
|
- **Purpose**: Fast feedback during development
|
|
- **Duration**: < 30 seconds total
|
|
- **Features**:
|
|
- Basic functionality verification
|
|
- Limited iterations (1-3)
|
|
- Small data sets
|
|
- Minimal concurrency
|
|
- Essential memory leak checks
|
|
|
|
**Configuration**:
|
|
- Max Iterations: 3
|
|
- Max Concurrency: 5
|
|
- Memory Threshold: 2.0 MB
|
|
- Cache Size: 50
|
|
- Timeout: 10 seconds
|
|
|
|
### 2. Extended Tests
|
|
- **Purpose**: Comprehensive testing before commits
|
|
- **Duration**: 2-5 minutes
|
|
- **Features**:
|
|
- Increased test coverage
|
|
- More iterations (5-10)
|
|
- Medium concurrency tests
|
|
- Enhanced memory leak detection
|
|
|
|
**Configuration**:
|
|
- Max Iterations: 10
|
|
- Max Concurrency: 20
|
|
- Memory Threshold: 10.0 MB
|
|
- Cache Size: 200
|
|
- Timeout: 30 seconds
|
|
|
|
### 3. Long Tests
|
|
- **Purpose**: Performance validation and stress testing
|
|
- **Duration**: 5-15 minutes
|
|
- **Features**:
|
|
- High iteration counts (50-100)
|
|
- High concurrency scenarios
|
|
- Large data sets
|
|
- Comprehensive memory testing
|
|
|
|
**Configuration**:
|
|
- Max Iterations: 100
|
|
- Max Concurrency: 50
|
|
- Memory Threshold: 50.0 MB
|
|
- Cache Size: 1000
|
|
- Timeout: 60 seconds
|
|
|
|
### 4. Stress Tests
|
|
- **Purpose**: Maximum load testing and edge case validation
|
|
- **Duration**: 10-30 minutes
|
|
- **Features**:
|
|
- Extreme iteration counts (100-500)
|
|
- Maximum concurrency (100+)
|
|
- Large memory allocations
|
|
- Edge case combinations
|
|
|
|
**Configuration**:
|
|
- Max Iterations: 500
|
|
- Max Concurrency: 100
|
|
- Memory Threshold: 100.0 MB
|
|
- Cache Size: 2000
|
|
- Timeout: 120 seconds
|
|
|
|
## Environment Variables
|
|
|
|
### Test Execution Control
|
|
```bash
|
|
# Enable specific test types
|
|
export RUN_EXTENDED_TESTS=1 # Enable extended tests
|
|
export RUN_LONG_TESTS=1 # Enable long-running tests
|
|
export RUN_STRESS_TESTS=1 # Enable stress tests
|
|
|
|
# Disable specific features
|
|
export DISABLE_LEAK_DETECTION=1 # Skip memory leak detection
|
|
```
|
|
|
|
### Parameter Customization
|
|
```bash
|
|
# Customize concurrency limits
|
|
export TEST_MAX_CONCURRENCY=10 # Override max concurrent operations
|
|
|
|
# Customize iteration limits
|
|
export TEST_MAX_ITERATIONS=50 # Override max test iterations
|
|
|
|
# Customize memory thresholds
|
|
export TEST_MEMORY_THRESHOLD_MB=25.5 # Override memory growth limit (in MB)
|
|
```
|
|
|
|
## Test-Specific Behavior
|
|
|
|
### Memory Leak Tests
|
|
- **Quick Mode**: 1-3 iterations, small data sets, strict memory limits
|
|
- **Extended Mode**: 5-10 iterations, medium data sets, relaxed limits
|
|
- **Long Mode**: 50-100 iterations, large data sets, performance focus
|
|
- **Stress Mode**: 100-500 iterations, maximum data sets, stress focus
|
|
|
|
### Concurrency Tests
|
|
- **Quick Mode**: 2-5 concurrent operations, basic race detection
|
|
- **Extended Mode**: 10-20 concurrent operations, moderate stress
|
|
- **Long Mode**: 20-50 concurrent operations, high contention
|
|
- **Stress Mode**: 50-100+ concurrent operations, maximum stress
|
|
|
|
### Cache Tests
|
|
- **Quick Mode**: Small caches (50 items), basic operations
|
|
- **Extended Mode**: Medium caches (200 items), varied operations
|
|
- **Long Mode**: Large caches (1000 items), performance testing
|
|
- **Stress Mode**: Very large caches (2000+ items), stress testing
|
|
|
|
## Integration with CI/CD
|
|
|
|
### GitHub Actions Example
|
|
```yaml
|
|
# Quick tests for every push/PR
|
|
- name: Quick Tests
|
|
run: go test ./... -short
|
|
|
|
# Extended tests for main branch
|
|
- name: Extended Tests
|
|
if: github.ref == 'refs/heads/main'
|
|
run: RUN_EXTENDED_TESTS=1 go test ./...
|
|
|
|
# Nightly comprehensive testing
|
|
- name: Nightly Stress Tests
|
|
if: github.event_name == 'schedule'
|
|
run: RUN_STRESS_TESTS=1 go test ./...
|
|
```
|
|
|
|
### Local Development Workflow
|
|
```bash
|
|
# During active development
|
|
go test ./... -short
|
|
|
|
# Before committing
|
|
RUN_EXTENDED_TESTS=1 go test ./...
|
|
|
|
# Before major releases
|
|
RUN_LONG_TESTS=1 go test ./...
|
|
|
|
# Performance validation
|
|
RUN_STRESS_TESTS=1 go test ./...
|
|
```
|
|
|
|
## Performance Optimization Features
|
|
|
|
### Dynamic Test Scaling
|
|
The test system automatically adjusts parameters based on:
|
|
- Test mode (quick/extended/long/stress)
|
|
- Available resources
|
|
- Environment variables
|
|
- Previous test performance
|
|
|
|
### Memory Management
|
|
- **Garbage Collection**: Forced GC between test iterations
|
|
- **Memory Monitoring**: Real-time memory growth tracking
|
|
- **Leak Detection**: Goroutine and memory leak prevention
|
|
- **Resource Cleanup**: Automatic cleanup of test resources
|
|
|
|
### Timeout Management
|
|
- **Adaptive Timeouts**: Timeouts scale with test complexity
|
|
- **Graceful Degradation**: Tests adapt to slower environments
|
|
- **Early Termination**: Failed tests terminate quickly
|
|
|
|
## Troubleshooting
|
|
|
|
### Tests Taking Too Long
|
|
```bash
|
|
# Check if running in extended mode accidentally
|
|
echo $RUN_EXTENDED_TESTS $RUN_LONG_TESTS
|
|
|
|
# Force quick mode
|
|
unset RUN_EXTENDED_TESTS RUN_LONG_TESTS RUN_STRESS_TESTS
|
|
go test ./... -short
|
|
```
|
|
|
|
### Memory Issues
|
|
```bash
|
|
# Reduce memory limits for constrained environments
|
|
export TEST_MEMORY_THRESHOLD_MB=5.0
|
|
export TEST_MAX_CONCURRENCY=2
|
|
go test ./...
|
|
```
|
|
|
|
### Concurrency Issues
|
|
```bash
|
|
# Reduce concurrency for slower systems
|
|
export TEST_MAX_CONCURRENCY=5
|
|
export TEST_MAX_ITERATIONS=10
|
|
go test ./...
|
|
```
|
|
|
|
### Skip Specific Test Types
|
|
```bash
|
|
# Skip memory leak detection if problematic
|
|
export DISABLE_LEAK_DETECTION=1
|
|
go test ./...
|
|
```
|
|
|
|
## Benchmarking
|
|
|
|
### Running Benchmarks
|
|
```bash
|
|
# Quick benchmarks
|
|
go test -bench=. -short
|
|
|
|
# Extended benchmarks
|
|
RUN_EXTENDED_TESTS=1 go test -bench=.
|
|
|
|
# Memory profiling
|
|
go test -bench=. -memprofile=mem.prof
|
|
go tool pprof mem.prof
|
|
```
|
|
|
|
### Benchmark Categories
|
|
- **Basic Operations**: Set/Get performance
|
|
- **Concurrency**: Multi-threaded performance
|
|
- **Memory**: Allocation and cleanup performance
|
|
- **Cache**: Eviction and cleanup performance
|
|
|
|
## Best Practices
|
|
|
|
### For Developers
|
|
1. Always run quick tests during development (`go test ./... -short`)
|
|
2. Run extended tests before committing (`RUN_EXTENDED_TESTS=1 go test ./...`)
|
|
3. Use appropriate test categories for your use case
|
|
4. Monitor test execution time and adjust if needed
|
|
|
|
### For CI/CD
|
|
1. Use quick tests for fast feedback on PRs
|
|
2. Use extended tests for main branch validation
|
|
3. Use long tests for release validation
|
|
4. Use stress tests for nightly/weekly validation
|
|
|
|
### For Performance Testing
|
|
1. Use consistent environment variables
|
|
2. Run tests multiple times for statistical significance
|
|
3. Monitor both execution time and resource usage
|
|
4. Use profiling tools for detailed analysis
|
|
|
|
## Examples
|
|
|
|
### Daily Development
|
|
```bash
|
|
# Fast tests while coding
|
|
go test ./... -short
|
|
|
|
# Before git commit
|
|
RUN_EXTENDED_TESTS=1 go test ./...
|
|
```
|
|
|
|
### Release Testing
|
|
```bash
|
|
# Comprehensive validation
|
|
RUN_LONG_TESTS=1 go test ./...
|
|
|
|
# Stress testing
|
|
RUN_STRESS_TESTS=1 go test ./...
|
|
```
|
|
|
|
### Custom Configuration
|
|
```bash
|
|
# Custom limits for specific environment
|
|
export TEST_MAX_CONCURRENCY=8
|
|
export TEST_MAX_ITERATIONS=25
|
|
export TEST_MEMORY_THRESHOLD_MB=15.0
|
|
RUN_EXTENDED_TESTS=1 go test ./...
|
|
```
|
|
|
|
This test system provides flexible, scalable test execution that adapts to your development workflow and infrastructure constraints while maintaining comprehensive test coverage. |