AtlatestRepositorysigil-http3

sigil-http3 / tree / testtest-control.sgl

1(import (sigil test)
2 (sigil http3 error)
3 (sigil http3 control))
4
5(define (control-test-code thunk)
6 (guard (exn
7 ((h3-error? exn) (h3-error-code exn))
8 (else (raise exn)))
9 (thunk)
10 #f))
12(test-group "HTTP/3 peer control stream"
13 (test "fragmented SETTINGS is emitted once after its complete payload"
14 (let ((control (make-h3-control)))
15 (assert-equal '() (h3-control-input! control #u8(4) #f))
16 (assert-equal '() (h3-control-input! control #u8(2 8) #f))
17 (assert-false (h3-control-settings control))
18 (let ((events (h3-control-input! control #u8(1) #f)))
19 (assert-equal 1 (length events))
20 (assert-equal 4 (vector-ref (car events) 0)))
21 (assert-equal '((8 . 1)) (h3-control-settings control))))
23 (test "empty SETTINGS is distinct from missing SETTINGS"
24 (let ((control (make-h3-control)))
25 (h3-control-input! control #u8(4 0) #f)
26 (assert-equal '() (h3-control-settings control))
27 (assert-equal 1 (length (h3-control-input! control #u8(33 0) #f)))))
29 (test "the first control frame must be SETTINGS, including before grease"
30 (for-each
31 (lambda (wire)
32 (assert-equal #x10a
33 (control-test-code
34 (lambda () (h3-control-input! (make-h3-control) wire #f)))))
35 (list #u8(0 0) #u8(33 0) #u8(7 1 0))))
37 (test "a second SETTINGS and request frames are forbidden"
38 (for-each
39 (lambda (wire)
40 (let ((control (make-h3-control)))
41 (h3-control-input! control #u8(4 0) #f)
42 (assert-equal #x105
43 (control-test-code (lambda () (h3-control-input! control wire #f))))))
44 (list #u8(4 0) #u8(0 0) #u8(1 0) #u8(5 0))))
46 (test "control FIN always raises CLOSED_CRITICAL_STREAM"
47 (assert-equal #x104
48 (control-test-code
49 (lambda () (h3-control-input! (make-h3-control) #u8() #t)))))
51 (test "peer GOAWAY cannot increase and MAX_PUSH_ID cannot decrease"
52 (let ((control (make-h3-control)))
53 (h3-control-input! control #u8(4 0 7 1 9 7 1 7) #f)
54 (assert-equal #x108
55 (control-test-code (lambda () (h3-control-input! control #u8(7 1 8) #f)))))
56 (let ((control (make-h3-control)))
57 (h3-control-input! control #u8(4 0 13 1 1 13 1 2) #f)
58 (assert-equal #x108
59 (control-test-code (lambda () (h3-control-input! control #u8(13 1 1) #f))))))
61 (test "unknown frames after SETTINGS are ignored without losing framing"
62 (let ((control (make-h3-control)))
63 (h3-control-input! control #u8(4 0) #f)
64 (let ((events (h3-control-input! control #u8(33 2 99 100 7 1 0) #f)))
65 (assert-equal 2 (length events))
66 (assert-equal 7 (vector-ref (cadr events) 0)))))
68 (test "CANCEL_PUSH cannot refer to an unpromised push"
69 (let ((control (make-h3-control)))
70 (h3-control-input! control #u8(4 0) #f)
71 (assert-equal #x108
72 (control-test-code (lambda () (h3-control-input! control #u8(3 1 0) #f)))))))