Refactor ProxyWarden routing and settings flow

This commit is contained in:
2026-07-09 11:51:16 +03:00
parent db0c1dede9
commit 1bb795a532
18 changed files with 1018 additions and 210 deletions

View File

@@ -0,0 +1,43 @@
import { describe, expect, it } from 'vitest';
import { parseProxy } from './parseProxy';
describe('parseProxy', () => {
it('parses host and port without explicit protocol', () => {
expect(parseProxy('proxy.example.test:1080')).toEqual({
protocol: 'socks5',
host: 'proxy.example.test',
port: 1080,
});
});
it('parses socks5 URLs', () => {
expect(parseProxy('socks5://127.0.0.1:1080')).toEqual({
protocol: 'socks5',
host: '127.0.0.1',
port: 1080,
});
});
it('parses bracketed IPv6 hosts', () => {
expect(parseProxy('socks5://[::1]:1080')).toEqual({
protocol: 'socks5',
host: '::1',
port: 1080,
});
});
it('rejects unsupported schemes', () => {
expect(() => parseProxy('http://proxy.example.test:8080')).toThrow('SOCKS5');
});
it('rejects missing or invalid ports', () => {
expect(() => parseProxy('proxy.example.test')).toThrow('хост и порт');
expect(() => parseProxy('proxy.example.test:70000')).toThrow('Формат');
});
it('rejects userinfo credentials', () => {
expect(() => parseProxy('socks5://user:password@proxy.example.test:1080')).toThrow(
'логином и паролем',
);
});
});