naive_test.go 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  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. "github.com/sagernet/sing/common/auth"
  8. "github.com/sagernet/sing/common/network"
  9. )
  10. func TestNaiveInboundWithNginx(t *testing.T) {
  11. caPem, certPem, keyPem := createSelfSignedCertificate(t, "example.org")
  12. startInstance(t, option.Options{
  13. Log: &option.LogOptions{
  14. Level: "error",
  15. },
  16. Inbounds: []option.Inbound{
  17. {
  18. Type: C.TypeNaive,
  19. NaiveOptions: option.NaiveInboundOptions{
  20. ListenOptions: option.ListenOptions{
  21. Listen: option.ListenAddress(netip.IPv4Unspecified()),
  22. ListenPort: otherPort,
  23. },
  24. Users: []auth.User{
  25. {
  26. Username: "sekai",
  27. Password: "password",
  28. },
  29. },
  30. Network: network.NetworkTCP,
  31. },
  32. },
  33. },
  34. })
  35. startDockerContainer(t, DockerOptions{
  36. Image: ImageNginx,
  37. Ports: []uint16{serverPort, otherPort},
  38. Bind: map[string]string{
  39. "nginx.conf": "/etc/nginx/nginx.conf",
  40. "naive-nginx.conf": "/etc/nginx/conf.d/naive.conf",
  41. certPem: "/etc/nginx/cert.pem",
  42. keyPem: "/etc/nginx/key.pem",
  43. },
  44. })
  45. startDockerContainer(t, DockerOptions{
  46. Image: ImageNaive,
  47. Ports: []uint16{serverPort, clientPort},
  48. Bind: map[string]string{
  49. "naive.json": "/etc/naiveproxy/config.json",
  50. caPem: "/etc/naiveproxy/ca.pem",
  51. },
  52. Env: []string{
  53. "SSL_CERT_FILE=/etc/naiveproxy/ca.pem",
  54. },
  55. })
  56. testTCP(t, clientPort, testPort)
  57. }
  58. func TestNaiveInbound(t *testing.T) {
  59. caPem, certPem, keyPem := createSelfSignedCertificate(t, "example.org")
  60. startInstance(t, option.Options{
  61. Log: &option.LogOptions{
  62. Level: "error",
  63. },
  64. Inbounds: []option.Inbound{
  65. {
  66. Type: C.TypeNaive,
  67. NaiveOptions: option.NaiveInboundOptions{
  68. ListenOptions: option.ListenOptions{
  69. Listen: option.ListenAddress(netip.IPv4Unspecified()),
  70. ListenPort: serverPort,
  71. },
  72. Users: []auth.User{
  73. {
  74. Username: "sekai",
  75. Password: "password",
  76. },
  77. },
  78. Network: network.NetworkTCP,
  79. TLS: &option.InboundTLSOptions{
  80. Enabled: true,
  81. ServerName: "example.org",
  82. CertificatePath: certPem,
  83. KeyPath: keyPem,
  84. },
  85. },
  86. },
  87. },
  88. })
  89. startDockerContainer(t, DockerOptions{
  90. Image: ImageNaive,
  91. Ports: []uint16{serverPort, clientPort},
  92. Bind: map[string]string{
  93. "naive.json": "/etc/naiveproxy/config.json",
  94. caPem: "/etc/naiveproxy/ca.pem",
  95. },
  96. Env: []string{
  97. "SSL_CERT_FILE=/etc/naiveproxy/ca.pem",
  98. },
  99. })
  100. testTCP(t, clientPort, testPort)
  101. }
  102. func TestNaiveHTTP3Inbound(t *testing.T) {
  103. if !C.QUIC_AVAILABLE {
  104. t.Skip("QUIC not included")
  105. }
  106. caPem, certPem, keyPem := createSelfSignedCertificate(t, "example.org")
  107. startInstance(t, option.Options{
  108. Log: &option.LogOptions{
  109. Level: "error",
  110. },
  111. Inbounds: []option.Inbound{
  112. {
  113. Type: C.TypeNaive,
  114. NaiveOptions: option.NaiveInboundOptions{
  115. ListenOptions: option.ListenOptions{
  116. Listen: option.ListenAddress(netip.IPv4Unspecified()),
  117. ListenPort: serverPort,
  118. },
  119. Users: []auth.User{
  120. {
  121. Username: "sekai",
  122. Password: "password",
  123. },
  124. },
  125. Network: network.NetworkUDP,
  126. TLS: &option.InboundTLSOptions{
  127. Enabled: true,
  128. ServerName: "example.org",
  129. CertificatePath: certPem,
  130. KeyPath: keyPem,
  131. },
  132. },
  133. },
  134. },
  135. })
  136. startDockerContainer(t, DockerOptions{
  137. Image: ImageNaive,
  138. Ports: []uint16{serverPort, clientPort},
  139. Bind: map[string]string{
  140. "naive-quic.json": "/etc/naiveproxy/config.json",
  141. caPem: "/etc/naiveproxy/ca.pem",
  142. },
  143. Env: []string{
  144. "SSL_CERT_FILE=/etc/naiveproxy/ca.pem",
  145. },
  146. })
  147. testTCP(t, clientPort, testPort)
  148. }