hysteria_test.go 4.3 KB

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