CI / go-test (push) Canceled after 0s
CI / postgres-durable-first (push) Canceled after 0s
CI / codegen (push) Canceled after 0s
CI / govulncheck (push) Canceled after 0s
CI / race (push) Canceled after 0s
CI / fuzz-smoke (push) Canceled after 0s
CI / golangci (push) Canceled after 0s
CI / frontend (push) Canceled after 0s
CodeQL Advanced / Analyze (go) (push) Canceled after 0s
CodeQL Advanced / Analyze (actions) (push) Canceled after 0s
CodeQL Advanced / Analyze (javascript-typescript) (push) Canceled after 0s
Docs CI / build (push) Canceled after 0s
Docs Deploy (GitHub Pages) / build (push) Canceled after 0s
Release 3X-UI / build (386) (push) Canceled after 0s
Release 3X-UI / build (amd64) (push) Canceled after 0s
Release 3X-UI / build (arm64) (push) Canceled after 0s
Release 3X-UI / build (armv5) (push) Canceled after 0s
Release 3X-UI / build (armv6) (push) Canceled after 0s
Release 3X-UI / build (armv7) (push) Canceled after 0s
Release 3X-UI / build (s390x) (push) Canceled after 0s
Release 3X-UI / Build for Windows (amd64) (push) Canceled after 0s
Deploy Smoke Tests / noninteractive-install (ubuntu-24.04-arm) (push) Canceled after 0s
Deploy Smoke Tests / noninteractive-install (ubuntu-latest) (push) Canceled after 0s
Deploy Smoke Tests / release-tag-install (ubuntu-24.04-arm) (push) Canceled after 0s
Deploy Smoke Tests / release-tag-install (ubuntu-latest) (push) Canceled after 0s
Docs Deploy (GitHub Pages) / deploy (push) Canceled after 0s
Release 3X-UI / Publish rolling dev release (push) Canceled after 0s
68 lines
2.2 KiB
Go
68 lines
2.2 KiB
Go
package service
|
|
|
|
import (
|
|
"strings"
|
|
"testing"
|
|
|
|
"github.com/mhsanaei/3x-ui/v3/internal/database/model"
|
|
"github.com/mhsanaei/3x-ui/v3/internal/mtproto"
|
|
"github.com/mhsanaei/3x-ui/v3/internal/web/runtime"
|
|
)
|
|
|
|
func TestClientCrudMtprotoAppliesImmediately(t *testing.T) {
|
|
setupConflictDB(t)
|
|
pidFile := installFakeMtg(t)
|
|
runtime.SetManager(runtime.NewManager(runtime.LocalDeps{APIPort: func() int { return 0 }}))
|
|
t.Cleanup(func() { runtime.SetManager(nil) })
|
|
|
|
inboundSvc := &InboundService{}
|
|
clientSvc := &ClientService{}
|
|
|
|
created, _, err := inboundSvc.AddInbound(&model.Inbound{
|
|
Enable: true,
|
|
Listen: "",
|
|
Port: 46201,
|
|
Protocol: model.MTProto,
|
|
Settings: `{"clients":[{"email":"first","secret":"` + mtprotoTestSecretA + `","enable":true}]}`,
|
|
})
|
|
if err != nil {
|
|
t.Fatalf("AddInbound: %v", err)
|
|
}
|
|
t.Cleanup(func() { mtproto.GetManager().Remove(created.Id) })
|
|
waitForSpawns(t, pidFile, 1)
|
|
|
|
t.Run("add client rewrites the served config", func(t *testing.T) {
|
|
payload := &model.Inbound{
|
|
Id: created.Id,
|
|
Settings: `{"clients":[{"email":"second","secret":"` + mtprotoTestSecretB + `","enable":true}]}`,
|
|
}
|
|
needRestart, err := clientSvc.AddInboundClient(inboundSvc, payload)
|
|
if err != nil {
|
|
t.Fatalf("AddInboundClient: %v", err)
|
|
}
|
|
if needRestart {
|
|
t.Fatal("adding an mtproto client must not request an xray restart")
|
|
}
|
|
cfg := readMtgConfig(t, created.Id)
|
|
if !strings.Contains(cfg, `"second" = "`+mtprotoTestSecretB+`"`) {
|
|
t.Fatalf("new client must be in the served config:\n%s", cfg)
|
|
}
|
|
if !strings.Contains(cfg, `"first" = "`+mtprotoTestSecretA+`"`) {
|
|
t.Fatalf("existing client must remain served:\n%s", cfg)
|
|
}
|
|
})
|
|
|
|
t.Run("delete client drops it from the served config", func(t *testing.T) {
|
|
if _, err := clientSvc.DelInboundClientByEmail(inboundSvc, created.Id, "second", false, true); err != nil {
|
|
t.Fatalf("DelInboundClientByEmail: %v", err)
|
|
}
|
|
cfg := readMtgConfig(t, created.Id)
|
|
if strings.Contains(cfg, mtprotoTestSecretB) {
|
|
t.Fatalf("deleted client must leave the served config:\n%s", cfg)
|
|
}
|
|
if !strings.Contains(cfg, mtprotoTestSecretA) {
|
|
t.Fatalf("surviving client must stay served:\n%s", cfg)
|
|
}
|
|
})
|
|
}
|