2022-08-16 15:37:51 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net/netip"
|
|
|
|
"testing"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
C "github.com/sagernet/sing-box/constant"
|
|
|
|
"github.com/sagernet/sing-box/option"
|
2024-11-07 13:44:04 +00:00
|
|
|
"github.com/sagernet/sing/common"
|
|
|
|
"github.com/sagernet/sing/common/json/badoption"
|
2022-08-16 15:37:51 +00:00
|
|
|
)
|
|
|
|
|
2023-07-11 06:03:55 +00:00
|
|
|
func _TestWireGuard(t *testing.T) {
|
2022-08-16 15:37:51 +00:00
|
|
|
startDockerContainer(t, DockerOptions{
|
|
|
|
Image: ImageBoringTun,
|
|
|
|
Cap: []string{"MKNOD", "NET_ADMIN", "NET_RAW"},
|
|
|
|
Ports: []uint16{serverPort, testPort},
|
|
|
|
Bind: map[string]string{
|
|
|
|
"wireguard.conf": "/etc/wireguard/wg0.conf",
|
|
|
|
},
|
|
|
|
Cmd: []string{"wg0"},
|
|
|
|
})
|
|
|
|
time.Sleep(5 * time.Second)
|
|
|
|
startInstance(t, option.Options{
|
2024-11-07 13:44:04 +00:00
|
|
|
LegacyInbounds: []option.LegacyInbound{
|
2022-08-16 15:37:51 +00:00
|
|
|
{
|
|
|
|
Type: C.TypeMixed,
|
|
|
|
MixedOptions: option.HTTPMixedInboundOptions{
|
|
|
|
ListenOptions: option.ListenOptions{
|
2024-11-07 13:44:04 +00:00
|
|
|
Listen: common.Ptr(badoption.Addr(netip.IPv4Unspecified())),
|
2022-08-16 15:37:51 +00:00
|
|
|
ListenPort: clientPort,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2024-11-01 16:39:02 +00:00
|
|
|
LegacyOutbounds: []option.LegacyOutbound{
|
2022-08-16 15:37:51 +00:00
|
|
|
{
|
|
|
|
Type: C.TypeWireGuard,
|
|
|
|
WireGuardOptions: option.WireGuardOutboundOptions{
|
|
|
|
ServerOptions: option.ServerOptions{
|
|
|
|
Server: "127.0.0.1",
|
|
|
|
ServerPort: serverPort,
|
|
|
|
},
|
2023-10-25 04:00:00 +00:00
|
|
|
LocalAddress: []netip.Prefix{netip.MustParsePrefix("10.0.0.2/32")},
|
2022-08-16 15:37:51 +00:00
|
|
|
PrivateKey: "qGnwlkZljMxeECW8fbwAWdvgntnbK7B8UmMFl3zM0mk=",
|
|
|
|
PeerPublicKey: "QsdcBm+oJw2oNv0cIFXLIq1E850lgTBonup4qnKEQBg=",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
testSuitWg(t, clientPort, testPort)
|
|
|
|
}
|