github.com/pion/dtls/v2@v2.2.12/pkg/protocol/recordlayer/fuzz_test.go (about) 1 // SPDX-FileCopyrightText: 2023 The Pion community <https://pion.ly> 2 // SPDX-License-Identifier: MIT 3 4 package recordlayer 5 6 import ( 7 "testing" 8 ) 9 10 func partialHeaderMismatch(a, b Header) bool { 11 // Ignoring content length for now. 12 a.ContentLen = b.ContentLen 13 return a != b 14 } 15 16 func FuzzRecordLayer(f *testing.F) { 17 f.Fuzz(func(t *testing.T, data []byte) { 18 var r RecordLayer 19 if err := r.Unmarshal(data); err != nil { 20 return 21 } 22 23 buf, err := r.Marshal() 24 if err != nil { 25 return 26 } 27 28 if len(buf) == 0 { 29 t.Fatal("Zero buff") 30 } 31 32 var nr RecordLayer 33 if err = nr.Unmarshal(data); err != nil { 34 t.Fatal(err) 35 } 36 37 if partialHeaderMismatch(nr.Header, r.Header) { 38 t.Fatalf("Header mismatch: %+v != %+v", nr.Header, r.Header) 39 } 40 }) 41 }