inbound_protocol_masque_test.go 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. package service
  2. import (
  3. "strings"
  4. "testing"
  5. "github.com/mhsanaei/3x-ui/v3/internal/database"
  6. "github.com/mhsanaei/3x-ui/v3/internal/database/model"
  7. )
  8. // MASQUE is native Xray, so a node runs it, but a node panel older than the release
  9. // that knows it would hand the clients' "password" to a core that reads "pass".
  10. func TestCheckNodeCanHostProtocol_Masque(t *testing.T) {
  11. setupConflictDB(t)
  12. tests := []struct {
  13. version string
  14. wantErr string
  15. }{
  16. {"v3.9.0", "need v3.9.1 or newer"},
  17. {"v3.9.1", ""},
  18. {"dev+1d1128cf", ""},
  19. }
  20. for i, tc := range tests {
  21. t.Run(tc.version, func(t *testing.T) {
  22. node := &model.Node{Name: "masque-node-" + tc.version, Address: "127.0.0.1", Port: 2096 + i, PanelVersion: tc.version}
  23. if err := database.GetDB().Create(node).Error; err != nil {
  24. t.Fatalf("create node: %v", err)
  25. }
  26. err := checkNodeCanHostProtocol(database.GetDB(), node.Id, model.MASQUE)
  27. if tc.wantErr == "" {
  28. if err != nil {
  29. t.Fatalf("node on %s refused MASQUE: %v", tc.version, err)
  30. }
  31. return
  32. }
  33. if err == nil || !strings.Contains(err.Error(), tc.wantErr) {
  34. t.Fatalf("node on %s: err = %v, want one containing %q", tc.version, err, tc.wantErr)
  35. }
  36. })
  37. }
  38. }