1
0

hysteria_test.go 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. package main
  2. import (
  3. "net/netip"
  4. "testing"
  5. C "github.com/sagernet/sing-box/constant"
  6. "github.com/sagernet/sing-box/option"
  7. )
  8. func TestHysteriaSelf(t *testing.T) {
  9. _, certPem, keyPem := createSelfSignedCertificate(t, "example.org")
  10. startInstance(t, option.Options{
  11. Inbounds: []option.Inbound{
  12. {
  13. Type: C.TypeMixed,
  14. Tag: "mixed-in",
  15. MixedOptions: option.HTTPMixedInboundOptions{
  16. ListenOptions: option.ListenOptions{
  17. Listen: option.NewListenAddress(netip.IPv4Unspecified()),
  18. ListenPort: clientPort,
  19. },
  20. },
  21. },
  22. {
  23. Type: C.TypeHysteria,
  24. HysteriaOptions: option.HysteriaInboundOptions{
  25. ListenOptions: option.ListenOptions{
  26. Listen: option.NewListenAddress(netip.IPv4Unspecified()),
  27. ListenPort: serverPort,
  28. },
  29. UpMbps: 100,
  30. DownMbps: 100,
  31. Users: []option.HysteriaUser{{
  32. AuthString: "password",
  33. }},
  34. Obfs: "fuck me till the daylight",
  35. InboundTLSOptionsContainer: option.InboundTLSOptionsContainer{
  36. TLS: &option.InboundTLSOptions{
  37. Enabled: true,
  38. ServerName: "example.org",
  39. CertificatePath: certPem,
  40. KeyPath: keyPem,
  41. },
  42. },
  43. },
  44. },
  45. },
  46. Outbounds: []option.Outbound{
  47. {
  48. Type: C.TypeDirect,
  49. },
  50. {
  51. Type: C.TypeHysteria,
  52. Tag: "hy-out",
  53. HysteriaOptions: option.HysteriaOutboundOptions{
  54. ServerOptions: option.ServerOptions{
  55. Server: "127.0.0.1",
  56. ServerPort: serverPort,
  57. },
  58. UpMbps: 100,
  59. DownMbps: 100,
  60. AuthString: "password",
  61. Obfs: "fuck me till the daylight",
  62. OutboundTLSOptionsContainer: option.OutboundTLSOptionsContainer{
  63. TLS: &option.OutboundTLSOptions{
  64. Enabled: true,
  65. ServerName: "example.org",
  66. CertificatePath: certPem,
  67. },
  68. },
  69. },
  70. },
  71. },
  72. Route: &option.RouteOptions{
  73. Rules: []option.Rule{
  74. {
  75. DefaultOptions: option.DefaultRule{
  76. Inbound: []string{"mixed-in"},
  77. Outbound: "hy-out",
  78. },
  79. },
  80. },
  81. },
  82. })
  83. testSuit(t, clientPort, testPort)
  84. }
  85. func TestHysteriaInbound(t *testing.T) {
  86. caPem, certPem, keyPem := createSelfSignedCertificate(t, "example.org")
  87. startInstance(t, option.Options{
  88. Inbounds: []option.Inbound{
  89. {
  90. Type: C.TypeHysteria,
  91. HysteriaOptions: option.HysteriaInboundOptions{
  92. ListenOptions: option.ListenOptions{
  93. Listen: option.NewListenAddress(netip.IPv4Unspecified()),
  94. ListenPort: serverPort,
  95. },
  96. UpMbps: 100,
  97. DownMbps: 100,
  98. Users: []option.HysteriaUser{{
  99. AuthString: "password",
  100. }},
  101. Obfs: "fuck me till the daylight",
  102. InboundTLSOptionsContainer: option.InboundTLSOptionsContainer{
  103. TLS: &option.InboundTLSOptions{
  104. Enabled: true,
  105. ServerName: "example.org",
  106. CertificatePath: certPem,
  107. KeyPath: keyPem,
  108. },
  109. },
  110. },
  111. },
  112. },
  113. })
  114. startDockerContainer(t, DockerOptions{
  115. Image: ImageHysteria,
  116. Ports: []uint16{serverPort, clientPort},
  117. Cmd: []string{"-c", "/etc/hysteria/config.json", "client"},
  118. Bind: map[string]string{
  119. "hysteria-client.json": "/etc/hysteria/config.json",
  120. caPem: "/etc/hysteria/ca.pem",
  121. },
  122. })
  123. testSuit(t, clientPort, testPort)
  124. }
  125. func TestHysteriaOutbound(t *testing.T) {
  126. _, certPem, keyPem := createSelfSignedCertificate(t, "example.org")
  127. startDockerContainer(t, DockerOptions{
  128. Image: ImageHysteria,
  129. Ports: []uint16{testPort},
  130. Cmd: []string{"-c", "/etc/hysteria/config.json", "server"},
  131. Bind: map[string]string{
  132. "hysteria-server.json": "/etc/hysteria/config.json",
  133. certPem: "/etc/hysteria/cert.pem",
  134. keyPem: "/etc/hysteria/key.pem",
  135. },
  136. })
  137. startInstance(t, option.Options{
  138. Inbounds: []option.Inbound{
  139. {
  140. Type: C.TypeMixed,
  141. MixedOptions: option.HTTPMixedInboundOptions{
  142. ListenOptions: option.ListenOptions{
  143. Listen: option.NewListenAddress(netip.IPv4Unspecified()),
  144. ListenPort: clientPort,
  145. },
  146. },
  147. },
  148. },
  149. Outbounds: []option.Outbound{
  150. {
  151. Type: C.TypeHysteria,
  152. HysteriaOptions: option.HysteriaOutboundOptions{
  153. ServerOptions: option.ServerOptions{
  154. Server: "127.0.0.1",
  155. ServerPort: serverPort,
  156. },
  157. UpMbps: 100,
  158. DownMbps: 100,
  159. AuthString: "password",
  160. Obfs: "fuck me till the daylight",
  161. OutboundTLSOptionsContainer: option.OutboundTLSOptionsContainer{
  162. TLS: &option.OutboundTLSOptions{
  163. Enabled: true,
  164. ServerName: "example.org",
  165. CertificatePath: certPem,
  166. },
  167. },
  168. },
  169. },
  170. },
  171. })
  172. testSuitSimple1(t, clientPort, testPort)
  173. }