naive_test.go 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  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.ListenAddress(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.ListenAddress(netip.IPv4Unspecified()),
  64. ListenPort: serverPort,
  65. },
  66. Users: []auth.User{
  67. {
  68. Username: "sekai",
  69. Password: "password",
  70. },
  71. },
  72. Network: network.NetworkTCP,
  73. TLS: &option.InboundTLSOptions{
  74. Enabled: true,
  75. ServerName: "example.org",
  76. CertificatePath: certPem,
  77. KeyPath: keyPem,
  78. },
  79. },
  80. },
  81. },
  82. })
  83. startDockerContainer(t, DockerOptions{
  84. Image: ImageNaive,
  85. Ports: []uint16{serverPort, clientPort},
  86. Bind: map[string]string{
  87. "naive.json": "/etc/naiveproxy/config.json",
  88. caPem: "/etc/naiveproxy/ca.pem",
  89. },
  90. Env: []string{
  91. "SSL_CERT_FILE=/etc/naiveproxy/ca.pem",
  92. },
  93. })
  94. testTCP(t, clientPort, testPort)
  95. }
  96. func TestNaiveHTTP3Inbound(t *testing.T) {
  97. caPem, certPem, keyPem := createSelfSignedCertificate(t, "example.org")
  98. startInstance(t, option.Options{
  99. Inbounds: []option.Inbound{
  100. {
  101. Type: C.TypeNaive,
  102. NaiveOptions: option.NaiveInboundOptions{
  103. ListenOptions: option.ListenOptions{
  104. Listen: option.ListenAddress(netip.IPv4Unspecified()),
  105. ListenPort: serverPort,
  106. },
  107. Users: []auth.User{
  108. {
  109. Username: "sekai",
  110. Password: "password",
  111. },
  112. },
  113. Network: network.NetworkUDP,
  114. TLS: &option.InboundTLSOptions{
  115. Enabled: true,
  116. ServerName: "example.org",
  117. CertificatePath: certPem,
  118. KeyPath: keyPem,
  119. },
  120. },
  121. },
  122. },
  123. })
  124. startDockerContainer(t, DockerOptions{
  125. Image: ImageNaive,
  126. Ports: []uint16{serverPort, clientPort},
  127. Bind: map[string]string{
  128. "naive-quic.json": "/etc/naiveproxy/config.json",
  129. caPem: "/etc/naiveproxy/ca.pem",
  130. },
  131. Env: []string{
  132. "SSL_CERT_FILE=/etc/naiveproxy/ca.pem",
  133. },
  134. })
  135. testTCP(t, clientPort, testPort)
  136. }