File: README.md

package info (click to toggle)
rspamd 3.14.3-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 35,064 kB
  • sloc: ansic: 247,728; cpp: 107,741; javascript: 31,385; perl: 3,089; asm: 2,512; pascal: 1,625; python: 1,510; sh: 589; sql: 313; makefile: 195; xml: 74
file content (332 lines) | stat: -rw-r--r-- 7,592 bytes parent folder | download
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
# Rspamd Integration and Load Testing

Comprehensive integration and load testing for Rspamd using Docker Compose.

## Description

This test creates a complete Rspamd environment with:

- Scanner workers for processing emails (with encryption)
- Controller worker for management
- Proxy worker for proxying requests (with encryption)
- Fuzzy storage with encryption
- Redis for data storage
- Bayes classifier

The test performs the following steps:

1. Downloads email corpus from a given URL (or uses local test emails)
2. Trains Fuzzy storage on 10% of emails
3. Trains Bayes classifier on 10% of emails (spam and ham)
4. Scans the entire corpus
5. Validates that detection works correctly (~10% detection rate)

## Requirements

- Docker and Docker Compose
- Python 3.8+
- rspamadm (for key generation)

## Features

This test uses **AddressSanitizer (ASan)** to detect:

- Memory leaks
- Buffer overflows
- Use-after-free errors
- Other memory issues

Docker image: `rspamd/rspamd:asan-latest`

## Quick Start

### 1. Generate encryption keys

```bash
cd test/integration
./scripts/generate-keys.sh
```

### 2. Start environment

```bash
docker compose up -d
```

### 3. Check readiness

```bash
docker compose ps
docker compose logs rspamd
```

### 4. Run test

```bash
# With local corpus (uses test/functional/messages by default)
./scripts/integration-test.sh

# With rspamd-test-corpus (recommended)
# Download and extract the corpus
curl -L https://github.com/rspamd/rspamd-test-corpus/releases/latest/download/rspamd-test-corpus.zip -o corpus.zip
unzip corpus.zip
export CORPUS_DIR=$(pwd)/corpus/corpus
./scripts/integration-test.sh

# With local directory
export CORPUS_DIR=/path/to/emails
./scripts/integration-test.sh
```

### 5. Check for memory leaks

```bash
make check-asan
```

This script analyzes AddressSanitizer logs and reports any detected memory leaks.

### 6. Stop

```bash
docker compose down
```

## Test Parameters

The test script uses environment variables for configuration:

```bash
# Configuration via environment variables
export RSPAMD_HOST=localhost        # Rspamd host
export CONTROLLER_PORT=50002        # Controller port
export PROXY_PORT=50004             # Proxy port
export PASSWORD=q1                  # API password
export PARALLEL=10                  # Parallel requests
export TRAIN_RATIO=0.1              # Training ratio (10%)
export TEST_PROXY=true              # Test via proxy worker
export CORPUS_DIR=/path/to/emails   # Corpus directory

./scripts/integration-test.sh
```

## Project Structure

```
test/integration/
├── docker-compose.yml          # Docker Compose configuration
├── configs/                    # Rspamd configurations
│   ├── worker-normal.inc      # Scanner worker
│   ├── worker-controller.inc  # Controller worker
│   ├── worker-proxy.inc       # Proxy worker
│   ├── worker-fuzzy.inc       # Fuzzy storage worker
│   ├── fuzzy_check.conf       # fuzzy_check module
│   ├── redis.conf             # Redis settings
│   ├── statistic.conf         # Bayes classifier
│   ├── lsan.supp              # LeakSanitizer suppressions
│   └── fuzzy-keys.conf        # Encryption keys (generated)
├── scripts/
│   ├── generate-keys.sh       # Key generation
│   ├── integration-test.sh    # Test script
│   └── check-asan-logs.sh     # ASan log checker
├── data/                       # Data (corpus, results)
└── README.md
```

## Configuration

### Ports

- `50001` - Normal worker (scanning)
- `50002` - Controller (API)
- `50003` - Fuzzy storage
- `50004` - Proxy worker

### Environment Variables

In `docker-compose.yml` you can configure:

- `REDIS_ADDR` - Redis address
- `REDIS_PORT` - Redis port
- `ASAN_OPTIONS` - AddressSanitizer options
- `LSAN_OPTIONS` - LeakSanitizer options

### Encryption

Fuzzy storage uses encryption. Keys are generated automatically when running `generate-keys.sh`.

## Results

Results are saved in `data/results.json` in the following format:

```json
[
  {
    "file": "message1.eml",
    "score": 5.2,
    "symbols": {
      "FUZZY_SPAM": 2.5,
      "BAYES_SPAM": 3.0
    }
  },
  ...
]
```

## Debugging

### Check logs

```bash
# All logs
docker compose logs

# Only Rspamd
docker compose logs rspamd

# Follow logs
docker compose logs -f rspamd
```

### Connect to container

```bash
docker compose exec rspamd /bin/sh
```

### Check Rspamd operation

```bash
# Ping (Controller)
curl http://localhost:50002/ping

# Ping (Proxy)
curl http://localhost:50004/ping

# Statistics
curl -H "Password: q1" http://localhost:50002/stat

# Scan test email (via Controller)
curl -H "Password: q1" --data-binary @test.eml http://localhost:50002/checkv2

# Scan via Proxy
curl -H "Password: q1" --data-binary @test.eml http://localhost:50004/checkv2
```

### Check Fuzzy storage

```bash
# Fuzzy statistics
curl -H "Password: q1" http://localhost:50002/fuzzystats
```

### Test via Proxy

```bash
# Run test with proxy check
export TEST_PROXY=true
./scripts/integration-test.sh

# Results will be saved in:
# - data/scan_results.json (via controller)
# - data/proxy_results.json (via proxy)
```

## Email Corpus

### Using rspamd-test-corpus

The recommended way to run integration tests is with the [rspamd-test-corpus](https://github.com/rspamd/rspamd-test-corpus) repository.

This corpus contains:
- **~1000 base messages** from SpamAssassin public corpus
- **Regression tests** from real bug reports
- **Edge cases** for corner case testing

Download the latest release:

```bash
curl -L https://github.com/rspamd/rspamd-test-corpus/releases/latest/download/rspamd-test-corpus.zip -o corpus.zip
unzip corpus.zip
export CORPUS_DIR=$(pwd)/corpus/corpus
```

### Using Local Messages

By default, the test uses `test/functional/messages` directory. However, these messages are often too small or synthetic for realistic testing.

### Adding Regression Tests

If you find a problematic email that causes a bug:

1. Report the issue on GitHub
2. Add the email to [rspamd-test-corpus](https://github.com/rspamd/rspamd-test-corpus)
3. The corpus will be automatically used in CI tests

## CI/CD

See `.github/workflows/integration-test.yml` for automated runs in GitHub Actions.

The CI automatically downloads the latest corpus from rspamd-test-corpus repository.

## AddressSanitizer

### View ASan logs

```bash
# Logs are saved in data/asan.log*
cat data/asan.log*

# Automatic check
make check-asan
```

### ASan Configuration

In `docker-compose.yml` the following options are configured:

```
ASAN_OPTIONS=detect_leaks=1:halt_on_error=0:abort_on_error=0:print_stats=1:log_path=/data/asan.log
```

- `detect_leaks=1` - detect memory leaks
- `halt_on_error=0` - don't stop on first error
- `abort_on_error=0` - don't call abort()
- `print_stats=1` - print statistics
- `log_path=/data/asan.log` - log file path

### Suppress False Positives

Edit `configs/lsan.supp`:

```
leak:function_name_to_suppress
```

## Troubleshooting

### Rspamd doesn't start

1. Check that keys are generated: `ls configs/fuzzy-keys.conf`
2. Check logs: `docker compose logs rspamd`
3. Check ASan logs: `cat data/asan.log*`

### Redis unavailable

```bash
docker compose exec redis redis-cli ping
```

### Low detection rate

- Increase corpus size
- Verify training completed successfully
- Check Rspamd logs

## Performance

For load testing you can:

- Increase number of scanner workers in `configs/worker-normal.inc`
- Increase corpus size
- Run multiple parallel test instances