domain_inbound_test.go 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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. TLS: &option.InboundTLSOptions{
  38. Enabled: true,
  39. ServerName: "example.org",
  40. CertificatePath: certPem,
  41. KeyPath: keyPem,
  42. },
  43. },
  44. },
  45. },
  46. Outbounds: []option.Outbound{
  47. {
  48. Type: C.TypeDirect,
  49. },
  50. {
  51. Type: C.TypeTUIC,
  52. Tag: "tuic-out",
  53. TUICOptions: option.TUICOutboundOptions{
  54. ServerOptions: option.ServerOptions{
  55. Server: "127.0.0.1",
  56. ServerPort: serverPort,
  57. },
  58. UUID: uuid.Nil.String(),
  59. TLS: &option.OutboundTLSOptions{
  60. Enabled: true,
  61. ServerName: "example.org",
  62. CertificatePath: certPem,
  63. },
  64. },
  65. },
  66. },
  67. Route: &option.RouteOptions{
  68. Rules: []option.Rule{
  69. {
  70. DefaultOptions: option.DefaultRule{
  71. Inbound: []string{"mixed-in"},
  72. Outbound: "tuic-out",
  73. },
  74. },
  75. },
  76. },
  77. })
  78. testQUIC(t, clientPort)
  79. }