1
0

export_all_links_test.go 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. package sub
  2. import (
  3. "strings"
  4. "testing"
  5. "github.com/mhsanaei/3x-ui/v3/internal/database"
  6. "github.com/mhsanaei/3x-ui/v3/internal/database/model"
  7. )
  8. // inboundLinks (the "Export all inbound links" path) must render the remark
  9. // template's whole Client token group per client, name-only — the same engine
  10. // the client/QR pages use.
  11. func TestInboundLinks_RemarkTemplateClientTokens(t *testing.T) {
  12. seedSubDB(t)
  13. db := database.GetDB()
  14. settings := `{"clients":[{"id":"11111111-2222-4333-8444-000000000001","email":"john@e","subId":"subABC","comment":"vip","tgId":777,"enable":true}],"decryption":"none"}`
  15. ib := &model.Inbound{
  16. UserId: 1, Tag: "t", Enable: true, Listen: "203.0.113.5", Port: 4431,
  17. Protocol: model.VLESS, Remark: "Germany", Settings: settings,
  18. StreamSettings: `{"network":"ws","security":"tls","wsSettings":{"path":"/","host":""},"tlsSettings":{"serverName":"sni"}}`,
  19. }
  20. if err := db.Create(ib).Error; err != nil {
  21. t.Fatalf("seed inbound: %v", err)
  22. }
  23. svc := NewSubService("{{INBOUND}}-{{EMAIL}}-{{COMMENT}}-{{SUB_ID}}-{{TELEGRAM_ID}}-{{SHORT_ID}}|📊{{TRAFFIC_LEFT}}|⏳{{DAYS_LEFT}}D")
  24. svc.PrepareForRequest("req.example.com")
  25. links := svc.inboundLinks(ib)
  26. if len(links) != 1 {
  27. t.Fatalf("links = %d, want 1: %v", len(links), links)
  28. }
  29. frag := links[0]
  30. for _, want := range []string{"Germany-john", "vip", "subABC", "777", "11111111"} {
  31. if !strings.Contains(frag, want) {
  32. t.Fatalf("remark missing client token %q: %s", want, frag)
  33. }
  34. }
  35. if strings.Contains(frag, "GB") || strings.ContainsRune(frag, '⏳') {
  36. t.Fatalf("display mode must drop the traffic/expiry segments: %s", frag)
  37. }
  38. }