limit_ip_disconnect_test.go 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. package job
  2. import (
  3. "strings"
  4. "testing"
  5. "github.com/mhsanaei/3x-ui/v3/internal/database/model"
  6. "github.com/mhsanaei/3x-ui/v3/internal/logger"
  7. )
  8. // The protocol gate must let hysteria through: XrayAPI supports it, and the
  9. // skip left over-limit Hysteria2 sessions alive until the fail2ban ban caught up.
  10. func TestDisconnectClientTemporarilyAllowsHysteria(t *testing.T) {
  11. setupIntegrationDB(t)
  12. const email = "hy2-limit-probe"
  13. inbound := &model.Inbound{
  14. Id: 1,
  15. Protocol: model.Hysteria,
  16. Tag: "hy2-limit-probe-tag",
  17. Settings: `{"clients":[]}`,
  18. }
  19. clients := []model.Client{{Email: email, Auth: "secret"}}
  20. (&CheckClientIpJob{}).disconnectClientTemporarily(inbound, email, clients)
  21. var unsupported, attempted bool
  22. for _, line := range logger.GetLogs(500, "warning") {
  23. if strings.Contains(line, "Temporary disconnect is not supported for protocol hysteria") {
  24. unsupported = true
  25. }
  26. if strings.Contains(line, "Failed to remove user "+email) {
  27. attempted = true
  28. }
  29. }
  30. if unsupported {
  31. t.Fatal("hysteria was rejected by the protocol gate")
  32. }
  33. if !attempted {
  34. t.Fatal("expected a remove attempt against the Xray API for hysteria")
  35. }
  36. }