2022-08-19 15:42:57 +08:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net/netip"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
C "github.com/sagernet/sing-box/constant"
|
|
|
|
"github.com/sagernet/sing-box/option"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestHysteriaSelf(t *testing.T) {
|
2022-08-21 22:26:00 +08:00
|
|
|
_, certPem, keyPem := createSelfSignedCertificate(t, "example.org")
|
2022-08-19 15:42:57 +08:00
|
|
|
startInstance(t, option.Options{
|
|
|
|
Inbounds: []option.Inbound{
|
|
|
|
{
|
|
|
|
Type: C.TypeMixed,
|
|
|
|
Tag: "mixed-in",
|
|
|
|
MixedOptions: option.HTTPMixedInboundOptions{
|
|
|
|
ListenOptions: option.ListenOptions{
|
2023-03-19 20:46:22 +08:00
|
|
|
Listen: option.NewListenAddress(netip.IPv4Unspecified()),
|
2022-08-19 15:42:57 +08:00
|
|
|
ListenPort: clientPort,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Type: C.TypeHysteria,
|
|
|
|
HysteriaOptions: option.HysteriaInboundOptions{
|
|
|
|
ListenOptions: option.ListenOptions{
|
2023-03-19 20:46:22 +08:00
|
|
|
Listen: option.NewListenAddress(netip.IPv4Unspecified()),
|
2022-08-19 15:42:57 +08:00
|
|
|
ListenPort: serverPort,
|
|
|
|
},
|
2022-11-10 21:10:18 +08:00
|
|
|
UpMbps: 100,
|
|
|
|
DownMbps: 100,
|
|
|
|
Users: []option.HysteriaUser{{
|
|
|
|
AuthString: "password",
|
|
|
|
}},
|
|
|
|
Obfs: "fuck me till the daylight",
|
2023-12-11 18:36:06 +08:00
|
|
|
InboundTLSOptionsContainer: option.InboundTLSOptionsContainer{
|
|
|
|
TLS: &option.InboundTLSOptions{
|
|
|
|
Enabled: true,
|
|
|
|
ServerName: "example.org",
|
|
|
|
CertificatePath: certPem,
|
|
|
|
KeyPath: keyPem,
|
|
|
|
},
|
2022-08-19 15:42:57 +08:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Outbounds: []option.Outbound{
|
|
|
|
{
|
|
|
|
Type: C.TypeDirect,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Type: C.TypeHysteria,
|
|
|
|
Tag: "hy-out",
|
2022-08-21 00:59:49 +08:00
|
|
|
HysteriaOptions: option.HysteriaOutboundOptions{
|
2022-08-19 15:42:57 +08:00
|
|
|
ServerOptions: option.ServerOptions{
|
|
|
|
Server: "127.0.0.1",
|
|
|
|
ServerPort: serverPort,
|
|
|
|
},
|
|
|
|
UpMbps: 100,
|
|
|
|
DownMbps: 100,
|
|
|
|
AuthString: "password",
|
|
|
|
Obfs: "fuck me till the daylight",
|
2023-12-11 18:36:06 +08:00
|
|
|
OutboundTLSOptionsContainer: option.OutboundTLSOptionsContainer{
|
|
|
|
TLS: &option.OutboundTLSOptions{
|
|
|
|
Enabled: true,
|
|
|
|
ServerName: "example.org",
|
|
|
|
CertificatePath: certPem,
|
|
|
|
},
|
2022-08-21 22:26:00 +08:00
|
|
|
},
|
2022-08-19 15:42:57 +08:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Route: &option.RouteOptions{
|
|
|
|
Rules: []option.Rule{
|
|
|
|
{
|
2024-10-21 23:38:34 +08:00
|
|
|
Type: C.RuleTypeDefault,
|
2022-08-19 15:42:57 +08:00
|
|
|
DefaultOptions: option.DefaultRule{
|
2024-10-21 23:38:34 +08:00
|
|
|
RawDefaultRule: option.RawDefaultRule{
|
|
|
|
Inbound: []string{"mixed-in"},
|
|
|
|
},
|
|
|
|
RuleAction: option.RuleAction{
|
|
|
|
Action: C.RuleActionTypeRoute,
|
|
|
|
|
|
|
|
RouteOptions: option.RouteActionOptions{
|
|
|
|
Outbound: "hy-out",
|
|
|
|
},
|
|
|
|
},
|
2022-08-19 15:42:57 +08:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
2023-10-21 12:00:00 +08:00
|
|
|
testSuit(t, clientPort, testPort)
|
2022-08-19 15:42:57 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestHysteriaInbound(t *testing.T) {
|
|
|
|
caPem, certPem, keyPem := createSelfSignedCertificate(t, "example.org")
|
|
|
|
startInstance(t, option.Options{
|
|
|
|
Inbounds: []option.Inbound{
|
|
|
|
{
|
|
|
|
Type: C.TypeHysteria,
|
|
|
|
HysteriaOptions: option.HysteriaInboundOptions{
|
|
|
|
ListenOptions: option.ListenOptions{
|
2023-03-19 20:46:22 +08:00
|
|
|
Listen: option.NewListenAddress(netip.IPv4Unspecified()),
|
2022-08-19 15:42:57 +08:00
|
|
|
ListenPort: serverPort,
|
|
|
|
},
|
2022-11-10 21:10:18 +08:00
|
|
|
UpMbps: 100,
|
|
|
|
DownMbps: 100,
|
|
|
|
Users: []option.HysteriaUser{{
|
|
|
|
AuthString: "password",
|
|
|
|
}},
|
|
|
|
Obfs: "fuck me till the daylight",
|
2023-12-11 18:36:06 +08:00
|
|
|
InboundTLSOptionsContainer: option.InboundTLSOptionsContainer{
|
|
|
|
TLS: &option.InboundTLSOptions{
|
|
|
|
Enabled: true,
|
|
|
|
ServerName: "example.org",
|
|
|
|
CertificatePath: certPem,
|
|
|
|
KeyPath: keyPem,
|
|
|
|
},
|
2022-08-19 15:42:57 +08:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
startDockerContainer(t, DockerOptions{
|
|
|
|
Image: ImageHysteria,
|
|
|
|
Ports: []uint16{serverPort, clientPort},
|
|
|
|
Cmd: []string{"-c", "/etc/hysteria/config.json", "client"},
|
|
|
|
Bind: map[string]string{
|
|
|
|
"hysteria-client.json": "/etc/hysteria/config.json",
|
|
|
|
caPem: "/etc/hysteria/ca.pem",
|
|
|
|
},
|
|
|
|
})
|
2023-10-21 12:00:00 +08:00
|
|
|
testSuit(t, clientPort, testPort)
|
2022-08-19 15:42:57 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestHysteriaOutbound(t *testing.T) {
|
2022-08-21 22:26:00 +08:00
|
|
|
_, certPem, keyPem := createSelfSignedCertificate(t, "example.org")
|
2022-08-19 15:42:57 +08:00
|
|
|
startDockerContainer(t, DockerOptions{
|
|
|
|
Image: ImageHysteria,
|
2023-07-11 14:03:55 +08:00
|
|
|
Ports: []uint16{testPort},
|
2022-08-19 15:42:57 +08:00
|
|
|
Cmd: []string{"-c", "/etc/hysteria/config.json", "server"},
|
|
|
|
Bind: map[string]string{
|
|
|
|
"hysteria-server.json": "/etc/hysteria/config.json",
|
|
|
|
certPem: "/etc/hysteria/cert.pem",
|
|
|
|
keyPem: "/etc/hysteria/key.pem",
|
|
|
|
},
|
|
|
|
})
|
|
|
|
startInstance(t, option.Options{
|
|
|
|
Inbounds: []option.Inbound{
|
|
|
|
{
|
|
|
|
Type: C.TypeMixed,
|
|
|
|
MixedOptions: option.HTTPMixedInboundOptions{
|
|
|
|
ListenOptions: option.ListenOptions{
|
2023-03-19 20:46:22 +08:00
|
|
|
Listen: option.NewListenAddress(netip.IPv4Unspecified()),
|
2022-08-19 15:42:57 +08:00
|
|
|
ListenPort: clientPort,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Outbounds: []option.Outbound{
|
|
|
|
{
|
|
|
|
Type: C.TypeHysteria,
|
2022-08-21 00:59:49 +08:00
|
|
|
HysteriaOptions: option.HysteriaOutboundOptions{
|
2022-08-19 15:42:57 +08:00
|
|
|
ServerOptions: option.ServerOptions{
|
|
|
|
Server: "127.0.0.1",
|
|
|
|
ServerPort: serverPort,
|
|
|
|
},
|
|
|
|
UpMbps: 100,
|
|
|
|
DownMbps: 100,
|
|
|
|
AuthString: "password",
|
|
|
|
Obfs: "fuck me till the daylight",
|
2023-12-11 18:36:06 +08:00
|
|
|
OutboundTLSOptionsContainer: option.OutboundTLSOptionsContainer{
|
|
|
|
TLS: &option.OutboundTLSOptions{
|
|
|
|
Enabled: true,
|
|
|
|
ServerName: "example.org",
|
|
|
|
CertificatePath: certPem,
|
|
|
|
},
|
2022-08-21 22:26:00 +08:00
|
|
|
},
|
2022-08-19 15:42:57 +08:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
2022-09-14 16:07:52 +08:00
|
|
|
testSuitSimple1(t, clientPort, testPort)
|
2022-08-19 15:42:57 +08:00
|
|
|
}
|