AtlatestRepositorysigil-http3
sigil-http3 / tree / testtest-frame.sgl
1
(import (sigil test)2
(sigil quic wire)3
(sigil quic bytes)4
(sigil http3 error)5
(sigil http3 frame))7
(define (failure-code thunk)8
(guard (exn9
((h3-error? exn) (h3-error-code exn))10
(else (raise exn)))11
(thunk)12
#f))14
(test-group "HTTP/3 wire framing"15
(test "HEADERS envelope has independently specified bytes"16
(assert-equal #u8(1 3 0 0 217)17
(encode-h3-frame 1 #u8(0 0 217))))19
(test "every truncated prefix waits for more bytes"20
(let ((wire #u8(0 64 64)))21
(do ((end 0 (+ end 1))) ((= end 3))22
(assert-false (decode-h3-frame (bytevector-copy wire 0 end))))23
(assert-false (decode-h3-frame wire))))25
(test "a complete DATA frame leaves a following frame untouched"26
(let ((frame (decode-h3-frame #u8(0 2 10 20 1 0))))27
(assert-equal 0 (vector-ref frame 0))28
(assert-equal #u8(10 20) (vector-ref frame 1))29
(assert-equal 4 (vector-ref frame 2))30
(assert-equal #u8() (vector-ref (decode-h3-frame #u8(0 2 10 20 1 0) 4) 1))))32
(test "unknown extension frame types remain parseable"33
(let ((frame (decode-h3-frame #u8(64 33 0))))34
(assert-equal 33 (vector-ref frame 0))35
(assert-equal #u8() (vector-ref frame 1))))37
(test "HTTP/2-only frame types raise H3_FRAME_UNEXPECTED"38
(for-each39
(lambda (type)40
(assert-equal #x10541
(failure-code (lambda () (decode-h3-frame (bytevector type 0))))))42
'(2 6 8 9)))44
(test "oversized declared lengths fail before a body arrives"45
(assert-equal #x10746
(failure-code47
(lambda ()48
(decode-h3-frame (bytes-append #u8(0) (encode-varint 65537))))))))50
(test-group "HTTP/3 SETTINGS and shutdown"51
(test "zero QPACK capacity and extended CONNECT have known bytes"52
(assert-equal #u8(4 6 1 0 7 0 8 1)53
(encode-h3-settings '((1 . 0) (7 . 0) (8 . 1))))54
(assert-equal '((1 . 0) (7 . 0) (8 . 1))55
(decode-h3-settings #u8(1 0 7 0 8 1))))57
(test "unknown settings are preserved"58
(assert-equal '((33 . 9)) (decode-h3-settings #u8(33 9))))60
(test "duplicate and reserved settings raise H3_SETTINGS_ERROR"61
(assert-equal #x10962
(failure-code (lambda () (decode-h3-settings #u8(1 0 1 0)))))63
(for-each64
(lambda (identifier)65
(assert-equal #x10966
(failure-code (lambda () (decode-h3-settings (bytevector identifier 0))))))67
'(2 3 4 5)))69
(test "boolean settings reject values above one"70
(for-each71
(lambda (identifier)72
(assert-equal #x10973
(failure-code (lambda () (decode-h3-settings (bytevector identifier 2))))))74
'(8 51)))76
(test "truncated setting values raise H3_FRAME_ERROR"77
(for-each78
(lambda (payload)79
(assert-equal #x10680
(failure-code (lambda () (decode-h3-settings payload)))))81
(list #u8(1) #u8(64) #u8(1 64))))83
(test "setting work is bounded independently of payload size"84
(let ((payload85
(apply bytes-append86
(map87
(lambda (identifier) (bytes-append (encode-varint identifier) #u8(0)))88
(iota 65 100)))))89
(assert-equal #x10790
(failure-code (lambda () (decode-h3-settings payload))))))92
(test "GOAWAY has one complete identifier and exact wire bytes"93
(assert-equal #u8(7 1 4) (encode-h3-goaway 4))94
(assert-equal 4 (decode-h3-goaway #u8(4)))95
(assert-equal #x106 (failure-code (lambda () (decode-h3-goaway #u8()))))96
(assert-equal #x10697
(failure-code (lambda () (decode-h3-goaway #u8(4 0)))))))