mtproto-clients-link.test.ts 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. import { describe, expect, it } from 'vitest';
  2. import { genInboundLinks } from '@/lib/xray/inbound-link';
  3. import { InboundSchema } from '@/schemas/api/inbound';
  4. // Multi-client MTProto renders one tg://proxy deep link per entry in
  5. // settings.clients, each carrying that client's own FakeTLS secret.
  6. function mtprotoInbound() {
  7. return InboundSchema.parse({
  8. id: 70,
  9. remark: 'mt-mc',
  10. port: 8443,
  11. protocol: 'mtproto',
  12. settings: {
  13. fakeTlsDomain: 'www.cloudflare.com',
  14. clients: [
  15. {
  16. email: 'alice',
  17. secret: 'ee0123456789abcdef0123456789abcdef7777772e636c6f7564666c6172652e636f6d',
  18. enable: true,
  19. },
  20. {
  21. email: 'bob',
  22. secret: 'eeabcdefabcdefabcdefabcdefabcdef01676f6f676c652e636f6d',
  23. enable: true,
  24. },
  25. ],
  26. },
  27. });
  28. }
  29. describe('mtproto multi-client link fan-out', () => {
  30. it('emits one tg://proxy per client from settings.clients', () => {
  31. const out = genInboundLinks({ inbound: mtprotoInbound(), remark: 'mt-mc', fallbackHostname: 'mt.example.test' });
  32. const links = out.split('\r\n').filter(Boolean);
  33. expect(links).toHaveLength(2);
  34. expect(links[0]).toContain('tg://proxy');
  35. expect(links[0]).toContain('secret=ee0123456789abcdef0123456789abcdef7777772e636c6f7564666c6172652e636f6d');
  36. expect(links[1]).toContain('secret=eeabcdefabcdefabcdefabcdefabcdef01676f6f676c652e636f6d');
  37. expect(links[0]).not.toContain('#');
  38. expect(links[1]).not.toContain('#');
  39. });
  40. });