spider-x.test.ts 1.2 KB

123456789101112131415161718192021222324252627
  1. import { describe, expect, it } from 'vitest';
  2. import { deriveSpiderX } from '@/lib/xray/spider-x';
  3. // Cross-language vectors shared with TestDeriveSpiderXMatchesFrontendVectors
  4. // in internal/sub/service_sharelink_test.go: subscription links come from Go,
  5. // panel links from this module, and the two must agree byte-for-byte.
  6. describe('deriveSpiderX', () => {
  7. it('matches the Go deriveSpiderX vectors', () => {
  8. expect(deriveSpiderX('/seed', 'subAlice')).toBe('/c252fbc3ecd3e3c');
  9. expect(deriveSpiderX('/', '')).toBe('/d08ed99bd9afc60');
  10. });
  11. it('is stable per client, distinct across clients, and rotates with the seed', () => {
  12. expect(deriveSpiderX('/seed', 'subAlice')).toBe(deriveSpiderX('/seed', 'subAlice'));
  13. expect(deriveSpiderX('/seed', 'subAlice')).not.toBe(deriveSpiderX('/seed', 'subBob'));
  14. expect(deriveSpiderX('/seedA', 'subAlice')).not.toBe(deriveSpiderX('/seedB', 'subAlice'));
  15. });
  16. it('returns empty when there is nothing to derive from', () => {
  17. expect(deriveSpiderX('', '')).toBe('');
  18. });
  19. it('emits a /-prefixed 15-hex-char path', () => {
  20. expect(deriveSpiderX('/some-seed', '[email protected]')).toMatch(/^\/[0-9a-f]{15}$/);
  21. });
  22. });