44 lines
1.2 KiB
TypeScript
44 lines
1.2 KiB
TypeScript
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(
|
|
'логином и паролем',
|
|
);
|
|
});
|
|
});
|