sing-box/common/sniff/stun_test.go

30 lines
671 B
Go
Raw Normal View History

2022-07-16 04:01:02 +00:00
package sniff_test
import (
"context"
"encoding/hex"
"testing"
"github.com/sagernet/sing-box/common/sniff"
C "github.com/sagernet/sing-box/constant"
"github.com/stretchr/testify/require"
)
func TestSniffSTUN(t *testing.T) {
2022-07-16 13:49:54 +00:00
t.Parallel()
2022-07-16 04:01:02 +00:00
packet, err := hex.DecodeString("000100002112a44224b1a025d0c180c484341306")
require.NoError(t, err)
metadata, err := sniff.STUNMessage(context.Background(), packet)
require.NoError(t, err)
require.Equal(t, metadata.Protocol, C.ProtocolSTUN)
}
func FuzzSniffSTUN(f *testing.F) {
f.Fuzz(func(t *testing.T, data []byte) {
if _, err := sniff.STUNMessage(context.Background(), data); err == nil {
t.Fail()
}
})
}