File size: 3,747 Bytes
c0e2219
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
"""

Юнит-тесты для regex-паттернов поиска URL в выводе туннельных утилит.

Тесты не требуют сети или реальных процессов.

"""
import re
import pytest


# Cloudflared───
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
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


# MMAR
@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


# Tunnelite
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'


# Beeceptor
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'


# Bore Digital──
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'


# SSH-провайдеры
@pytest.mark.parametrize('pattern, text, should_match', [

    # Optimistix

    (r'https://\S+\.otnl\.link',

     'Forwarding from https://tunnel-abc.otnl.link', True),



    # srv.us — минимум 10 символов в субдомене

    (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),



    # Serveo

    (r'https://\S+\.serveousercontent\.com',

     'Forwarding from https://mytunnel.serveousercontent.com', True),



    # localhost.run — admin исключён

    (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}'