From 5a3de62c508a21d5180f7da155715c74823c90e9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=96=E7=95=8C?= <i@sekai.icu> Date: Fri, 15 Jul 2022 11:18:14 +0800 Subject: [PATCH] Add ss aead tests --- go.mod | 2 +- go.sum | 4 ++-- test/box_test.go | 5 +++-- test/go.mod | 2 +- test/go.sum | 4 ++-- test/shadowsocks_test.go | 18 ++++++++++++++++++ 6 files changed, 27 insertions(+), 8 deletions(-) diff --git a/go.mod b/go.mod index e5709b81..1b903851 100644 --- a/go.mod +++ b/go.mod @@ -9,7 +9,7 @@ require ( github.com/oschwald/maxminddb-golang v1.9.0 github.com/sagernet/sing v0.0.0-20220714145306-09b55ce4b6d0 github.com/sagernet/sing-dns v0.0.0-20220711062726-c64e938e4619 - github.com/sagernet/sing-shadowsocks v0.0.0-20220714111527-a6fa7ada6e81 + github.com/sagernet/sing-shadowsocks v0.0.0-20220715031600-dacfbcd606f4 github.com/sagernet/sing-tun v0.0.0-20220714151007-c0d248af0361 github.com/spf13/cobra v1.5.0 github.com/stretchr/testify v1.8.0 diff --git a/go.sum b/go.sum index 889d7af7..03ad8d76 100644 --- a/go.sum +++ b/go.sum @@ -29,8 +29,8 @@ github.com/sagernet/sing v0.0.0-20220714145306-09b55ce4b6d0 h1:8tnMLN6jdqKkjPXwg github.com/sagernet/sing v0.0.0-20220714145306-09b55ce4b6d0/go.mod h1:3ZmoGNg/nNJTyHAZFNRSPaXpNIwpDvyIiAUd0KIWV5c= github.com/sagernet/sing-dns v0.0.0-20220711062726-c64e938e4619 h1:oHbOmq1WS0XaZmXp6WpxzyB2xeyRIA1/L8EJKuNntfY= github.com/sagernet/sing-dns v0.0.0-20220711062726-c64e938e4619/go.mod h1:y2fpvoxukw3G7eApIZwkcpcG/NE4AB8pCQI0Qd8rMqk= -github.com/sagernet/sing-shadowsocks v0.0.0-20220714111527-a6fa7ada6e81 h1:VuUk/04yCr3dw2uJj0/OFVeVO5O2dwYGlj/RzuEfYDE= -github.com/sagernet/sing-shadowsocks v0.0.0-20220714111527-a6fa7ada6e81/go.mod h1:MuyT+9fEPjvauAv0fSE0a6Q+l0Tv2ZrAafTkYfnxBFw= +github.com/sagernet/sing-shadowsocks v0.0.0-20220715031600-dacfbcd606f4 h1:s3yKbPfiNwFFGfcNUs8NcKYzor78HWmZuDl5B0dsVQI= +github.com/sagernet/sing-shadowsocks v0.0.0-20220715031600-dacfbcd606f4/go.mod h1:MuyT+9fEPjvauAv0fSE0a6Q+l0Tv2ZrAafTkYfnxBFw= github.com/sagernet/sing-tun v0.0.0-20220714151007-c0d248af0361 h1:M6m9mXG5u151voF0wSDLf5JoDwHU5+4FOMrzb/kaRdc= github.com/sagernet/sing-tun v0.0.0-20220714151007-c0d248af0361/go.mod h1:p7QbUBs2ejf6UQsiHyy1xGAWOk9JWQjZTHy8pOmkWmo= github.com/spf13/cobra v1.5.0 h1:X+jTBEBqF0bHN+9cSMgmfuvv2VHJ9ezmFNf9Y/XstYU= diff --git a/test/box_test.go b/test/box_test.go index beac2575..514e3e0e 100644 --- a/test/box_test.go +++ b/test/box_test.go @@ -9,6 +9,7 @@ import ( "github.com/sagernet/sing-box" "github.com/sagernet/sing-box/option" "github.com/sagernet/sing/common/control" + F "github.com/sagernet/sing/common/format" M "github.com/sagernet/sing/common/metadata" N "github.com/sagernet/sing/common/network" "github.com/sagernet/sing/protocol/socks" @@ -20,11 +21,11 @@ func mkPort(t *testing.T) uint16 { var lc net.ListenConfig lc.Control = control.ReuseAddr() for { - tcpListener, err := net.ListenTCP("tcp", nil) + tcpListener, err := lc.Listen(context.Background(), "tcp", ":0") require.NoError(t, err) listenPort := M.SocksaddrFromNet(tcpListener.Addr()).Port tcpListener.Close() - udpListener, err := net.ListenUDP("udp", &net.UDPAddr{Port: int(listenPort)}) + udpListener, err := lc.Listen(context.Background(), "tcp", F.ToString(":", listenPort)) if err != nil { continue } diff --git a/test/go.mod b/test/go.mod index 98640597..cf0a5603 100644 --- a/test/go.mod +++ b/test/go.mod @@ -33,7 +33,7 @@ require ( github.com/pkg/errors v0.9.1 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect github.com/sagernet/sing-dns v0.0.0-20220711062726-c64e938e4619 // indirect - github.com/sagernet/sing-shadowsocks v0.0.0-20220714111527-a6fa7ada6e81 // indirect + github.com/sagernet/sing-shadowsocks v0.0.0-20220715031600-dacfbcd606f4 // indirect github.com/sagernet/sing-tun v0.0.0-20220714151007-c0d248af0361 // indirect github.com/sirupsen/logrus v1.8.1 // indirect github.com/vishvananda/netlink v1.1.0 // indirect diff --git a/test/go.sum b/test/go.sum index cdaba883..4fcb3b4d 100644 --- a/test/go.sum +++ b/test/go.sum @@ -56,8 +56,8 @@ github.com/sagernet/sing v0.0.0-20220714145306-09b55ce4b6d0 h1:8tnMLN6jdqKkjPXwg github.com/sagernet/sing v0.0.0-20220714145306-09b55ce4b6d0/go.mod h1:3ZmoGNg/nNJTyHAZFNRSPaXpNIwpDvyIiAUd0KIWV5c= github.com/sagernet/sing-dns v0.0.0-20220711062726-c64e938e4619 h1:oHbOmq1WS0XaZmXp6WpxzyB2xeyRIA1/L8EJKuNntfY= github.com/sagernet/sing-dns v0.0.0-20220711062726-c64e938e4619/go.mod h1:y2fpvoxukw3G7eApIZwkcpcG/NE4AB8pCQI0Qd8rMqk= -github.com/sagernet/sing-shadowsocks v0.0.0-20220714111527-a6fa7ada6e81 h1:VuUk/04yCr3dw2uJj0/OFVeVO5O2dwYGlj/RzuEfYDE= -github.com/sagernet/sing-shadowsocks v0.0.0-20220714111527-a6fa7ada6e81/go.mod h1:MuyT+9fEPjvauAv0fSE0a6Q+l0Tv2ZrAafTkYfnxBFw= +github.com/sagernet/sing-shadowsocks v0.0.0-20220715031600-dacfbcd606f4 h1:s3yKbPfiNwFFGfcNUs8NcKYzor78HWmZuDl5B0dsVQI= +github.com/sagernet/sing-shadowsocks v0.0.0-20220715031600-dacfbcd606f4/go.mod h1:MuyT+9fEPjvauAv0fSE0a6Q+l0Tv2ZrAafTkYfnxBFw= github.com/sagernet/sing-tun v0.0.0-20220714151007-c0d248af0361 h1:M6m9mXG5u151voF0wSDLf5JoDwHU5+4FOMrzb/kaRdc= github.com/sagernet/sing-tun v0.0.0-20220714151007-c0d248af0361/go.mod h1:p7QbUBs2ejf6UQsiHyy1xGAWOk9JWQjZTHy8pOmkWmo= github.com/sirupsen/logrus v1.7.0/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0= diff --git a/test/shadowsocks_test.go b/test/shadowsocks_test.go index 5fcbfe69..98cb5a15 100644 --- a/test/shadowsocks_test.go +++ b/test/shadowsocks_test.go @@ -14,6 +14,24 @@ import ( ) func TestShadowsocks(t *testing.T) { + for _, method := range []string{ + "aes-128-gcm", + "aes-256-gcm", + "chacha20-ietf-poly1305", + } { + t.Run(method+"-inbound", func(t *testing.T) { + testShadowsocksInboundWithShadowsocksRust(t, method, mkBase64(t, 16)) + }) + t.Run(method+"-outbound", func(t *testing.T) { + testShadowsocksOutboundWithShadowsocksRust(t, method, mkBase64(t, 16)) + }) + t.Run(method+"-self", func(t *testing.T) { + testShadowsocksSelf(t, method, mkBase64(t, 16)) + }) + } +} + +func TestShadowsocks2022(t *testing.T) { for _, method16 := range []string{ "2022-blake3-aes-128-gcm", } {