Skip to content

Commit

Permalink
all ruff formatting changes
Browse files Browse the repository at this point in the history
  • Loading branch information
johubertj committed Feb 20, 2025
1 parent 4ae43ec commit 8e80fc4
Show file tree
Hide file tree
Showing 32 changed files with 2,599 additions and 1,387 deletions.
539 changes: 369 additions & 170 deletions tests/integrationv2/common.py

Large diffs are not rendered by default.

340 changes: 202 additions & 138 deletions tests/integrationv2/configuration.py

Large diffs are not rendered by default.

21 changes: 14 additions & 7 deletions tests/integrationv2/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def available_providers():
bin_path = f"{expected_location}/{binary}"
if not os.path.exists(bin_path):
pytest.fail(f"unable to locate {binary}")
os.environ['PATH'] += os.pathsep + expected_location
os.environ["PATH"] += os.pathsep + expected_location
providers.add(S2N)

if os.path.exists("./bin/SSLSocketClient.class"):
Expand All @@ -34,8 +34,14 @@ def available_providers():


def pytest_addoption(parser: pytest.Parser):
parser.addoption("--provider-version", action="store", dest="provider-version",
default=None, type=str, help="Set the version of the TLS provider")
parser.addoption(
"--provider-version",
action="store",
dest="provider-version",
default=None,
type=str,
help="Set the version of the TLS provider",
)
parser.addoption(
"--best-effort-NOT-FOR-CI",
action="store_true",
Expand All @@ -54,13 +60,14 @@ def pytest_configure(config: pytest.Config):
This is executed once per pytest session on process startup.
"""
config.addinivalue_line(
"markers", "uncollect_if(*, func): function to unselect tests from parametrization"
"markers",
"uncollect_if(*, func): function to unselect tests from parametrization",
)

if config.getoption("--best-effort-NOT-FOR-CI"):
config.stash[PATH_CONFIGURATION_KEY] = available_providers()

provider_version = config.getoption('provider-version', None)
provider_version = config.getoption("provider-version", None)
# By default, any libcrypto with "fips" in its name should be in fips mode.
# However, s2n-tls no longer supports fips mode with openssl-1.0.2-fips.
if "fips" in provider_version and "openssl-1.0.2-fips" not in provider_version:
Expand All @@ -75,9 +82,9 @@ def pytest_collection_modifyitems(config, items):
removed = []
kept = []
for item in items:
m = item.get_closest_marker('uncollect_if')
m = item.get_closest_marker("uncollect_if")
if m:
func = m.kwargs['func']
func = m.kwargs["func"]
if func(**item.callspec.params):
removed.append(item)
continue
Expand Down
5 changes: 2 additions & 3 deletions tests/integrationv2/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,5 @@
TEST_SNI_CERT_DIRECTORY = "../pems/sni/"
TEST_OCSP_DIRECTORY = "../pems/ocsp/"

TRUST_STORE_BUNDLE = TEST_CERT_DIRECTORY + 'trust-store/ca-bundle.crt'
TRUST_STORE_TRUSTED_BUNDLE = TEST_CERT_DIRECTORY + \
'trust-store/ca-bundle.trust.crt'
TRUST_STORE_BUNDLE = TEST_CERT_DIRECTORY + "trust-store/ca-bundle.crt"
TRUST_STORE_TRUSTED_BUNDLE = TEST_CERT_DIRECTORY + "trust-store/ca-bundle.trust.crt"
38 changes: 26 additions & 12 deletions tests/integrationv2/fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,16 @@ def managed_process(request: pytest.FixtureRequest):
# Indicates whether a launch was aborted. If so, non-graceful shutdown is allowed
aborted = False

def _fn(provider_class: Provider, options: ProviderOptions, timeout=5, send_marker=None, close_marker=None,
expect_stderr=None, kill_marker=None, send_with_newline=None):
def _fn(
provider_class: Provider,
options: ProviderOptions,
timeout=5,
send_marker=None,
close_marker=None,
expect_stderr=None,
kill_marker=None,
send_with_newline=None,
):
best_effort_mode = request.config.getoption("--best-effort-NOT-FOR-CI")
if best_effort_mode:
# modify the `aborted` field in the generator object
Expand All @@ -40,7 +48,11 @@ def _fn(provider_class: Provider, options: ProviderOptions, timeout=5, send_mark
provider = provider_class(options)
cmd_line = provider.get_cmd_line()

if best_effort_mode and provider_class is S2N and not (cmd_line[0] == "s2nc" or cmd_line[0] == "s2nd"):
if (
best_effort_mode
and provider_class is S2N
and not (cmd_line[0] == "s2nc" or cmd_line[0] == "s2nd")
):
aborted = True
pytest.skip("s2nc_head or s2nd_head not supported for best-effort")

Expand All @@ -63,7 +75,7 @@ def _fn(provider_class: Provider, options: ProviderOptions, timeout=5, send_mark
env_overrides=options.env_overrides,
expect_stderr=expect_stderr,
kill_marker=kill_marker,
send_with_newline=send_with_newline
send_with_newline=send_with_newline,
)

processes.append(p)
Expand All @@ -72,7 +84,8 @@ def _fn(provider_class: Provider, options: ProviderOptions, timeout=5, send_mark
with provider._provider_ready_condition:
# Don't continue processing until the provider has indicated it is ready.
provider._provider_ready_condition.wait_for(
provider.is_provider_ready, timeout)
provider.is_provider_ready, timeout
)
return p

try:
Expand All @@ -96,13 +109,14 @@ def _swap_mtu(device, new_mtu):
Return the original MTU so it can be reset later.
"""
cmd = ["ip", "link", "show", device]
p = subprocess.Popen(cmd, stdin=subprocess.PIPE,
stdout=subprocess.PIPE, stderr=subprocess.PIPE)
p = subprocess.Popen(
cmd, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE
)
mtu = 65536
for line in p.stdout.readlines():
s = line.decode("utf-8")
pieces = s.split(' ')
if len(pieces) >= 4 and pieces[3] == 'mtu':
pieces = s.split(" ")
if len(pieces) >= 4 and pieces[3] == "mtu":
mtu = int(pieces[4])

p.wait()
Expand All @@ -112,7 +126,7 @@ def _swap_mtu(device, new_mtu):
return int(mtu)


@pytest.fixture(scope='module')
@pytest.fixture(scope="module")
def custom_mtu():
"""
This fixture will swap the loopback's MTU from the default
Expand All @@ -126,6 +140,6 @@ def custom_mtu():
if os.geteuid() != 0:
pytest.skip("Test needs root privileges to modify lo MTU")

original_mtu = _swap_mtu('lo', 1500)
original_mtu = _swap_mtu("lo", 1500)
yield
_swap_mtu('lo', original_mtu)
_swap_mtu("lo", original_mtu)
4 changes: 2 additions & 2 deletions tests/integrationv2/global_flags.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
# based on the environment.

# If S2N is operating in FIPS mode
S2N_FIPS_MODE = 's2n_fips_mode'
S2N_FIPS_MODE = "s2n_fips_mode"

# The version of provider being used
# (set from the S2N_LIBCRYPTO env var, which is how the original integration test works)
S2N_PROVIDER_VERSION = 's2n_provider_version'
S2N_PROVIDER_VERSION = "s2n_provider_version"

_flags = {}

Expand Down
Loading

0 comments on commit 8e80fc4

Please sign in to comment.