2022-08-10 12:19:16 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net/netip"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
C "github.com/sagernet/sing-box/constant"
|
|
|
|
"github.com/sagernet/sing-box/option"
|
2024-11-18 10:59:19 +00:00
|
|
|
"github.com/sagernet/sing/common"
|
2022-08-10 12:19:16 +00:00
|
|
|
"github.com/sagernet/sing/common/auth"
|
2024-11-18 10:59:19 +00:00
|
|
|
"github.com/sagernet/sing/common/json/badoption"
|
2022-08-10 12:19:16 +00:00
|
|
|
"github.com/sagernet/sing/common/network"
|
|
|
|
)
|
|
|
|
|
2022-08-23 06:37:17 +00:00
|
|
|
func TestNaiveInboundWithNginx(t *testing.T) {
|
2022-08-23 05:22:03 +00:00
|
|
|
caPem, certPem, keyPem := createSelfSignedCertificate(t, "example.org")
|
|
|
|
startInstance(t, option.Options{
|
2024-11-18 10:59:19 +00:00
|
|
|
Inbounds: []option.Inbound{
|
2022-08-23 05:22:03 +00:00
|
|
|
{
|
|
|
|
Type: C.TypeNaive,
|
2024-11-18 10:59:19 +00:00
|
|
|
Options: &option.NaiveInboundOptions{
|
2022-08-23 05:22:03 +00:00
|
|
|
ListenOptions: option.ListenOptions{
|
2024-11-18 10:59:19 +00:00
|
|
|
Listen: common.Ptr(badoption.Addr(netip.IPv4Unspecified())),
|
2022-08-23 05:22:03 +00:00
|
|
|
ListenPort: otherPort,
|
|
|
|
},
|
|
|
|
Users: []auth.User{
|
|
|
|
{
|
|
|
|
Username: "sekai",
|
|
|
|
Password: "password",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Network: network.NetworkTCP,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
startDockerContainer(t, DockerOptions{
|
|
|
|
Image: ImageNginx,
|
|
|
|
Ports: []uint16{serverPort, otherPort},
|
|
|
|
Bind: map[string]string{
|
2022-08-23 06:37:17 +00:00
|
|
|
"nginx.conf": "/etc/nginx/nginx.conf",
|
2022-08-23 05:22:03 +00:00
|
|
|
"naive-nginx.conf": "/etc/nginx/conf.d/naive.conf",
|
|
|
|
certPem: "/etc/nginx/cert.pem",
|
|
|
|
keyPem: "/etc/nginx/key.pem",
|
|
|
|
},
|
|
|
|
})
|
|
|
|
startDockerContainer(t, DockerOptions{
|
|
|
|
Image: ImageNaive,
|
|
|
|
Ports: []uint16{serverPort, clientPort},
|
|
|
|
Bind: map[string]string{
|
|
|
|
"naive.json": "/etc/naiveproxy/config.json",
|
|
|
|
caPem: "/etc/naiveproxy/ca.pem",
|
|
|
|
},
|
|
|
|
Env: []string{
|
|
|
|
"SSL_CERT_FILE=/etc/naiveproxy/ca.pem",
|
|
|
|
},
|
|
|
|
})
|
|
|
|
testTCP(t, clientPort, testPort)
|
|
|
|
}
|
|
|
|
|
2022-08-10 12:19:16 +00:00
|
|
|
func TestNaiveInbound(t *testing.T) {
|
|
|
|
caPem, certPem, keyPem := createSelfSignedCertificate(t, "example.org")
|
|
|
|
startInstance(t, option.Options{
|
2024-11-18 10:59:19 +00:00
|
|
|
Inbounds: []option.Inbound{
|
2022-08-10 12:19:16 +00:00
|
|
|
{
|
|
|
|
Type: C.TypeNaive,
|
2024-11-18 10:59:19 +00:00
|
|
|
Options: &option.NaiveInboundOptions{
|
2022-08-10 12:19:16 +00:00
|
|
|
ListenOptions: option.ListenOptions{
|
2024-11-18 10:59:19 +00:00
|
|
|
Listen: common.Ptr(badoption.Addr(netip.IPv4Unspecified())),
|
2022-08-10 12:19:16 +00:00
|
|
|
ListenPort: serverPort,
|
|
|
|
},
|
|
|
|
Users: []auth.User{
|
|
|
|
{
|
|
|
|
Username: "sekai",
|
|
|
|
Password: "password",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Network: network.NetworkTCP,
|
2023-12-11 10:36:06 +00:00
|
|
|
InboundTLSOptionsContainer: option.InboundTLSOptionsContainer{
|
|
|
|
TLS: &option.InboundTLSOptions{
|
|
|
|
Enabled: true,
|
|
|
|
ServerName: "example.org",
|
|
|
|
CertificatePath: certPem,
|
|
|
|
KeyPath: keyPem,
|
|
|
|
},
|
2022-08-10 12:19:16 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
startDockerContainer(t, DockerOptions{
|
|
|
|
Image: ImageNaive,
|
|
|
|
Ports: []uint16{serverPort, clientPort},
|
|
|
|
Bind: map[string]string{
|
|
|
|
"naive.json": "/etc/naiveproxy/config.json",
|
|
|
|
caPem: "/etc/naiveproxy/ca.pem",
|
|
|
|
},
|
|
|
|
Env: []string{
|
|
|
|
"SSL_CERT_FILE=/etc/naiveproxy/ca.pem",
|
|
|
|
},
|
|
|
|
})
|
|
|
|
testTCP(t, clientPort, testPort)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestNaiveHTTP3Inbound(t *testing.T) {
|
|
|
|
caPem, certPem, keyPem := createSelfSignedCertificate(t, "example.org")
|
|
|
|
startInstance(t, option.Options{
|
2024-11-18 10:59:19 +00:00
|
|
|
Inbounds: []option.Inbound{
|
2022-08-10 12:19:16 +00:00
|
|
|
{
|
|
|
|
Type: C.TypeNaive,
|
2024-11-18 10:59:19 +00:00
|
|
|
Options: &option.NaiveInboundOptions{
|
2022-08-10 12:19:16 +00:00
|
|
|
ListenOptions: option.ListenOptions{
|
2024-11-18 10:59:19 +00:00
|
|
|
Listen: common.Ptr(badoption.Addr(netip.IPv4Unspecified())),
|
2022-08-10 12:19:16 +00:00
|
|
|
ListenPort: serverPort,
|
|
|
|
},
|
|
|
|
Users: []auth.User{
|
|
|
|
{
|
|
|
|
Username: "sekai",
|
|
|
|
Password: "password",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Network: network.NetworkUDP,
|
2023-12-11 10:36:06 +00:00
|
|
|
InboundTLSOptionsContainer: option.InboundTLSOptionsContainer{
|
|
|
|
TLS: &option.InboundTLSOptions{
|
|
|
|
Enabled: true,
|
|
|
|
ServerName: "example.org",
|
|
|
|
CertificatePath: certPem,
|
|
|
|
KeyPath: keyPem,
|
|
|
|
},
|
2022-08-10 12:19:16 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
startDockerContainer(t, DockerOptions{
|
|
|
|
Image: ImageNaive,
|
|
|
|
Ports: []uint16{serverPort, clientPort},
|
|
|
|
Bind: map[string]string{
|
|
|
|
"naive-quic.json": "/etc/naiveproxy/config.json",
|
|
|
|
caPem: "/etc/naiveproxy/ca.pem",
|
|
|
|
},
|
|
|
|
Env: []string{
|
|
|
|
"SSL_CERT_FILE=/etc/naiveproxy/ca.pem",
|
|
|
|
},
|
|
|
|
})
|
|
|
|
testTCP(t, clientPort, testPort)
|
|
|
|
}
|