reality_test.go 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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 TestReality(t *testing.T) {
  12. user, _ := uuid.NewV4()
  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.TypeVLESS,
  27. Options: &option.VLESSInboundOptions{
  28. ListenOptions: option.ListenOptions{
  29. Listen: common.Ptr(badoption.Addr(netip.IPv4Unspecified())),
  30. ListenPort: serverPort,
  31. },
  32. Users: []option.VLESSUser{{UUID: user.String()}},
  33. InboundTLSOptionsContainer: option.InboundTLSOptionsContainer{
  34. TLS: &option.InboundTLSOptions{
  35. Enabled: true,
  36. ServerName: "google.com",
  37. Reality: &option.InboundRealityOptions{
  38. Enabled: true,
  39. Handshake: option.InboundRealityHandshakeOptions{
  40. ServerOptions: option.ServerOptions{
  41. Server: "google.com",
  42. ServerPort: 443,
  43. },
  44. },
  45. ShortID: []string{"0123456789abcdef"},
  46. PrivateKey: "UuMBgl7MXTPx9inmQp2UC7Jcnwc6XYbwDNebonM-FCc",
  47. },
  48. },
  49. },
  50. },
  51. },
  52. },
  53. Outbounds: []option.Outbound{
  54. {
  55. Type: C.TypeDirect,
  56. },
  57. {
  58. Type: C.TypeVLESS,
  59. Tag: "ss-out",
  60. Options: &option.VLESSOutboundOptions{
  61. ServerOptions: option.ServerOptions{
  62. Server: "127.0.0.1",
  63. ServerPort: serverPort,
  64. },
  65. UUID: user.String(),
  66. OutboundTLSOptionsContainer: option.OutboundTLSOptionsContainer{
  67. TLS: &option.OutboundTLSOptions{
  68. Enabled: true,
  69. ServerName: "google.com",
  70. Reality: &option.OutboundRealityOptions{
  71. Enabled: true,
  72. ShortID: "0123456789abcdef",
  73. PublicKey: "jNXHt1yRo0vDuchQlIP6Z0ZvjT3KtzVI-T4E7RoLJS0",
  74. },
  75. UTLS: &option.OutboundUTLSOptions{
  76. Enabled: true,
  77. },
  78. },
  79. },
  80. },
  81. },
  82. },
  83. Route: &option.RouteOptions{
  84. Rules: []option.Rule{
  85. {
  86. Type: C.RuleTypeDefault,
  87. DefaultOptions: option.DefaultRule{
  88. RawDefaultRule: option.RawDefaultRule{
  89. Inbound: []string{"mixed-in"},
  90. },
  91. RuleAction: option.RuleAction{
  92. Action: C.RuleActionTypeRoute,
  93. RouteOptions: option.RouteActionOptions{
  94. Outbound: "ss-out",
  95. },
  96. },
  97. },
  98. },
  99. },
  100. },
  101. })
  102. testSuit(t, clientPort, testPort)
  103. }