sing-box/common/sniff/stun_test.go

33 lines
794 B
Go
Raw Normal View History

2022-07-16 12:01:02 +08:00
package sniff_test
import (
"context"
"encoding/hex"
"testing"
2024-07-07 15:45:50 +08:00
"github.com/sagernet/sing-box/adapter"
2022-07-16 12:01:02 +08:00
"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 21:49:54 +08:00
t.Parallel()
2022-07-16 12:01:02 +08:00
packet, err := hex.DecodeString("000100002112a44224b1a025d0c180c484341306")
require.NoError(t, err)
2024-07-07 15:45:50 +08:00
var metadata adapter.InboundContext
err = sniff.STUNMessage(context.Background(), &metadata, packet)
2022-07-16 12:01:02 +08:00
require.NoError(t, err)
require.Equal(t, metadata.Protocol, C.ProtocolSTUN)
}
func FuzzSniffSTUN(f *testing.F) {
f.Fuzz(func(t *testing.T, data []byte) {
2024-07-07 15:45:50 +08:00
var metadata adapter.InboundContext
if err := sniff.STUNMessage(context.Background(), &metadata, data); err == nil {
2022-07-16 12:01:02 +08:00
t.Fail()
}
})
}