domain_inbound_test.go 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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. },
  32. Users: []option.TUICUser{{
  33. UUID: uuid.Nil.String(),
  34. }},
  35. InboundTLSOptionsContainer: option.InboundTLSOptionsContainer{
  36. TLS: &option.InboundTLSOptions{
  37. Enabled: true,
  38. ServerName: "example.org",
  39. CertificatePath: certPem,
  40. KeyPath: keyPem,
  41. },
  42. },
  43. },
  44. },
  45. },
  46. Outbounds: []option.Outbound{
  47. {
  48. Type: C.TypeDirect,
  49. },
  50. {
  51. Type: C.TypeTUIC,
  52. Tag: "tuic-out",
  53. Options: &option.TUICOutboundOptions{
  54. ServerOptions: option.ServerOptions{
  55. Server: "127.0.0.1",
  56. ServerPort: serverPort,
  57. },
  58. UUID: uuid.Nil.String(),
  59. OutboundTLSOptionsContainer: option.OutboundTLSOptionsContainer{
  60. TLS: &option.OutboundTLSOptions{
  61. Enabled: true,
  62. ServerName: "example.org",
  63. CertificatePath: certPem,
  64. },
  65. },
  66. },
  67. },
  68. },
  69. Route: &option.RouteOptions{
  70. Rules: []option.Rule{
  71. {
  72. Type: C.RuleTypeDefault,
  73. DefaultOptions: option.DefaultRule{
  74. RawDefaultRule: option.RawDefaultRule{
  75. Inbound: []string{"mixed-in"},
  76. },
  77. RuleAction: option.RuleAction{
  78. Action: C.RuleActionTypeRoute,
  79. RouteOptions: option.RouteActionOptions{
  80. Outbound: "tuic-out",
  81. },
  82. },
  83. },
  84. },
  85. },
  86. },
  87. })
  88. testQUIC(t, clientPort)
  89. }