|
| 1 | +package inbound_test |
| 2 | + |
| 3 | +import ( |
| 4 | + "net/netip" |
| 5 | + "testing" |
| 6 | + |
| 7 | + "github.com/metacubex/mihomo/adapter/outbound" |
| 8 | + "github.com/metacubex/mihomo/listener/inbound" |
| 9 | + |
| 10 | + "github.com/stretchr/testify/assert" |
| 11 | +) |
| 12 | + |
| 13 | +func testInboundHysteria2(t *testing.T, inboundOptions inbound.Hysteria2Option, outboundOptions outbound.Hysteria2Option) { |
| 14 | + inboundOptions.BaseOption = inbound.BaseOption{ |
| 15 | + NameStr: "hysteria2_inbound", |
| 16 | + Listen: "127.0.0.1", |
| 17 | + Port: "0", |
| 18 | + } |
| 19 | + inboundOptions.Users = map[string]string{"test": userUUID} |
| 20 | + in, err := inbound.NewHysteria2(&inboundOptions) |
| 21 | + assert.NoError(t, err) |
| 22 | + |
| 23 | + tunnel := NewHttpTestTunnel() |
| 24 | + defer tunnel.Close() |
| 25 | + |
| 26 | + err = in.Listen(tunnel) |
| 27 | + assert.NoError(t, err) |
| 28 | + defer in.Close() |
| 29 | + |
| 30 | + addrPort, err := netip.ParseAddrPort(in.Address()) |
| 31 | + assert.NoError(t, err) |
| 32 | + |
| 33 | + outboundOptions.Name = "hysteria2_outbound" |
| 34 | + outboundOptions.Server = addrPort.Addr().String() |
| 35 | + outboundOptions.Port = int(addrPort.Port()) |
| 36 | + outboundOptions.Password = userUUID |
| 37 | + |
| 38 | + out, err := outbound.NewHysteria2(outboundOptions) |
| 39 | + assert.NoError(t, err) |
| 40 | + defer out.Close() |
| 41 | + |
| 42 | + tunnel.DoTest(t, out) |
| 43 | +} |
| 44 | + |
| 45 | +func TestInboundHysteria2_TLS(t *testing.T) { |
| 46 | + inboundOptions := inbound.Hysteria2Option{ |
| 47 | + Certificate: tlsCertificate, |
| 48 | + PrivateKey: tlsPrivateKey, |
| 49 | + } |
| 50 | + outboundOptions := outbound.Hysteria2Option{ |
| 51 | + Fingerprint: tlsFingerprint, |
| 52 | + } |
| 53 | + testInboundHysteria2(t, inboundOptions, outboundOptions) |
| 54 | +} |
| 55 | + |
| 56 | +func TestInboundHysteria2_Salamander(t *testing.T) { |
| 57 | + inboundOptions := inbound.Hysteria2Option{ |
| 58 | + Certificate: tlsCertificate, |
| 59 | + PrivateKey: tlsPrivateKey, |
| 60 | + Obfs: "salamander", |
| 61 | + ObfsPassword: userUUID, |
| 62 | + } |
| 63 | + outboundOptions := outbound.Hysteria2Option{ |
| 64 | + Fingerprint: tlsFingerprint, |
| 65 | + Obfs: "salamander", |
| 66 | + ObfsPassword: userUUID, |
| 67 | + } |
| 68 | + testInboundHysteria2(t, inboundOptions, outboundOptions) |
| 69 | +} |
| 70 | + |
| 71 | +func TestInboundHysteria2_Brutal(t *testing.T) { |
| 72 | + inboundOptions := inbound.Hysteria2Option{ |
| 73 | + Certificate: tlsCertificate, |
| 74 | + PrivateKey: tlsPrivateKey, |
| 75 | + Up: "30 Mbps", |
| 76 | + Down: "200 Mbps", |
| 77 | + } |
| 78 | + outboundOptions := outbound.Hysteria2Option{ |
| 79 | + Fingerprint: tlsFingerprint, |
| 80 | + Up: "30 Mbps", |
| 81 | + Down: "200 Mbps", |
| 82 | + } |
| 83 | + testInboundHysteria2(t, inboundOptions, outboundOptions) |
| 84 | +} |
0 commit comments