github.com/sagernet/sing-box@v1.9.0-rc.20/common/sniff/stun_test.go (about)

     1  package sniff_test
     2  
     3  import (
     4  	"context"
     5  	"encoding/hex"
     6  	"testing"
     7  
     8  	"github.com/sagernet/sing-box/common/sniff"
     9  	C "github.com/sagernet/sing-box/constant"
    10  
    11  	"github.com/stretchr/testify/require"
    12  )
    13  
    14  func TestSniffSTUN(t *testing.T) {
    15  	t.Parallel()
    16  	packet, err := hex.DecodeString("000100002112a44224b1a025d0c180c484341306")
    17  	require.NoError(t, err)
    18  	metadata, err := sniff.STUNMessage(context.Background(), packet)
    19  	require.NoError(t, err)
    20  	require.Equal(t, metadata.Protocol, C.ProtocolSTUN)
    21  }
    22  
    23  func FuzzSniffSTUN(f *testing.F) {
    24  	f.Fuzz(func(t *testing.T, data []byte) {
    25  		if _, err := sniff.STUNMessage(context.Background(), data); err == nil {
    26  			t.Fail()
    27  		}
    28  	})
    29  }