File: conftest.py

package info (click to toggle)
python-aiohttp-proxy 0.1.1%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 148 kB
  • sloc: python: 735; makefile: 4
file content (55 lines) | stat: -rw-r--r-- 1,587 bytes parent folder | download | duplicates (2)
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
import platform
import os

# noinspection PyPackageRequirements
import pytest

from tests.utils import resolve_path, ProxyServer

LOGIN = 'admin'
PASSWORD = 'admin'

SOCKS5_IPV6_HOST = '::1'
SOCKS5_IPV6_PORT = 7780

SOCKS5_IPV4_HOST = '127.0.0.1'
SOCKS5_IPV4_PORT = 7780

SOCKS4_HOST = '127.0.0.1'
SOCKS4_PORT = 7781

SKIP_IPV6_TESTS = 'SKIP_IPV6_TESTS' in os.environ


@pytest.fixture(scope='session', autouse=True)
def proxy_server():
    system = platform.system().lower()
    config_path = resolve_path('./3proxy/cfg/3proxy.cfg')
    binary_path = resolve_path('./3proxy/bin/%s/3proxy' % system)

    with open(config_path, mode='w') as cfg:
        cfg.write('users %s:CL:%s\n' % (LOGIN, PASSWORD))

        if not SKIP_IPV6_TESTS:
            cfg.write('auth strong\n')
            cfg.write('socks -p%d -i%s\n' % (SOCKS5_IPV6_PORT,
                                             SOCKS5_IPV6_HOST))

        cfg.write('auth strong\n')
        cfg.write('socks -p%d -i%s\n' % (SOCKS5_IPV4_PORT, SOCKS5_IPV4_HOST))

        cfg.write('auth none\n')
        cfg.write('socks -p%d -i%s\n' % (SOCKS4_PORT, SOCKS4_HOST))

    server = ProxyServer(binary_path=binary_path, config_path=config_path)

    if not SKIP_IPV6_TESTS:
        server.wait_until_connectable(host=SOCKS5_IPV6_HOST,
                                      port=SOCKS5_IPV6_PORT)

    server.wait_until_connectable(host=SOCKS5_IPV4_HOST, port=SOCKS5_IPV4_PORT)
    server.wait_until_connectable(host=SOCKS4_HOST, port=SOCKS4_PORT)

    yield None

    server.kill()