domain_inbound_test.go 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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. dns "github.com/sagernet/sing-dns"
  8. "github.com/gofrs/uuid/v5"
  9. )
  10. func TestTUICDomainUDP(t *testing.T) {
  11. _, certPem, keyPem := createSelfSignedCertificate(t, "example.org")
  12. startInstance(t, option.Options{
  13. Inbounds: []option.Inbound{
  14. {
  15. Type: C.TypeMixed,
  16. Tag: "mixed-in",
  17. MixedOptions: option.HTTPMixedInboundOptions{
  18. ListenOptions: option.ListenOptions{
  19. Listen: option.NewListenAddress(netip.IPv4Unspecified()),
  20. ListenPort: clientPort,
  21. },
  22. },
  23. },
  24. {
  25. Type: C.TypeTUIC,
  26. TUICOptions: option.TUICInboundOptions{
  27. ListenOptions: option.ListenOptions{
  28. Listen: option.NewListenAddress(netip.IPv4Unspecified()),
  29. ListenPort: serverPort,
  30. InboundOptions: option.InboundOptions{
  31. DomainStrategy: option.DomainStrategy(dns.DomainStrategyUseIPv6),
  32. },
  33. },
  34. Users: []option.TUICUser{{
  35. UUID: uuid.Nil.String(),
  36. }},
  37. InboundTLSOptionsContainer: option.InboundTLSOptionsContainer{
  38. TLS: &option.InboundTLSOptions{
  39. Enabled: true,
  40. ServerName: "example.org",
  41. CertificatePath: certPem,
  42. KeyPath: keyPem,
  43. },
  44. },
  45. },
  46. },
  47. },
  48. Outbounds: []option.Outbound{
  49. {
  50. Type: C.TypeDirect,
  51. },
  52. {
  53. Type: C.TypeTUIC,
  54. Tag: "tuic-out",
  55. TUICOptions: option.TUICOutboundOptions{
  56. ServerOptions: option.ServerOptions{
  57. Server: "127.0.0.1",
  58. ServerPort: serverPort,
  59. },
  60. UUID: uuid.Nil.String(),
  61. OutboundTLSOptionsContainer: option.OutboundTLSOptionsContainer{
  62. TLS: &option.OutboundTLSOptions{
  63. Enabled: true,
  64. ServerName: "example.org",
  65. CertificatePath: certPem,
  66. },
  67. },
  68. },
  69. },
  70. },
  71. Route: &option.RouteOptions{
  72. Rules: []option.Rule{
  73. {
  74. DefaultOptions: option.DefaultRule{
  75. Inbound: []string{"mixed-in"},
  76. Outbound: "tuic-out",
  77. },
  78. },
  79. },
  80. },
  81. })
  82. testQUIC(t, clientPort)
  83. }