client_delete_node_full_test.go 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. package service
  2. import (
  3. "testing"
  4. "github.com/google/uuid"
  5. "github.com/mhsanaei/3x-ui/v3/internal/database/model"
  6. )
  7. // A full client delete must reach the node as the full-delete RPC so the node
  8. // drops its own client record too — the detach RPC leaves an orphaned record
  9. // that keeps showing in the node's client list (#5797).
  10. func TestDelete_NodeClientDispatchesFullDeleteRPC(t *testing.T) {
  11. setupBulkDB(t)
  12. nodeID, fake := setupNodeRuntime(t)
  13. clients := []model.Client{{ID: uuid.NewString(), Email: "full-del@x", Enable: true}}
  14. nodeInbound(t, nodeID, 32001, clients)
  15. svc := &ClientService{}
  16. inboundSvc := &InboundService{}
  17. rec, err := svc.GetRecordByEmail(nil, "full-del@x")
  18. if err != nil {
  19. t.Fatalf("GetRecordByEmail: %v", err)
  20. }
  21. if _, err := svc.Delete(inboundSvc, rec.Id, false); err != nil {
  22. t.Fatalf("Delete: %v", err)
  23. }
  24. if got := fake.deleteClient.Load(); got != 1 {
  25. t.Fatalf("full delete dispatched %d DeleteClient RPCs, want 1", got)
  26. }
  27. if got := fake.deleteUser.Load(); got != 0 {
  28. t.Fatalf("full delete dispatched %d DeleteUser (detach) RPCs, want 0", got)
  29. }
  30. }
  31. // A plain detach must stay scoped to the one inbound via the detach RPC and
  32. // never escalate to the node-wide full delete.
  33. func TestDetach_NodeClientStaysOnDetachRPC(t *testing.T) {
  34. setupBulkDB(t)
  35. nodeID, fake := setupNodeRuntime(t)
  36. clients := []model.Client{{ID: uuid.NewString(), Email: "detach-me@x", Enable: true}}
  37. ib := nodeInbound(t, nodeID, 32002, clients)
  38. svc := &ClientService{}
  39. inboundSvc := &InboundService{}
  40. rec, err := svc.GetRecordByEmail(nil, "detach-me@x")
  41. if err != nil {
  42. t.Fatalf("GetRecordByEmail: %v", err)
  43. }
  44. if _, err := svc.Detach(inboundSvc, rec.Id, []int{ib.Id}); err != nil {
  45. t.Fatalf("Detach: %v", err)
  46. }
  47. if got := fake.deleteUser.Load(); got != 1 {
  48. t.Fatalf("detach dispatched %d DeleteUser RPCs, want 1", got)
  49. }
  50. if got := fake.deleteClient.Load(); got != 0 {
  51. t.Fatalf("detach dispatched %d DeleteClient RPCs, want 0", got)
  52. }
  53. }