domain_inbound_test.go 2.3 KB

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