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
|
# SPDX-License-Identifier: GPL-3.0-or-later
import socket
import pytest
from kresd import init_portdir, make_kresd
@pytest.fixture
def kresd(tmpdir):
with make_kresd(tmpdir) as kresd:
yield kresd
@pytest.fixture
def kresd_silent(tmpdir):
with make_kresd(tmpdir, verbose=False) as kresd:
yield kresd
@pytest.fixture
def kresd_tt(tmpdir):
with make_kresd(tmpdir, 'tt') as kresd:
yield kresd
@pytest.fixture(params=[
'ip_tcp_socket',
'ip6_tcp_socket',
'ip_tls_socket',
'ip6_tls_socket',
])
def make_kresd_sock(request, kresd):
"""Factory function to create sockets of the same kind."""
sock_func = getattr(kresd, request.param)
def _make_kresd_sock():
return sock_func()
return _make_kresd_sock
@pytest.fixture(params=[
'ip_tcp_socket',
'ip6_tcp_socket',
'ip_tls_socket',
'ip6_tls_socket',
])
def make_kresd_silent_sock(request, kresd_silent):
"""Factory function to create sockets of the same kind (no verbose)."""
sock_func = getattr(kresd_silent, request.param)
def _make_kresd_sock():
return sock_func()
return _make_kresd_sock
@pytest.fixture
def kresd_sock(make_kresd_sock):
return make_kresd_sock()
@pytest.fixture(params=[
socket.AF_INET,
socket.AF_INET6,
])
def sock_family(request):
return request.param
@pytest.fixture(params=[
True,
False
])
def single_buffer(request): # whether to send all data in a single buffer
return request.param
@pytest.fixture(params=[
True,
False
])
def query_before(request): # whether to send an initial query
return request.param
@pytest.hookimpl(optionalhook=True)
def pytest_metadata(metadata): # filter potentially sensitive data from GitLab CI
keys_to_delete = []
for key in metadata.keys():
key_lower = key.lower()
if 'password' in key_lower or 'token' in key_lower or \
key_lower.startswith('ci') or key_lower.startswith('gitlab'):
keys_to_delete.append(key)
for key in keys_to_delete:
del metadata[key]
def pytest_sessionstart(session): # pylint: disable=unused-argument
init_portdir()
|