hysteria_test.go 4.2 KB

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