naive_test.go 3.7 KB

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