domain_inbound_test.go 2.3 KB

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