123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147 |
- package main
- import (
- "net/netip"
- "testing"
- C "github.com/sagernet/sing-box/constant"
- "github.com/sagernet/sing-box/option"
- "github.com/sagernet/sing/common"
- "github.com/sagernet/sing/common/auth"
- "github.com/sagernet/sing/common/json/badoption"
- "github.com/sagernet/sing/common/network"
- )
- func TestNaiveInboundWithNginx(t *testing.T) {
- caPem, certPem, keyPem := createSelfSignedCertificate(t, "example.org")
- startInstance(t, option.Options{
- Inbounds: []option.Inbound{
- {
- Type: C.TypeNaive,
- Options: &option.NaiveInboundOptions{
- ListenOptions: option.ListenOptions{
- Listen: common.Ptr(badoption.Addr(netip.IPv4Unspecified())),
- 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{
- "nginx.conf": "/etc/nginx/nginx.conf",
- "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)
- }
- func TestNaiveInbound(t *testing.T) {
- caPem, certPem, keyPem := createSelfSignedCertificate(t, "example.org")
- startInstance(t, option.Options{
- Inbounds: []option.Inbound{
- {
- Type: C.TypeNaive,
- Options: &option.NaiveInboundOptions{
- ListenOptions: option.ListenOptions{
- Listen: common.Ptr(badoption.Addr(netip.IPv4Unspecified())),
- ListenPort: serverPort,
- },
- Users: []auth.User{
- {
- Username: "sekai",
- Password: "password",
- },
- },
- Network: network.NetworkTCP,
- InboundTLSOptionsContainer: option.InboundTLSOptionsContainer{
- TLS: &option.InboundTLSOptions{
- Enabled: true,
- ServerName: "example.org",
- CertificatePath: certPem,
- KeyPath: keyPem,
- },
- },
- },
- },
- },
- })
- 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{
- Inbounds: []option.Inbound{
- {
- Type: C.TypeNaive,
- Options: &option.NaiveInboundOptions{
- ListenOptions: option.ListenOptions{
- Listen: common.Ptr(badoption.Addr(netip.IPv4Unspecified())),
- ListenPort: serverPort,
- },
- Users: []auth.User{
- {
- Username: "sekai",
- Password: "password",
- },
- },
- Network: network.NetworkUDP,
- InboundTLSOptionsContainer: option.InboundTLSOptionsContainer{
- TLS: &option.InboundTLSOptions{
- Enabled: true,
- ServerName: "example.org",
- CertificatePath: certPem,
- KeyPath: keyPem,
- },
- },
- },
- },
- },
- })
- 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)
- }
|