parlov 0.7.0

HTTP oracle detection tool — systematic probing for RFC-compliant information leakage.
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
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
//! Integration tests for RFC 9110 §13 cache-probing GET handlers.
//!
//! Each test spawns an isolated server and validates the differential
//! between existing (known) and nonexistent resource IDs when
//! conditional, range, or negotiation headers are present.

#![deny(clippy::all)]

mod fixtures {
    pub mod get_server;
}

use fixtures::get_server::spawn;

// ========================================================================
// /cp/conditional/{id} — RFC 9110 §13.2 evaluation chain
// ========================================================================

// --- baseline: no conditional headers ---

#[tokio::test]
async fn conditional_no_headers_existing_returns_200() {
    let addr = spawn().await;
    let resp = reqwest::get(format!("http://{addr}/cp/conditional/42"))
        .await
        .expect("request failed");
    assert_eq!(resp.status(), 200);
}

#[tokio::test]
async fn conditional_no_headers_nonexistent_returns_404() {
    let addr = spawn().await;
    let resp = reqwest::get(format!("http://{addr}/cp/conditional/999"))
        .await
        .expect("request failed");
    assert_eq!(resp.status(), 404);
}

#[tokio::test]
async fn conditional_200_includes_etag_and_last_modified() {
    let addr = spawn().await;
    let resp = reqwest::get(format!("http://{addr}/cp/conditional/42"))
        .await
        .expect("request failed");
    assert_eq!(resp.status(), 200);
    assert_eq!(resp.headers()["etag"], "\"known-etag-42\"");
    assert_eq!(
        resp.headers()["last-modified"],
        "Wed, 01 Jan 2025 00:00:00 GMT"
    );
    assert_eq!(resp.headers()["content-type"], "application/json");
}

// --- If-None-Match ---

#[tokio::test]
async fn conditional_if_none_match_star_existing_returns_304() {
    let addr = spawn().await;
    let client = reqwest::Client::new();
    let resp = client
        .get(format!("http://{addr}/cp/conditional/42"))
        .header("If-None-Match", "*")
        .send()
        .await
        .expect("request failed");
    assert_eq!(resp.status(), 304);
}

#[tokio::test]
async fn conditional_if_none_match_star_nonexistent_returns_404() {
    let addr = spawn().await;
    let client = reqwest::Client::new();
    let resp = client
        .get(format!("http://{addr}/cp/conditional/999"))
        .header("If-None-Match", "*")
        .send()
        .await
        .expect("request failed");
    assert_eq!(resp.status(), 404);
}

#[tokio::test]
async fn conditional_if_none_match_matching_etag_returns_304() {
    let addr = spawn().await;
    let client = reqwest::Client::new();
    let resp = client
        .get(format!("http://{addr}/cp/conditional/42"))
        .header("If-None-Match", "\"known-etag-42\"")
        .send()
        .await
        .expect("request failed");
    assert_eq!(resp.status(), 304);
}

#[tokio::test]
async fn conditional_if_none_match_nonmatching_etag_returns_200() {
    let addr = spawn().await;
    let client = reqwest::Client::new();
    let resp = client
        .get(format!("http://{addr}/cp/conditional/42"))
        .header("If-None-Match", "\"wrong-etag\"")
        .send()
        .await
        .expect("request failed");
    assert_eq!(resp.status(), 200);
}

#[tokio::test]
async fn conditional_if_none_match_list_with_match_returns_304() {
    let addr = spawn().await;
    let client = reqwest::Client::new();
    let resp = client
        .get(format!("http://{addr}/cp/conditional/42"))
        .header("If-None-Match", "\"other\", \"known-etag-42\", \"another\"")
        .send()
        .await
        .expect("request failed");
    assert_eq!(resp.status(), 304);
}

// --- If-Match ---

#[tokio::test]
async fn conditional_if_match_star_existing_returns_200() {
    let addr = spawn().await;
    let client = reqwest::Client::new();
    let resp = client
        .get(format!("http://{addr}/cp/conditional/42"))
        .header("If-Match", "*")
        .send()
        .await
        .expect("request failed");
    assert_eq!(resp.status(), 200);
}

#[tokio::test]
async fn conditional_if_match_matching_etag_returns_200() {
    let addr = spawn().await;
    let client = reqwest::Client::new();
    let resp = client
        .get(format!("http://{addr}/cp/conditional/42"))
        .header("If-Match", "\"known-etag-42\"")
        .send()
        .await
        .expect("request failed");
    assert_eq!(resp.status(), 200);
}

#[tokio::test]
async fn conditional_if_match_nonmatching_etag_returns_412() {
    let addr = spawn().await;
    let client = reqwest::Client::new();
    let resp = client
        .get(format!("http://{addr}/cp/conditional/42"))
        .header("If-Match", "\"wrong-etag\"")
        .send()
        .await
        .expect("request failed");
    assert_eq!(resp.status(), 412);
}

#[tokio::test]
async fn conditional_if_match_nonmatching_nonexistent_returns_404() {
    let addr = spawn().await;
    let client = reqwest::Client::new();
    let resp = client
        .get(format!("http://{addr}/cp/conditional/999"))
        .header("If-Match", "\"wrong-etag\"")
        .send()
        .await
        .expect("request failed");
    assert_eq!(resp.status(), 404);
}

// --- If-Unmodified-Since ---

#[tokio::test]
async fn conditional_if_unmodified_since_future_returns_200() {
    let addr = spawn().await;
    let client = reqwest::Client::new();
    // Date after Last-Modified → resource not modified since → pass
    let resp = client
        .get(format!("http://{addr}/cp/conditional/42"))
        .header("If-Unmodified-Since", "Sun, 01 Jun 2025 00:00:00 GMT")
        .send()
        .await
        .expect("request failed");
    assert_eq!(resp.status(), 200);
}

#[tokio::test]
async fn conditional_if_unmodified_since_past_returns_412() {
    let addr = spawn().await;
    let client = reqwest::Client::new();
    // Date before Last-Modified → resource WAS modified since → 412
    let resp = client
        .get(format!("http://{addr}/cp/conditional/42"))
        .header("If-Unmodified-Since", "Mon, 01 Jan 2024 00:00:00 GMT")
        .send()
        .await
        .expect("request failed");
    assert_eq!(resp.status(), 412);
}

#[tokio::test]
async fn conditional_if_unmodified_since_skipped_when_if_match_present() {
    let addr = spawn().await;
    let client = reqwest::Client::new();
    // If-Match passes (star) → If-Unmodified-Since is skipped per §13.2 step 2
    let resp = client
        .get(format!("http://{addr}/cp/conditional/42"))
        .header("If-Match", "*")
        .header("If-Unmodified-Since", "Mon, 01 Jan 2024 00:00:00 GMT")
        .send()
        .await
        .expect("request failed");
    assert_eq!(resp.status(), 200);
}

// --- If-Modified-Since ---

#[tokio::test]
async fn conditional_if_modified_since_past_returns_200() {
    let addr = spawn().await;
    let client = reqwest::Client::new();
    // Date before Last-Modified → resource WAS modified since → 200
    let resp = client
        .get(format!("http://{addr}/cp/conditional/42"))
        .header("If-Modified-Since", "Mon, 01 Jan 2024 00:00:00 GMT")
        .send()
        .await
        .expect("request failed");
    assert_eq!(resp.status(), 200);
}

#[tokio::test]
async fn conditional_if_modified_since_future_returns_304() {
    let addr = spawn().await;
    let client = reqwest::Client::new();
    // Date after Last-Modified → resource NOT modified since → 304
    let resp = client
        .get(format!("http://{addr}/cp/conditional/42"))
        .header("If-Modified-Since", "Sun, 01 Jun 2025 00:00:00 GMT")
        .send()
        .await
        .expect("request failed");
    assert_eq!(resp.status(), 304);
}

#[tokio::test]
async fn conditional_if_modified_since_skipped_when_if_none_match_present() {
    let addr = spawn().await;
    let client = reqwest::Client::new();
    // If-None-Match fails (no match) → If-Modified-Since is skipped per §13.2 step 4
    let resp = client
        .get(format!("http://{addr}/cp/conditional/42"))
        .header("If-None-Match", "\"wrong-etag\"")
        .header("If-Modified-Since", "Sun, 01 Jun 2025 00:00:00 GMT")
        .send()
        .await
        .expect("request failed");
    // If-None-Match didn't match → condition passes → If-Modified-Since skipped → 200
    assert_eq!(resp.status(), 200);
}

// --- evaluation order: If-Match before If-None-Match ---

#[tokio::test]
async fn conditional_if_match_fails_before_if_none_match() {
    let addr = spawn().await;
    let client = reqwest::Client::new();
    // If-Match fails → 412, even though If-None-Match would succeed
    let resp = client
        .get(format!("http://{addr}/cp/conditional/42"))
        .header("If-Match", "\"wrong-etag\"")
        .header("If-None-Match", "\"known-etag-42\"")
        .send()
        .await
        .expect("request failed");
    assert_eq!(resp.status(), 412);
}

// ========================================================================
// /cp/range/{id} — Range evaluation
// ========================================================================

#[tokio::test]
async fn range_no_header_existing_returns_200_with_accept_ranges() {
    let addr = spawn().await;
    let resp = reqwest::get(format!("http://{addr}/cp/range/42"))
        .await
        .expect("request failed");
    assert_eq!(resp.status(), 200);
    assert_eq!(resp.headers()["accept-ranges"], "bytes");
}

#[tokio::test]
async fn range_no_header_nonexistent_returns_404() {
    let addr = spawn().await;
    let resp = reqwest::get(format!("http://{addr}/cp/range/999"))
        .await
        .expect("request failed");
    assert_eq!(resp.status(), 404);
}

#[tokio::test]
async fn range_valid_byte_range_returns_206() {
    let addr = spawn().await;
    let client = reqwest::Client::new();
    let resp = client
        .get(format!("http://{addr}/cp/range/42"))
        .header("Range", "bytes=0-4")
        .send()
        .await
        .expect("request failed");
    assert_eq!(resp.status(), 206);
    assert!(
        resp.headers()["content-range"]
            .to_str()
            .unwrap()
            .starts_with("bytes 0-4/")
    );
    let body = resp.text().await.expect("body read failed");
    assert_eq!(body.len(), 5); // bytes 0 through 4 inclusive
}

#[tokio::test]
async fn range_unsatisfiable_returns_416() {
    let addr = spawn().await;
    let client = reqwest::Client::new();
    let resp = client
        .get(format!("http://{addr}/cp/range/42"))
        .header("Range", "bytes=9999-10000")
        .send()
        .await
        .expect("request failed");
    assert_eq!(resp.status(), 416);
    assert!(
        resp.headers()["content-range"]
            .to_str()
            .unwrap()
            .starts_with("bytes */")
    );
}

#[tokio::test]
async fn range_valid_range_nonexistent_returns_404() {
    let addr = spawn().await;
    let client = reqwest::Client::new();
    let resp = client
        .get(format!("http://{addr}/cp/range/999"))
        .header("Range", "bytes=0-4")
        .send()
        .await
        .expect("request failed");
    assert_eq!(resp.status(), 404);
}

#[tokio::test]
async fn range_suffix_returns_206() {
    let addr = spawn().await;
    let client = reqwest::Client::new();
    let resp = client
        .get(format!("http://{addr}/cp/range/42"))
        .header("Range", "bytes=-5")
        .send()
        .await
        .expect("request failed");
    assert_eq!(resp.status(), 206);
    let body = resp.text().await.expect("body read failed");
    assert_eq!(body.len(), 5);
}

#[tokio::test]
async fn range_open_ended_returns_206() {
    let addr = spawn().await;
    let client = reqwest::Client::new();
    // bytes=0- means from byte 0 to end
    let resp = client
        .get(format!("http://{addr}/cp/range/42"))
        .header("Range", "bytes=0-")
        .send()
        .await
        .expect("request failed");
    assert_eq!(resp.status(), 206);
}

// --- If-Range + Range ---

#[tokio::test]
async fn range_if_range_matching_etag_returns_206() {
    let addr = spawn().await;
    let client = reqwest::Client::new();
    let resp = client
        .get(format!("http://{addr}/cp/range/42"))
        .header("Range", "bytes=0-4")
        .header("If-Range", "\"known-etag-42\"")
        .send()
        .await
        .expect("request failed");
    assert_eq!(resp.status(), 206);
}

#[tokio::test]
async fn range_if_range_nonmatching_etag_returns_200() {
    let addr = spawn().await;
    let client = reqwest::Client::new();
    let resp = client
        .get(format!("http://{addr}/cp/range/42"))
        .header("Range", "bytes=0-4")
        .header("If-Range", "\"stale-etag\"")
        .send()
        .await
        .expect("request failed");
    assert_eq!(resp.status(), 200);
}

#[tokio::test]
async fn range_if_range_nonexistent_returns_404() {
    let addr = spawn().await;
    let client = reqwest::Client::new();
    let resp = client
        .get(format!("http://{addr}/cp/range/999"))
        .header("Range", "bytes=0-4")
        .header("If-Range", "\"known-etag-999\"")
        .send()
        .await
        .expect("request failed");
    assert_eq!(resp.status(), 404);
}

#[tokio::test]
async fn range_if_range_without_range_ignored() {
    let addr = spawn().await;
    let client = reqwest::Client::new();
    // If-Range without Range → ignored, returns 200 with full body
    let resp = client
        .get(format!("http://{addr}/cp/range/42"))
        .header("If-Range", "\"known-etag-42\"")
        .send()
        .await
        .expect("request failed");
    assert_eq!(resp.status(), 200);
}

// ========================================================================
// /cp/negotiated/{id} — Content negotiation
// ========================================================================

#[tokio::test]
async fn negotiated_json_accept_existing_returns_200() {
    let addr = spawn().await;
    let client = reqwest::Client::new();
    let resp = client
        .get(format!("http://{addr}/cp/negotiated/42"))
        .header("Accept", "application/json")
        .send()
        .await
        .expect("request failed");
    assert_eq!(resp.status(), 200);
    assert_eq!(resp.headers()["content-type"], "application/json");
}

#[tokio::test]
async fn negotiated_no_accept_header_returns_200() {
    let addr = spawn().await;
    let resp = reqwest::get(format!("http://{addr}/cp/negotiated/42"))
        .await
        .expect("request failed");
    // No Accept header → server may return any type → 200
    assert_eq!(resp.status(), 200);
}

#[tokio::test]
async fn negotiated_xml_only_returns_406() {
    let addr = spawn().await;
    let client = reqwest::Client::new();
    let resp = client
        .get(format!("http://{addr}/cp/negotiated/42"))
        .header("Accept", "application/xml")
        .send()
        .await
        .expect("request failed");
    assert_eq!(resp.status(), 406);
}

#[tokio::test]
async fn negotiated_nonexistent_returns_404() {
    let addr = spawn().await;
    let client = reqwest::Client::new();
    let resp = client
        .get(format!("http://{addr}/cp/negotiated/999"))
        .header("Accept", "application/json")
        .send()
        .await
        .expect("request failed");
    assert_eq!(resp.status(), 404);
}

#[tokio::test]
async fn negotiated_wildcard_accept_returns_200() {
    let addr = spawn().await;
    let client = reqwest::Client::new();
    let resp = client
        .get(format!("http://{addr}/cp/negotiated/42"))
        .header("Accept", "*/*")
        .send()
        .await
        .expect("request failed");
    assert_eq!(resp.status(), 200);
}

// ========================================================================
// /cp/normalized/{id} — Hardened negative case
// ========================================================================

#[tokio::test]
async fn normalized_existing_id_returns_404() {
    let addr = spawn().await;
    let resp = reqwest::get(format!("http://{addr}/cp/normalized/42"))
        .await
        .expect("request failed");
    assert_eq!(resp.status(), 404);
}

#[tokio::test]
async fn normalized_nonexistent_id_returns_404() {
    let addr = spawn().await;
    let resp = reqwest::get(format!("http://{addr}/cp/normalized/999"))
        .await
        .expect("request failed");
    assert_eq!(resp.status(), 404);
}

#[tokio::test]
async fn normalized_with_conditional_headers_still_returns_404() {
    let addr = spawn().await;
    let client = reqwest::Client::new();
    let resp = client
        .get(format!("http://{addr}/cp/normalized/42"))
        .header("If-None-Match", "*")
        .send()
        .await
        .expect("request failed");
    assert_eq!(resp.status(), 404);
}