test(mesh): test PKI helpers + shared conftest (1/9 of #195 split)#220
Merged
cagataycali merged 2 commits intoMay 26, 2026
Merged
Conversation
Adds shared test infrastructure used by every later mesh security test PR: - tests/mesh/_pki.py: minimal in-process CA + cert helpers (deterministic CN strings, fd-clean tempdir lifetime, no host paths) used by the wire-config and transport-security suites to assemble mTLS chains in tests. - tests/mesh/conftest.py: shared pytest fixtures (env scrubbing, audit dir cleanup, Zenoh mock). Lands first in the split of strands-labs#195 so every later test PR has a green CI baseline. Tracking: strands-labs#219 Source PR: strands-labs#195
yinsong1986
reviewed
May 25, 2026
Contributor
yinsong1986
left a comment
There was a problem hiding this comment.
Summary
Adds shared test infrastructure for the upcoming mesh-security test split: an in-process CA + leaf-cert helper (tests/mesh/_pki.py, 128 LOC) and a tests/mesh/conftest.py (27 LOC) that defaults STRANDS_MESH_AUTH_MODE=none for any test under tests/mesh/. Scope matches the description -- no strands_robots/ source is touched, two files only, tests-only cryptography dependency. Landing this first makes the dependent PRs (#3/#6/#7/#8) cheaper to review.
What's good
- Scope discipline: 2 files / 155 LOC / 0 deletions. Matches the PR description exactly.
- AGENTS.md compliance: no host paths, no emojis in user-facing strings, deterministic CN strings (no
random.uniformetc.), 0o600 on private key files. - Each test gets its own ephemeral CA via
tmp_path, so cross-test bleed is structurally prevented. - Module docstring is explicit that this is test-only and points readers at the production provisioning path.
Concerns
- Conftest scope is broader than stated.
autouse=Trueon the env-scrubbing fixture means every future test added undertests/mesh/silently inheritsSTRANDS_MESH_AUTH_MODE=noneANDSTRANDS_MESH_I_KNOW_THIS_IS_INSECURE=1. A future test that wants to verify the second-factor gate itself will now have to actively unset the var, which is the opposite of the intent. Worth narrowing to an opt-in fixture or scoping per-module. Inline below. TestCAwill trigger aPytestCollectionWarningon every run. Pytest treats classes whose name starts withTestas collection candidates; a frozen dataclass with a generated__init__confuses the collector. Inline below.common_nameis interpolated directly into filesystem paths and X.509 SANs without validation. Test-only or not, the PR description's reviewer-focus list explicitly calls out path safety, and AGENTS.md > 'Sanitize user inputs' applies the same way_safe_joindoes instrands_robots/utils.py. Inline below.- Documentation drift: the module docstring says
mesh/iot/provision.pybut the actual module path isstrands_robots/mesh/iot/provision.py. AGENTS.md > Review Learnings (#86) > 'Reference module names, not filenames' applies. - Test surface: this PR adds zero tests of the helpers themselves. The PR description treats that as a feature ("green CI baseline of zero new tests passing"), but it does mean a regression in
make_test_ca/TestCA.issuewill only surface when PR-3 lands. A handful of self-tests on the helpers (CA basicConstraints critical, leaf chain validates against the CA, key file is 0o600, twoissue()calls on the sameout_dirdon't clobber each other) would catch silent breakage at the right layer.
Verification suggestions
# Reproduce the pytest collection warning (no test deps yet, but conftest is loaded):
hatch run test tests/mesh/ -W error::pytest.PytestCollectionWarning
# Confirm the autouse fixture leaks across the whole mesh suite, not just the new files:
hatch run test tests/mesh/test_mesh.py -s -p no:cacheprovider \
--setup-show 2>&1 | grep -i 'STRANDS_MESH_AUTH_MODE\|_default_mesh_auth_mode_none'
# Sanity-check the CA helper end-to-end:
python - <<'PY'
from pathlib import Path
import tempfile, ssl
from tests.mesh._pki import make_test_ca
with tempfile.TemporaryDirectory() as d:
ca = make_test_ca(Path(d))
cp, kp = ca.issue('node-a', Path(d) / 'leaf')
ctx = ssl.create_default_context(cafile=str(ca.cert_path))
ctx.load_cert_chain(certfile=str(cp), keyfile=str(kp))
print('chain ok:', cp, kp, oct(kp.stat().st_mode & 0o777))
PY
This was referenced May 25, 2026
Open
mesh(transport): bridge cross-transport dedup + monotonic TTL + strict mode (5/9 of #195 split)
#222
Open
Four fixes from PR-220 review comments:
1. _pki.py: Add anchored CN regex validation in issue() + make_test_ca().
common_name was interpolated directly into filesystem path and
x509.DNSName(...) without validation. AGENTS.md > 'Sanitize user
inputs' applies -- every later mesh-security test PR uses this
helper, so issue('node/a', out_dir) or issue('../foo', out_dir)
must fail loudly.
Ref: strands-labs#220 (comment)
2. _pki.py: Rename TestCA -> EphemeralCA. The original triggered
PytestCollectionWarning on every run because pytest's default rule
matches Test*. Rename is cleaner than __test__ = False.
Ref: strands-labs#220 (comment)
3. conftest.py: Tighten autouse fixture: (a) move second-factor flag
into same conditional branch as auth-mode override so AUTH_MODE=mtls
does NOT inject the insecure flag; (b) add @pytest.mark.mesh_auth_mode_default
opt-out marker so tests exercising the gate itself don't pass by
accident under autouse.
Ref: strands-labs#220 (comment)
4. _pki.py: Fix docstring -- module path 'strands_robots.mesh.iot.provision'
not filename 'mesh/iot/provision.py' (AGENTS.md PR strands-labs#86 review
learning); 'Returns the generated CA' not 'loaded'.
Ref: strands-labs#220 (comment)
Tracking: strands-labs#219
Source PR: strands-labs#195
Member
Author
|
Thanks for the review @yinsong1986. All four threads addressed in
Resolving the threads now. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Part 1 / 9 of the split of #195 — tracked by #219.
Adds shared test infrastructure that every later mesh security test PR depends on:
tests/mesh/_pki.py(128 LOC) — minimal in-process CA + cert helpers. Deterministic CN strings, fd-clean tempdir lifetime, no host paths. Used by the wire-config and transport-security suites in PR-3 to assemble mTLS chains.tests/mesh/conftest.py(27 LOC) — shared pytest fixtures: env scrubbing forSTRANDS_MESH_*, audit dir cleanup between tests, Zenoh mock harness.Why this lands first
Every later test PR (
PR-3,PR-6,PR-7,PR-8) imports fromtests/mesh/_pki.pyor relies on the conftest fixtures. Landing this in isolation gives every later PR a green CI baseline of zero new tests passing.Reviewer focus
random.uniformetc.) so test failures are reproducible.Scope
Out of scope
No source code under
strands_robots/is touched in this PR — the helpers will be exercised by tests in subsequent PRs.Landing order: PR-1 → PR-2/3/4/5 (parallel) → PR-6 → PR-7 → PR-8 → PR-9. Full plan:
PR_LIST.md. Tracking: #219.