del_shared_email_runtime_test.go 1.2 KB

12345678910111213141516171819202122232425262728293031323334
  1. package service
  2. import (
  3. "testing"
  4. "github.com/google/uuid"
  5. "github.com/mhsanaei/3x-ui/v3/internal/database/model"
  6. )
  7. // Deleting a client that is attached to more than one inbound must still remove
  8. // the user from the running runtime of the inbound being deleted from. The
  9. // runtime user is keyed by inbound tag, so a sibling inbound still carrying the
  10. // same email (emailShared) must not suppress the per-inbound runtime removal —
  11. // otherwise the deleted user keeps connecting on that inbound until Xray
  12. // restart (#5543).
  13. func TestDelInboundClientByEmail_SharedEmailStillRemovesFromRuntime(t *testing.T) {
  14. setupBulkDB(t)
  15. nodeID, fake := setupNodeRuntime(t)
  16. shared := []model.Client{{ID: uuid.NewString(), Email: "shared@x", Enable: true}}
  17. ibA := nodeInbound(t, nodeID, 31001, shared)
  18. nodeInbound(t, nodeID, 31002, shared)
  19. svc := &ClientService{}
  20. inboundSvc := &InboundService{}
  21. if _, err := svc.DelInboundClientByEmail(inboundSvc, ibA.Id, "shared@x", false); err != nil {
  22. t.Fatalf("DelInboundClientByEmail: %v", err)
  23. }
  24. if got := fake.deleteUser.Load(); got != 1 {
  25. t.Fatalf("shared-email delete dispatched %d DeleteUser RPCs, want 1 (must remove from the deleted inbound's runtime despite the sibling inbound) (#5543)", got)
  26. }
  27. }