hysteria_test.go 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  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. if !C.QUIC_AVAILABLE {
  10. t.Skip("QUIC not included")
  11. }
  12. _, certPem, keyPem := createSelfSignedCertificate(t, "example.org")
  13. startInstance(t, option.Options{
  14. Log: &option.LogOptions{
  15. Level: "error",
  16. },
  17. Inbounds: []option.Inbound{
  18. {
  19. Type: C.TypeMixed,
  20. Tag: "mixed-in",
  21. MixedOptions: option.HTTPMixedInboundOptions{
  22. ListenOptions: option.ListenOptions{
  23. Listen: option.ListenAddress(netip.IPv4Unspecified()),
  24. ListenPort: clientPort,
  25. },
  26. },
  27. },
  28. {
  29. Type: C.TypeHysteria,
  30. HysteriaOptions: option.HysteriaInboundOptions{
  31. ListenOptions: option.ListenOptions{
  32. Listen: option.ListenAddress(netip.IPv4Unspecified()),
  33. ListenPort: serverPort,
  34. },
  35. UpMbps: 100,
  36. DownMbps: 100,
  37. AuthString: "password",
  38. Obfs: "fuck me till the daylight",
  39. TLS: &option.InboundTLSOptions{
  40. Enabled: true,
  41. ServerName: "example.org",
  42. CertificatePath: certPem,
  43. KeyPath: keyPem,
  44. },
  45. },
  46. },
  47. },
  48. Outbounds: []option.Outbound{
  49. {
  50. Type: C.TypeDirect,
  51. },
  52. {
  53. Type: C.TypeHysteria,
  54. Tag: "hy-out",
  55. HysteriaOptions: option.HysteriaOutboundOptions{
  56. ServerOptions: option.ServerOptions{
  57. Server: "127.0.0.1",
  58. ServerPort: serverPort,
  59. },
  60. UpMbps: 100,
  61. DownMbps: 100,
  62. AuthString: "password",
  63. Obfs: "fuck me till the daylight",
  64. TLS: &option.OutboundTLSOptions{
  65. Enabled: true,
  66. ServerName: "example.org",
  67. CertificatePath: certPem,
  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. testSuitQUIC(t, clientPort, testPort)
  84. }
  85. func TestHysteriaInbound(t *testing.T) {
  86. if !C.QUIC_AVAILABLE {
  87. t.Skip("QUIC not included")
  88. }
  89. caPem, certPem, keyPem := createSelfSignedCertificate(t, "example.org")
  90. startInstance(t, option.Options{
  91. Log: &option.LogOptions{
  92. Level: "error",
  93. },
  94. Inbounds: []option.Inbound{
  95. {
  96. Type: C.TypeHysteria,
  97. HysteriaOptions: option.HysteriaInboundOptions{
  98. ListenOptions: option.ListenOptions{
  99. Listen: option.ListenAddress(netip.IPv4Unspecified()),
  100. ListenPort: serverPort,
  101. },
  102. UpMbps: 100,
  103. DownMbps: 100,
  104. AuthString: "password",
  105. Obfs: "fuck me till the daylight",
  106. TLS: &option.InboundTLSOptions{
  107. Enabled: true,
  108. ServerName: "example.org",
  109. CertificatePath: certPem,
  110. KeyPath: keyPem,
  111. },
  112. },
  113. },
  114. },
  115. })
  116. startDockerContainer(t, DockerOptions{
  117. Image: ImageHysteria,
  118. Ports: []uint16{serverPort, clientPort},
  119. Cmd: []string{"-c", "/etc/hysteria/config.json", "client"},
  120. Bind: map[string]string{
  121. "hysteria-client.json": "/etc/hysteria/config.json",
  122. caPem: "/etc/hysteria/ca.pem",
  123. },
  124. })
  125. testSuit(t, clientPort, testPort)
  126. }
  127. func TestHysteriaOutbound(t *testing.T) {
  128. if !C.QUIC_AVAILABLE {
  129. t.Skip("QUIC not included")
  130. }
  131. _, certPem, keyPem := createSelfSignedCertificate(t, "example.org")
  132. startDockerContainer(t, DockerOptions{
  133. Image: ImageHysteria,
  134. Ports: []uint16{serverPort, testPort},
  135. Cmd: []string{"-c", "/etc/hysteria/config.json", "server"},
  136. Bind: map[string]string{
  137. "hysteria-server.json": "/etc/hysteria/config.json",
  138. certPem: "/etc/hysteria/cert.pem",
  139. keyPem: "/etc/hysteria/key.pem",
  140. },
  141. })
  142. startInstance(t, option.Options{
  143. Log: &option.LogOptions{
  144. Level: "error",
  145. },
  146. Inbounds: []option.Inbound{
  147. {
  148. Type: C.TypeMixed,
  149. MixedOptions: option.HTTPMixedInboundOptions{
  150. ListenOptions: option.ListenOptions{
  151. Listen: option.ListenAddress(netip.IPv4Unspecified()),
  152. ListenPort: clientPort,
  153. },
  154. },
  155. },
  156. },
  157. Outbounds: []option.Outbound{
  158. {
  159. Type: C.TypeHysteria,
  160. HysteriaOptions: option.HysteriaOutboundOptions{
  161. ServerOptions: option.ServerOptions{
  162. Server: "127.0.0.1",
  163. ServerPort: serverPort,
  164. },
  165. UpMbps: 100,
  166. DownMbps: 100,
  167. AuthString: "password",
  168. Obfs: "fuck me till the daylight",
  169. TLS: &option.OutboundTLSOptions{
  170. Enabled: true,
  171. ServerName: "example.org",
  172. CertificatePath: certPem,
  173. },
  174. },
  175. },
  176. },
  177. })
  178. testSuitQUIC(t, clientPort, testPort)
  179. }