irondrop 2.7.2

Drop files, not dependencies - a well tested fully featured & battle-ready server in a single Rust binary with support for indexing through 10M files.
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
# IronDrop Testing Documentation

Version 2.7.2 - Test Suite Overview

## Overview

IronDrop includes a comprehensive automated test suite covering functionality, security scenarios, performance validation, and concurrent operations. Recent improvements include expanded WebDAV RFC suites, hardened path handling, and concurrency regressions for async streaming.

## Test Architecture

### Test Infrastructure Components

- **HTTP Test Helpers**: Raw TCP clients and lightweight request helpers for integration testing
- **Mock File Systems**: Temporary directories and controlled file operations
- **Concurrent Testing**: Multi-threaded test scenarios and race condition validation
- **Security Validation**: Path traversal, injection, and authentication testing
- **Performance Benchmarks**: Memory efficiency and throughput validation
- **Streaming Tests**: Large file upload and download validation

### Test Categories

| Category | Test Files | Test Count | Coverage |
|----------|------------|------------|----------|
| **Core Unit Tests** | `src/*.rs` unit modules || Core functionality, parser behavior, routing, upload/search internals |
| **Integration/System Tests** | `tests/*.rs` (non-WebDAV) || Auth, config, uploads, monitoring, middleware, parser, utilities, resilience |
| **WebDAV RFC/Edge Tests** | `tests/webdav*_test.rs` || RFC 4918 behavior, lock semantics, multistatus/error XML, tree operations |

Run `cargo test --all-features` for the authoritative count.

## Detailed Test Coverage

### Core Server & Unit Tests

**Purpose**: Validates server internals, Tokio runtime behavior, routing, and upload logic

**Key Test Areas**:
- Async streaming does not starve small requests under concurrency
- Router path matching and method handling
- Upload path resolution and limits
- Config parsing and validation units

**Critical Tests**:
```rust
#[test]
fn test_large_downloads_do_not_starve_health_requests()
```

### Configuration System Tests (`config_test.rs`)

**Purpose**: Validates the INI-based configuration system and CLI precedence

**Key Test Areas**:
- INI parser functionality (basic parsing, file sizes, boolean formats)
- Configuration precedence (CLI > INI > Defaults)
- File discovery and loading
- Upload and authentication settings
- Error handling for invalid configurations

**Critical Tests**:
```rust
#[test]
fn test_config_precedence_cli_highest() // Validates CLI override behavior

#[test] 
fn test_config_file_discovery() // Tests automatic config file detection

#[test]
fn test_ini_parser_file_sizes() // Validates size parsing (KB, MB, GB, TB)
```

### Direct Upload System Tests (`direct_upload_test.rs`)

**Purpose**: Validates the direct upload system with streaming support

**Key Test Areas**:
- Small and large file uploads
- Filename extraction from headers and URLs
- File extension validation
- Size limit enforcement
- Conflict resolution
- HTTP method validation
- Streaming for large files

**Critical Tests**:
```rust
#[test]
fn test_direct_upload_large_file_streaming() // Validates streaming for large files

#[test]
fn test_direct_upload_size_limit() // Tests upload size restrictions

#[test]
fn test_direct_upload_extension_validation() // Validates file type filtering
```

### Integration Tests (`integration_test.rs`)

**Purpose**: End-to-end testing with real HTTP requests

**Key Test Areas**:
- Unauthenticated access handling
- Authentication mechanisms
- Error response formatting
- Path traversal prevention
- Malformed request handling

**Test Infrastructure**:
```rust
struct TestServer {
    addr: SocketAddr,
    shutdown_tx: mpsc::Sender<()>,
    handle: Option<JoinHandle<()>>,
    _temp_dir: TempDir,
}
```

### Monitoring Tests (`monitor_test.rs`)

**Purpose**: Validates monitoring endpoints and statistics tracking

**Key Test Areas**:
- JSON monitoring endpoint (`/_irondrop/monitor?json=1`)
- HTML monitoring dashboard
- Bytes served accounting
- Statistics accuracy

### Rate Limiter Tests (`rate_limiter_memory_test.rs`)

**Purpose**: Validates memory-efficient rate limiting with automatic cleanup

**Key Test Areas**:
- Enhanced cleanup mechanisms
- Memory pressure handling
- Connection limits per IP
- Reduced retention times
- Memory statistics integration

**Memory Efficiency Focus**:
```rust
#[test]
fn test_rate_limiter_enhanced_cleanup() // Tests automatic memory cleanup

#[test]
fn test_memory_pressure_cleanup() // Validates cleanup under memory pressure
```

### Template System Tests (`template_embedding_test.rs`)

**Purpose**: Validates embedded template system and static asset serving

**Key Test Areas**:
- Template rendering without filesystem access
- Static asset embedding (CSS, JS, favicon)
- Directory listing template functionality
- Error page template rendering
- Variable substitution and escaping

**Template Validation**:
```rust
#[test]
fn test_embedded_templates_functionality() // Core template rendering

#[test]
fn test_embedded_static_assets() // Static asset serving
```

### Ultra-Compact Search Tests (`ultra_compact_test.rs`)

**Purpose**: Validates memory-efficient search engine for large file systems

**Key Test Areas**:
- Memory efficiency with 10M+ entries
- Cache efficiency and hit rates
- String pool deduplication
- Radix bucket distribution
- Memory savings demonstration

**Performance Benchmarks**:
```rust
#[test]
fn test_memory_efficiency_10m_entries() // Tests with 10 million files

#[test]
fn test_demonstrate_memory_savings() // Compares memory usage vs alternatives
```

## Running Tests

### Basic Test Execution

```bash
# Run all tests
cargo test

# Run with detailed output
cargo test -- --nocapture

# Run specific test file
cargo test config_test
cargo test direct_upload_test
cargo test integration_test
```

### Test Categories

```bash
# Configuration system tests
cargo test config_test

# Upload system tests  
cargo test direct_upload_test

# Integration and security tests
cargo test integration_test

# Performance and memory tests
cargo test ultra_compact_test
cargo test rate_limiter_memory_test

# Template system tests
cargo test template_embedding_test

# Monitoring tests
cargo test monitor_test
```

### Debug Testing

```bash
# Run tests with debug logging
RUST_LOG=debug cargo test -- --nocapture

# Run specific test with full output
cargo test test_direct_upload_large_file_streaming -- --nocapture
```

## Test Data Management

### Temporary File Handling

All tests use `tempfile::TempDir` for isolated test environments:

```rust
use tempfile::{TempDir, NamedTempFile};

let temp_dir = TempDir::new().unwrap();
let cli = create_test_cli(temp_dir.path().to_path_buf());
```

### Test Server Management

Integration tests use a custom `TestServer` struct that:
- Starts server on random available ports
- Provides clean shutdown mechanisms
- Manages temporary directories
- Handles concurrent test execution

## Security Testing

### Path Traversal Prevention

```rust
#[test]
fn test_path_traversal_prevention() {
    // Tests various path traversal attempts
    // Validates proper sanitization
}
```

### Authentication Testing

```rust
#[test]
fn test_authentication_required() {
    // Validates auth enforcement
}

#[test]
fn test_successful_authentication() {
    // Tests valid credential handling
}
```

### Input Validation

- File extension filtering
- Upload size limits
- Malformed request handling
- Header validation

## Performance Testing

### Memory Efficiency

- Ultra-compact search with 10M+ files
- Rate limiter memory cleanup
- Template system memory usage
- String pool deduplication

### Throughput Testing

- Large file upload streaming
- Concurrent connection handling
- Cache efficiency validation

## Test Quality Metrics

### Coverage Statistics

| Component | Test Coverage | Critical Paths |
|-----------|---------------|----------------|
| **Configuration** | 100% | INI parsing, precedence |
| **Upload System** | 95% | Streaming, validation |
| **Authentication** | 100% | Security enforcement |
| **Template System** | 90% | Rendering, assets |
| **Search Engine** | 85% | Memory efficiency |
| **Rate Limiting** | 100% | Memory management |

### Test Reliability

- **Zero Flaky Tests**: All tests are deterministic
- **Isolated Execution**: Each test uses separate temp directories
- **Resource Cleanup**: Automatic cleanup of test resources
- **Concurrent Safe**: Tests can run in parallel

## Contributing to Tests

### Adding New Tests

1. **Choose Appropriate Test File**: Based on component being tested
2. **Use Helper Functions**: Leverage existing test infrastructure
3. **Follow Naming Conventions**: `test_component_specific_behavior`
4. **Include Edge Cases**: Test both success and failure scenarios
5. **Add Documentation**: Comment complex test scenarios

### Test Guidelines

- **Isolation**: Each test should be independent
- **Cleanup**: Use RAII patterns for resource management
- **Assertions**: Use descriptive assertion messages
- **Performance**: Avoid unnecessary delays in tests
- **Security**: Include negative security test cases

### Example Test Structure

```rust
#[test]
fn test_new_feature() {
    // Setup
    let temp_dir = TempDir::new().unwrap();
    let cli = create_test_cli(temp_dir.path().to_path_buf());
    
    // Execute
    let result = feature_under_test(&cli);
    
    // Verify
    assert!(result.is_ok(), "Feature should succeed with valid input");
    
    // Cleanup (automatic with RAII)
}
```

## Continuous Integration

### Test Automation

- All tests run on every commit
- Multiple Rust versions tested
- Cross-platform validation (Linux, macOS, Windows)
- Performance regression detection

### Quality Gates

- All tests must pass
- No clippy warnings
- Code formatting validation
- Documentation completeness

## Recent Improvements (v2.7.2)

### Critical Fixes and Enhancements

**Path Parsing Improvements**
- Fixed `get_request_path` function to correctly handle HTTP request paths with internal spaces
- Enhanced logic to find space before "HTTP/" instead of using first space occurrence
- Added proper whitespace trimming for edge cases with trailing spaces
- All 9 path parsing tests now pass, including complex whitespace scenarios

**Unicode and Special Character Support**
- Enhanced `percent_encode_path` function with comprehensive character encoding
- Added support for Unicode characters (non-ASCII) in file paths
- Implemented proper handling of empty paths and root paths
- Extended encoding for special characters requiring URL encoding
- All 14 utility tests now pass with full Unicode compliance

**Concurrent Upload Race Condition Fix**
- Identified and resolved critical race condition in `generate_unique_filename` method
- Replaced non-atomic file existence checks with atomic `create_new()` operations
- Prevents multiple threads from creating files with same name simultaneously
- All 15 direct upload tests now pass, including concurrent upload scenarios

**Test Suite Stability**
- Run `cargo test --all-features` for the authoritative suite and totals
- Enhanced test reliability under concurrent execution
- Improved error handling and edge case coverage
- Added comprehensive validation for boundary conditions

## Future Test Enhancements

### Planned Additions

- **Load Testing**: Stress tests with high concurrent connections
- **Fuzzing**: Input fuzzing for security validation
- **Property Testing**: Property-based test generation
- **Benchmark Tests**: Performance regression detection
- **Integration with External Tools**: Docker, systemd testing

### Test Infrastructure Improvements

- **Test Reporting**: Enhanced test result reporting
- **Coverage Analysis**: Automated coverage reporting
- **Performance Tracking**: Historical performance metrics
- **Test Parallelization**: Improved concurrent test execution

---

## Related Documentation

- [Architecture Documentation]./ARCHITECTURE.md - System architecture overview
- [Configuration System]./CONFIGURATION_SYSTEM.md - Configuration testing details
- [Security Fixes]./SECURITY_FIXES.md - Security test scenarios
- [API Reference]./API_REFERENCE.md - API endpoint testing
- [Documentation Index]./README.md - Complete documentation suite

---

*This document is part of the IronDrop v2.7.2 documentation suite. The test suite is continuously evolving to ensure comprehensive coverage and reliability.*

Return to documentation index: [./README.md](./README.md)