| 1 |
# Rspamd Integration and Load Testing |
| 2 |
|
| 3 |
Comprehensive integration and load testing for Rspamd using Docker Compose. |
| 4 |
|
| 5 |
## Description |
| 6 |
|
| 7 |
This test creates a complete Rspamd environment with: |
| 8 |
|
| 9 |
- Scanner workers for processing emails (with encryption) |
| 10 |
- Controller worker for management |
| 11 |
- Proxy worker for proxying requests (with encryption) |
| 12 |
- Fuzzy storage with encryption |
| 13 |
- Redis for data storage |
| 14 |
- Bayes classifier |
| 15 |
|
| 16 |
The test performs the following steps: |
| 17 |
|
| 18 |
1. Downloads email corpus from a given URL (or uses local test emails) |
| 19 |
2. Trains Fuzzy storage on 10% of emails |
| 20 |
3. Trains Bayes classifier on 10% of emails (spam and ham) |
| 21 |
4. Scans the entire corpus |
| 22 |
5. Validates that detection works correctly (~10% detection rate) |
| 23 |
|
| 24 |
## Requirements |
| 25 |
|
| 26 |
- Docker and Docker Compose |
| 27 |
- Python 3.8+ |
| 28 |
- rspamadm (for key generation) |
| 29 |
|
| 30 |
## Features |
| 31 |
|
| 32 |
This test uses **AddressSanitizer (ASan)** to detect: |
| 33 |
|
| 34 |
- Memory leaks |
| 35 |
- Buffer overflows |
| 36 |
- Use-after-free errors |
| 37 |
- Other memory issues |
| 38 |
|
| 39 |
Docker image: `rspamd/rspamd:asan-latest` |
| 40 |
|
| 41 |
## Quick Start |
| 42 |
|
| 43 |
### 1. Generate encryption keys |
| 44 |
|
| 45 |
```bash |
| 46 |
cd test/integration |
| 47 |
./scripts/generate-keys.sh |
| 48 |
``` |
| 49 |
|
| 50 |
### 2. Start environment |
| 51 |
|
| 52 |
```bash |
| 53 |
docker compose up -d |
| 54 |
``` |
| 55 |
|
| 56 |
### 3. Check readiness |
| 57 |
|
| 58 |
```bash |
| 59 |
docker compose ps |
| 60 |
docker compose logs rspamd |
| 61 |
``` |
| 62 |
|
| 63 |
### 4. Run test |
| 64 |
|
| 65 |
```bash |
| 66 |
# With local corpus (uses test/functional/messages by default) |
| 67 |
./scripts/integration-test.sh |
| 68 |
|
| 69 |
# With rspamd-test-corpus (recommended) |
| 70 |
# Download and extract the corpus |
| 71 |
curl -L https://github.com/rspamd/rspamd-test-corpus/releases/latest/download/rspamd-test-corpus.zip -o corpus.zip |
| 72 |
unzip corpus.zip |
| 73 |
export CORPUS_DIR=$(pwd)/corpus/corpus |
| 74 |
./scripts/integration-test.sh |
| 75 |
|
| 76 |
# With local directory |
| 77 |
export CORPUS_DIR=/path/to/emails |
| 78 |
./scripts/integration-test.sh |
| 79 |
``` |
| 80 |
|
| 81 |
### 5. Check for memory leaks |
| 82 |
|
| 83 |
```bash |
| 84 |
make check-asan |
| 85 |
``` |
| 86 |
|
| 87 |
This script analyzes AddressSanitizer logs and reports any detected memory leaks. |
| 88 |
|
| 89 |
### 6. Stop |
| 90 |
|
| 91 |
```bash |
| 92 |
docker compose down |
| 93 |
``` |
| 94 |
|
| 95 |
## Test Parameters |
| 96 |
|
| 97 |
The test script uses environment variables for configuration: |
| 98 |
|
| 99 |
```bash |
| 100 |
# Configuration via environment variables |
| 101 |
export RSPAMD_HOST=localhost # Rspamd host |
| 102 |
export CONTROLLER_PORT=50002 # Controller port |
| 103 |
export PROXY_PORT=50004 # Proxy port |
| 104 |
export PASSWORD=q1 # API password |
| 105 |
export PARALLEL=10 # Parallel requests |
| 106 |
export TRAIN_RATIO=0.1 # Training ratio (10%) |
| 107 |
export TEST_PROXY=true # Test via proxy worker |
| 108 |
export CORPUS_DIR=/path/to/emails # Corpus directory |
| 109 |
|
| 110 |
./scripts/integration-test.sh |
| 111 |
``` |
| 112 |
|
| 113 |
## Project Structure |
| 114 |
|
| 115 |
``` |
| 116 |
test/integration/ |
| 117 |
├── docker-compose.yml # Docker Compose configuration |
| 118 |
├── configs/ # Rspamd configurations |
| 119 |
│ ├── worker-normal.inc # Scanner worker |
| 120 |
│ ├── worker-controller.inc # Controller worker |
| 121 |
│ ├── worker-proxy.inc # Proxy worker |
| 122 |
│ ├── worker-fuzzy.inc # Fuzzy storage worker |
| 123 |
│ ├── fuzzy_check.conf # fuzzy_check module |
| 124 |
│ ├── redis.conf # Redis settings |
| 125 |
│ ├── statistic.conf # Bayes classifier |
| 126 |
│ ├── lsan.supp # LeakSanitizer suppressions |
| 127 |
│ └── fuzzy-keys.conf # Encryption keys (generated) |
| 128 |
├── scripts/ |
| 129 |
│ ├── generate-keys.sh # Key generation |
| 130 |
│ ├── integration-test.sh # Test script |
| 131 |
│ └── check-asan-logs.sh # ASan log checker |
| 132 |
├── data/ # Data (corpus, results) |
| 133 |
└── README.md |
| 134 |
``` |
| 135 |
|
| 136 |
## Configuration |
| 137 |
|
| 138 |
### Ports |
| 139 |
|
| 140 |
- `50001` - Normal worker (scanning) |
| 141 |
- `50002` - Controller (API) |
| 142 |
- `50003` - Fuzzy storage |
| 143 |
- `50004` - Proxy worker |
| 144 |
|
| 145 |
### Environment Variables |
| 146 |
|
| 147 |
In `docker-compose.yml` you can configure: |
| 148 |
|
| 149 |
- `REDIS_ADDR` - Redis address |
| 150 |
- `REDIS_PORT` - Redis port |
| 151 |
- `ASAN_OPTIONS` - AddressSanitizer options |
| 152 |
- `LSAN_OPTIONS` - LeakSanitizer options |
| 153 |
|
| 154 |
### Encryption |
| 155 |
|
| 156 |
Fuzzy storage uses encryption. Keys are generated automatically when running `generate-keys.sh`. |
| 157 |
|
| 158 |
## Results |
| 159 |
|
| 160 |
Results are saved in `data/results.json` in the following format: |
| 161 |
|
| 162 |
```json |
| 163 |
[ |
| 164 |
{ |
| 165 |
"file": "message1.eml", |
| 166 |
"score": 5.2, |
| 167 |
"symbols": { |
| 168 |
"FUZZY_SPAM": 2.5, |
| 169 |
"BAYES_SPAM": 3.0 |
| 170 |
} |
| 171 |
}, |
| 172 |
... |
| 173 |
] |
| 174 |
``` |
| 175 |
|
| 176 |
## Debugging |
| 177 |
|
| 178 |
### Check logs |
| 179 |
|
| 180 |
```bash |
| 181 |
# All logs |
| 182 |
docker compose logs |
| 183 |
|
| 184 |
# Only Rspamd |
| 185 |
docker compose logs rspamd |
| 186 |
|
| 187 |
# Follow logs |
| 188 |
docker compose logs -f rspamd |
| 189 |
``` |
| 190 |
|
| 191 |
### Connect to container |
| 192 |
|
| 193 |
```bash |
| 194 |
docker compose exec rspamd /bin/sh |
| 195 |
``` |
| 196 |
|
| 197 |
### Check Rspamd operation |
| 198 |
|
| 199 |
```bash |
| 200 |
# Ping (Controller) |
| 201 |
curl http://localhost:50002/ping |
| 202 |
|
| 203 |
# Ping (Proxy) |
| 204 |
curl http://localhost:50004/ping |
| 205 |
|
| 206 |
# Statistics |
| 207 |
curl -H "Password: q1" http://localhost:50002/stat |
| 208 |
|
| 209 |
# Scan test email (via Controller) |
| 210 |
curl -H "Password: q1" --data-binary @test.eml http://localhost:50002/checkv2 |
| 211 |
|
| 212 |
# Scan via Proxy |
| 213 |
curl -H "Password: q1" --data-binary @test.eml http://localhost:50004/checkv2 |
| 214 |
``` |
| 215 |
|
| 216 |
### Check Fuzzy storage |
| 217 |
|
| 218 |
```bash |
| 219 |
# Fuzzy statistics |
| 220 |
curl -H "Password: q1" http://localhost:50002/fuzzystats |
| 221 |
``` |
| 222 |
|
| 223 |
### Test via Proxy |
| 224 |
|
| 225 |
```bash |
| 226 |
# Run test with proxy check |
| 227 |
export TEST_PROXY=true |
| 228 |
./scripts/integration-test.sh |
| 229 |
|
| 230 |
# Results will be saved in: |
| 231 |
# - data/scan_results.json (via controller) |
| 232 |
# - data/proxy_results.json (via proxy) |
| 233 |
``` |
| 234 |
|
| 235 |
## Email Corpus |
| 236 |
|
| 237 |
### Using rspamd-test-corpus |
| 238 |
|
| 239 |
The recommended way to run integration tests is with the [rspamd-test-corpus](https://github.com/rspamd/rspamd-test-corpus) repository. |
| 240 |
|
| 241 |
This corpus contains: |
| 242 |
- **~1000 base messages** from SpamAssassin public corpus |
| 243 |
- **Regression tests** from real bug reports |
| 244 |
- **Edge cases** for corner case testing |
| 245 |
|
| 246 |
Download the latest release: |
| 247 |
|
| 248 |
```bash |
| 249 |
curl -L https://github.com/rspamd/rspamd-test-corpus/releases/latest/download/rspamd-test-corpus.zip -o corpus.zip |
| 250 |
unzip corpus.zip |
| 251 |
export CORPUS_DIR=$(pwd)/corpus/corpus |
| 252 |
``` |
| 253 |
|
| 254 |
### Using Local Messages |
| 255 |
|
| 256 |
By default, the test uses `test/functional/messages` directory. However, these messages are often too small or synthetic for realistic testing. |
| 257 |
|
| 258 |
### Adding Regression Tests |
| 259 |
|
| 260 |
If you find a problematic email that causes a bug: |
| 261 |
|
| 262 |
1. Report the issue on GitHub |
| 263 |
2. Add the email to [rspamd-test-corpus](https://github.com/rspamd/rspamd-test-corpus) |
| 264 |
3. The corpus will be automatically used in CI tests |
| 265 |
|
| 266 |
## CI/CD |
| 267 |
|
| 268 |
See `.github/workflows/integration-test.yml` for automated runs in GitHub Actions. |
| 269 |
|
| 270 |
The CI automatically downloads the latest corpus from rspamd-test-corpus repository. |
| 271 |
|
| 272 |
## AddressSanitizer |
| 273 |
|
| 274 |
### View ASan logs |
| 275 |
|
| 276 |
```bash |
| 277 |
# Logs are saved in data/asan.log* |
| 278 |
cat data/asan.log* |
| 279 |
|
| 280 |
# Automatic check |
| 281 |
make check-asan |
| 282 |
``` |
| 283 |
|
| 284 |
### ASan Configuration |
| 285 |
|
| 286 |
In `docker-compose.yml` the following options are configured: |
| 287 |
|
| 288 |
``` |
| 289 |
ASAN_OPTIONS=detect_leaks=1:halt_on_error=0:abort_on_error=0:print_stats=1:log_path=/data/asan.log |
| 290 |
``` |
| 291 |
|
| 292 |
- `detect_leaks=1` - detect memory leaks |
| 293 |
- `halt_on_error=0` - don't stop on first error |
| 294 |
- `abort_on_error=0` - don't call abort() |
| 295 |
- `print_stats=1` - print statistics |
| 296 |
- `log_path=/data/asan.log` - log file path |
| 297 |
|
| 298 |
### Suppress False Positives |
| 299 |
|
| 300 |
Edit `configs/lsan.supp`: |
| 301 |
|
| 302 |
``` |
| 303 |
leak:function_name_to_suppress |
| 304 |
``` |
| 305 |
|
| 306 |
## Troubleshooting |
| 307 |
|
| 308 |
### Rspamd doesn't start |
| 309 |
|
| 310 |
1. Check that keys are generated: `ls configs/fuzzy-keys.conf` |
| 311 |
2. Check logs: `docker compose logs rspamd` |
| 312 |
3. Check ASan logs: `cat data/asan.log*` |
| 313 |
|
| 314 |
### Redis unavailable |
| 315 |
|
| 316 |
```bash |
| 317 |
docker compose exec redis redis-cli ping |
| 318 |
``` |
| 319 |
|
| 320 |
### Low detection rate |
| 321 |
|
| 322 |
- Increase corpus size |
| 323 |
- Verify training completed successfully |
| 324 |
- Check Rspamd logs |
| 325 |
|
| 326 |
## Performance |
| 327 |
|
| 328 |
For load testing you can: |
| 329 |
|
| 330 |
- Increase number of scanner workers in `configs/worker-normal.inc` |
| 331 |
- Increase corpus size |
| 332 |
- Run multiple parallel test instances |