| """
|
| Юнит-тесты для regex-паттернов поиска URL в выводе туннельных утилит.
|
| Тесты не требуют сети или реальных процессов.
|
| """
|
| import re
|
| import pytest
|
|
|
|
|
|
|
| CF_PATTERN = r'(?P<url>https?://\S+\.trycloudflare\.com)'
|
|
|
| @pytest.mark.parametrize('text, expected', [
|
| (
|
| 'Visit your tunnel at https://autumn-bread-1234.trycloudflare.com',
|
| 'https://autumn-bread-1234.trycloudflare.com',
|
| ),
|
| (
|
| 'https://my-test.trycloudflare.com is ready',
|
| 'https://my-test.trycloudflare.com',
|
| ),
|
| ])
|
| def test_cloudflared(text: str, expected: str) -> None:
|
| m = re.search(CF_PATTERN, text)
|
| assert m is not None, f'Паттерн не нашёл URL в: {text!r}'
|
| assert m.group() == expected
|
|
|
|
|
|
|
| BORE_PATTERN = r'bore\.pub:\d+'
|
|
|
| @pytest.mark.parametrize('text, expected', [
|
| ('INFO bore::client: listening at bore.pub:12345', 'bore.pub:12345'),
|
| ('connected to bore.pub:54321 successfully', 'bore.pub:54321'),
|
| ])
|
| def test_bore(text: str, expected: str) -> None:
|
| m = re.search(BORE_PATTERN, text)
|
| assert m is not None
|
| assert m.group() == expected
|
|
|
|
|
|
|
| @pytest.mark.parametrize('text, expected', [
|
| ('Tunnel at https://abc123.mmar.dev', 'https://abc123.mmar.dev'),
|
| ('http://test-tunnel.mmar.dev/ active', 'http://test-tunnel.mmar.dev/'),
|
| ])
|
| def test_mmar(text: str, expected: str) -> None:
|
| m = re.search(r'(?P<url>https?://\S+\.mmar\.dev)', text)
|
| assert m is not None
|
| assert m.group() == expected
|
|
|
|
|
|
|
| def test_tunnelite() -> None:
|
| text = 'Your public URL: https://random-words.tunnelite.com'
|
| m = re.search(r'(?P<url>https?://\S+\.tunnelite\.com)', text)
|
| assert m is not None
|
| assert m.group() == 'https://random-words.tunnelite.com'
|
|
|
|
|
|
|
| def test_beeceptor() -> None:
|
| text = 'Tunnel running at https://my-endpoint.beeceptor.com'
|
| m = re.search(r'(?P<url>https?://\S+\.beeceptor\.com)', text)
|
| assert m is not None
|
| assert m.group() == 'https://my-endpoint.beeceptor.com'
|
|
|
|
|
|
|
| def test_boredigital() -> None:
|
| text = '| https://xyz123.bore.digital | active |'
|
| m = re.search(r'(?P<url>https://\S+\.bore\.digital)', text)
|
| assert m is not None
|
| assert m.group() == 'https://xyz123.bore.digital'
|
|
|
|
|
|
|
| @pytest.mark.parametrize('pattern, text, should_match', [
|
|
|
| (r'https://\S+\.otnl\.link',
|
| 'Forwarding from https://tunnel-abc.otnl.link', True),
|
|
|
|
|
| (r'https://[a-z0-9]{10,}\.srv\.us/?',
|
| 'https://abcdefghij.srv.us', True),
|
| (r'https://[a-z0-9]{10,}\.srv\.us/?',
|
| 'https://short.srv.us', False),
|
|
|
|
|
| (r'https://\S+\.serveousercontent\.com',
|
| 'Forwarding from https://mytunnel.serveousercontent.com', True),
|
|
|
|
|
| (r'https://(?!admin\b)[a-zA-Z0-9-]+\.(?:localhost\.run|lhr\.life)',
|
| 'https://abc123.localhost.run', True),
|
| (r'https://(?!admin\b)[a-zA-Z0-9-]+\.(?:localhost\.run|lhr\.life)',
|
| 'https://admin.localhost.run', False),
|
| (r'https://(?!admin\b)[a-zA-Z0-9-]+\.(?:localhost\.run|lhr\.life)',
|
| 'https://my-tunnel.lhr.life', True),
|
| ])
|
| def test_ssh_patterns(pattern: str, text: str, should_match: bool) -> None:
|
| m = re.search(pattern, text)
|
| if should_match:
|
| assert m is not None, f'{pattern!r} не нашёл совпадение в {text!r}'
|
| else:
|
| assert m is None, f'{pattern!r} не должен совпадать с {text!r}'
|
|
|