Restructure repository and implement secure search feature

Phase 1: Consolidate shared infrastructure
- Create shared/ directory for common code
- Consolidate Database.php from front-backend and formulaire into unified shared/Database.php
  - Smart path detection for test.db vs posterg.db
  - Secure search with wildcard escaping and input validation
  - Support both singleton and direct instantiation patterns
  - Full CRUD methods for admin functionality
- Move RateLimit.php to shared/ (30 requests/min)
- Update all require paths across apps to use shared/

Phase 2: Reorganize directory structure
- Rename front-backend/ → apps/public/
- Rename formulaire/ → apps/admin/
- Rename db/ → database/
- Update all file paths for new structure
- Create root .gitignore excluding databases, cache, logs

Implement secure search feature
- Add apps/public/search.php with full-text search across theses
- Search filters: query, year, orientation, AP program, keywords
- Security features:
  - SQL injection prevention (prepared statements)
  - Wildcard injection prevention (escape % and _)
  - Input validation (max 200 chars, year range 1900-2100)
  - Rate limiting (30 req/min per IP)
  - Pagination limited to 100 results/page
  - XSS protection (htmlspecialchars on output)

Add comprehensive test suite
- Create apps/public/tests/ with proper structure
  - tests/Integration/SearchTest.php - 12 search scenarios
  - tests/Security/SecurityTest.php - vulnerability testing
  - tests/Unit/RateLimitTest.php - rate limit behavior
- Create database/fixtures/CreateTestDatabase.php
- Add apps/public/run-tests.php test runner
- All tests passing (4/4 suites)

Update deployment configuration
- Rename justfile 'sync' recipe to 'deploy'
- Create deploy group with separate deploy-public and deploy-admin
- Add test-deploy recipe for test database
- Exclude *.db, tests/, cache/, *.md from production deploy
- Deploy shared/ to both public and admin locations

Stats: +4482 insertions, -654 deletions across 72 files
This commit is contained in:
Théophile Gervreau-Mercier
2026-01-28 10:24:36 +01:00
parent 95f52d549e
commit 467aced734
81 changed files with 6304 additions and 785 deletions

108
apps/public/tests/README.md Normal file
View File

@@ -0,0 +1,108 @@
# Tests Directory
This directory contains all tests for the front-backend application.
## Structure
```
tests/
├── Fixtures/ # Test data and setup scripts
│ └── CreateTestDatabase.php
├── Integration/ # Integration tests (multiple components)
│ └── SearchTest.php
├── Security/ # Security-focused tests
│ └── SecurityTest.php
└── Unit/ # Unit tests (individual methods)
└── RateLimitTest.php
```
## Running Tests
### Run All Tests
```bash
php run-tests.php
```
### Run Individual Tests
```bash
# Setup test database first
php tests/Fixtures/CreateTestDatabase.php
# Run specific test
php tests/Integration/SearchTest.php
php tests/Security/SecurityTest.php
php tests/Unit/RateLimitTest.php
```
## Test Suites
### Fixtures
Test data setup and database initialization.
**CreateTestDatabase.php**
- Creates test.db with sample theses
- Populates with 6 sample records
- Includes authors, supervisors, keywords
### Integration Tests
Test multiple components working together.
**SearchTest.php**
- Tests full search functionality
- Tests filtering (year, orientation, AP, keywords)
- Tests pagination
- Tests combined filters
### Security Tests
Verify security measures are working.
**SecurityTest.php**
- Wildcard injection prevention
- Input length validation
- Year range validation
- SQL injection prevention
- Pagination limits
### Unit Tests
Test individual components in isolation.
**RateLimitTest.php**
- Rate limit enforcement
- Request tracking
- Reset time calculation
- Header generation
## Expected Results
All tests should pass:
```
✅ PASSED - Fixtures/CreateTestDatabase.php
✅ PASSED - Integration/SearchTest.php
✅ PASSED - Security/SecurityTest.php
✅ PASSED - Unit/RateLimitTest.php
```
## Deployment
**Tests are NOT deployed to production.**
The deployment configuration (`justfile`) excludes:
- `tests/` directory
- `*.db` files
- Cache directory
- Documentation files
## Future Migration to PHPUnit
This directory structure is compatible with PHPUnit. To migrate:
1. Install PHPUnit:
```bash
composer require --dev phpunit/phpunit
```
2. Convert test files to PHPUnit format
3. Add `phpunit.xml` configuration
4. Run with: `composer test`
See `TESTING_BEST_PRACTICES.md` for details.