Files
3x-ui/internal/web/service/del_shared_email_runtime_test.go
T
MHSanaei b1fa76f9b6 fix(node): fully delete clients on nodes instead of only detaching them
Deleting a client on the master propagated to nodes via the detach
endpoint, which removes the client from that one inbound's settings but
deliberately keeps the client record. The node ended up with an
orphaned record that kept showing in its Clients view; the master and
node could never converge on a delete.

Full-delete and detach intent now travel separately: the Runtime
interface gains DeleteClient, which on Remote hits the node's
panel/api/clients/del endpoint (record, attachments, traffic; repeat
calls for a client on several inbounds of the same node are swallowed
as idempotent "not found"). Delete/DeleteByEmail/BulkDelete use it for
node inbounds, while Detach/BulkDetach keep the inbound-scoped detach
RPC so removing a client from one inbound never wipes it node-wide
(the #5543 guarantee is preserved and covered by tests). Bulk deletes
above the fold threshold still converge membership via reconcile; their
leftover node records can be cleaned with the node's delete-orphans
action.

Closes #5797
2026-07-05 20:28:26 +02:00

36 lines
1.2 KiB
Go

package service
import (
"testing"
"github.com/google/uuid"
"github.com/mhsanaei/3x-ui/v3/internal/database/model"
)
// Deleting a client that is attached to more than one inbound must still remove
// the user from the running runtime of the inbound being deleted from. The
// runtime user is keyed by inbound tag, so a sibling inbound still carrying the
// same email (emailShared) must not suppress the per-inbound runtime removal —
// otherwise the deleted user keeps connecting on that inbound until Xray
// restart (#5543).
func TestDelInboundClientByEmail_SharedEmailStillRemovesFromRuntime(t *testing.T) {
setupBulkDB(t)
nodeID, fake := setupNodeRuntime(t)
shared := []model.Client{{ID: uuid.NewString(), Email: "shared@x", Enable: true}}
ibA := nodeInbound(t, nodeID, 31001, shared)
nodeInbound(t, nodeID, 31002, shared)
svc := &ClientService{}
inboundSvc := &InboundService{}
if _, err := svc.DelInboundClientByEmail(inboundSvc, ibA.Id, "shared@x", false, false); err != nil {
t.Fatalf("DelInboundClientByEmail: %v", err)
}
if got := fake.deleteUser.Load(); got != 1 {
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)
}
}