tba-tests-workload-credential-conformance 0.4.0.dev2__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,66 @@
1
+ Metadata-Version: 2.4
2
+ Name: tba-tests-workload-credential-conformance
3
+ Version: 0.4.0.dev2
4
+ Summary: Reusable structural and negative vectors.
5
+ License: Apache-2.0
6
+ Requires-Python: >=3.10,<3.16
7
+ Classifier: Programming Language :: Python :: 3.10
8
+ Classifier: Programming Language :: Python :: 3.11
9
+ Classifier: Programming Language :: Python :: 3.12
10
+ Classifier: Programming Language :: Python :: 3.13
11
+ Classifier: Programming Language :: Python :: 3.14
12
+ Classifier: Programming Language :: Python :: 3.15
13
+ Provides-Extra: runner
14
+ Requires-Dist: cryptography (>=45.0.0) ; extra == "runner"
15
+ Requires-Dist: packaging (>=24.0) ; extra == "runner"
16
+ Requires-Dist: pytest (>=8.0) ; extra == "runner"
17
+ Requires-Dist: tba-primitives-identity (==0.4.0.dev2) ; extra == "runner"
18
+ Requires-Dist: tomli (>=2.0) ; (python_version < "3.11") and (extra == "runner")
19
+ Description-Content-Type: text/markdown
20
+
21
+ # tba-tests-workload-credential-conformance
22
+
23
+ <!-- BEGIN TBA README HEADER -->
24
+ <p align="center">
25
+ <a href="https://github.com/tigrbl/tigrbl_auth#readme"><img src="https://raw.githubusercontent.com/tigrbl/tigrbl_auth/master/docs/assets/tba-brand.png" alt="TBA · Tigrbl Auth" width="240"></a>
26
+ </p>
27
+ <p align="center">
28
+ <a href="https://github.com/tigrbl/tigrbl_auth/blob/master/pkgs/120-tests/tba-tests-workload-credential-conformance/pyproject.toml"><img alt="Checkout: 0.4.0.dev2" src="https://img.shields.io/badge/Checkout-0.4.0.dev2-1f6feb"></a>
29
+ <a href="https://github.com/tigrbl/tigrbl_auth/blob/master/pkgs/120-tests/tba-tests-workload-credential-conformance/pyproject.toml"><img alt="Python: &gt;=3.10,&lt;3.16" src="https://img.shields.io/badge/Python-%3E%3D3.10%2C%3C3.16-3776ab"></a>
30
+ <a href="https://github.com/tigrbl/tigrbl_auth/tree/master/pkgs/120-tests"><img alt="Layer: 120 tests" src="https://img.shields.io/badge/Layer-120%20tests-0a7f5a"></a>
31
+ <a href="https://pypi.org/project/tba-tests-workload-credential-conformance/"><img alt="PyPI version for tba-tests-workload-credential-conformance" src="https://img.shields.io/pypi/v/tba-tests-workload-credential-conformance?label=tba-tests-workload-credential-conformance%20PyPI"></a>
32
+ </p>
33
+ <p align="center">
34
+ <a href="https://pepy.tech/project/tba-tests-workload-credential-conformance"><img alt="Monthly PyPI downloads for tba-tests-workload-credential-conformance" src="https://static.pepy.tech/badge/tba-tests-workload-credential-conformance/month"></a>
35
+ <a href="https://github.com/tigrbl/tigrbl_auth/blob/master/pkgs/120-tests/tba-tests-workload-credential-conformance/README.md#verification"><img alt="Evidence: verification" src="https://img.shields.io/badge/Evidence-verification-8250df"></a>
36
+ </p>
37
+ <!-- END TBA README HEADER -->
38
+
39
+ Reusable structural and negative vectors. Passing these vectors is not an independent interoperability or certification claim.
40
+
41
+ ## Quick start
42
+
43
+ With [uv](https://docs.astral.sh/uv/) available, save the example as `quickstart.py`. This command uses the published package in an isolated Python 3.12 environment.
44
+
45
+ ```python
46
+ from tba_tests_workload_credential_conformance import VECTORS
47
+
48
+ assert any(vector.expected_valid for vector in VECTORS)
49
+ assert any(not vector.expected_valid for vector in VECTORS)
50
+ ```
51
+
52
+ ```bash
53
+ uv run --isolated --no-project --python 3.12 --with "tba-tests-workload-credential-conformance==0.4.0.dev2" python quickstart.py
54
+ ```
55
+
56
+ The fixture inventory contains both accepted and rejected cases.
57
+
58
+ The workload suites also import certificate and TLS fixtures from `fixtures`,
59
+ profile exercises from `profiles`, and the clean-wheel runner from `wheels`.
60
+ The `runner` extra supplies their test tooling. The root test environment
61
+ supplies the protocol packages exercised by each suite.
62
+
63
+ ## Verification
64
+
65
+ The quick start was run with the pinned distribution from PyPI and its declared dependencies. See the [public package entry point](https://github.com/tigrbl/tigrbl_auth/blob/master/pkgs/120-tests/tba-tests-workload-credential-conformance/src/tba_tests_workload_credential_conformance/__init__.py).
66
+
@@ -0,0 +1,45 @@
1
+ # tba-tests-workload-credential-conformance
2
+
3
+ <!-- BEGIN TBA README HEADER -->
4
+ <p align="center">
5
+ <a href="https://github.com/tigrbl/tigrbl_auth#readme"><img src="https://raw.githubusercontent.com/tigrbl/tigrbl_auth/master/docs/assets/tba-brand.png" alt="TBA · Tigrbl Auth" width="240"></a>
6
+ </p>
7
+ <p align="center">
8
+ <a href="https://github.com/tigrbl/tigrbl_auth/blob/master/pkgs/120-tests/tba-tests-workload-credential-conformance/pyproject.toml"><img alt="Checkout: 0.4.0.dev2" src="https://img.shields.io/badge/Checkout-0.4.0.dev2-1f6feb"></a>
9
+ <a href="https://github.com/tigrbl/tigrbl_auth/blob/master/pkgs/120-tests/tba-tests-workload-credential-conformance/pyproject.toml"><img alt="Python: &gt;=3.10,&lt;3.16" src="https://img.shields.io/badge/Python-%3E%3D3.10%2C%3C3.16-3776ab"></a>
10
+ <a href="https://github.com/tigrbl/tigrbl_auth/tree/master/pkgs/120-tests"><img alt="Layer: 120 tests" src="https://img.shields.io/badge/Layer-120%20tests-0a7f5a"></a>
11
+ <a href="https://pypi.org/project/tba-tests-workload-credential-conformance/"><img alt="PyPI version for tba-tests-workload-credential-conformance" src="https://img.shields.io/pypi/v/tba-tests-workload-credential-conformance?label=tba-tests-workload-credential-conformance%20PyPI"></a>
12
+ </p>
13
+ <p align="center">
14
+ <a href="https://pepy.tech/project/tba-tests-workload-credential-conformance"><img alt="Monthly PyPI downloads for tba-tests-workload-credential-conformance" src="https://static.pepy.tech/badge/tba-tests-workload-credential-conformance/month"></a>
15
+ <a href="https://github.com/tigrbl/tigrbl_auth/blob/master/pkgs/120-tests/tba-tests-workload-credential-conformance/README.md#verification"><img alt="Evidence: verification" src="https://img.shields.io/badge/Evidence-verification-8250df"></a>
16
+ </p>
17
+ <!-- END TBA README HEADER -->
18
+
19
+ Reusable structural and negative vectors. Passing these vectors is not an independent interoperability or certification claim.
20
+
21
+ ## Quick start
22
+
23
+ With [uv](https://docs.astral.sh/uv/) available, save the example as `quickstart.py`. This command uses the published package in an isolated Python 3.12 environment.
24
+
25
+ ```python
26
+ from tba_tests_workload_credential_conformance import VECTORS
27
+
28
+ assert any(vector.expected_valid for vector in VECTORS)
29
+ assert any(not vector.expected_valid for vector in VECTORS)
30
+ ```
31
+
32
+ ```bash
33
+ uv run --isolated --no-project --python 3.12 --with "tba-tests-workload-credential-conformance==0.4.0.dev2" python quickstart.py
34
+ ```
35
+
36
+ The fixture inventory contains both accepted and rejected cases.
37
+
38
+ The workload suites also import certificate and TLS fixtures from `fixtures`,
39
+ profile exercises from `profiles`, and the clean-wheel runner from `wheels`.
40
+ The `runner` extra supplies their test tooling. The root test environment
41
+ supplies the protocol packages exercised by each suite.
42
+
43
+ ## Verification
44
+
45
+ The quick start was run with the pinned distribution from PyPI and its declared dependencies. See the [public package entry point](https://github.com/tigrbl/tigrbl_auth/blob/master/pkgs/120-tests/tba-tests-workload-credential-conformance/src/tba_tests_workload_credential_conformance/__init__.py).
@@ -0,0 +1,30 @@
1
+ [project]
2
+ name="tba-tests-workload-credential-conformance"
3
+ version="0.4.0.dev2"
4
+ description = "Reusable structural and negative vectors."
5
+ license = { text = "Apache-2.0" }
6
+ readme = "README.md"
7
+ requires-python=">=3.10,<3.16"
8
+ classifiers = [
9
+ "Programming Language :: Python :: 3.10",
10
+ "Programming Language :: Python :: 3.11",
11
+ "Programming Language :: Python :: 3.12",
12
+ "Programming Language :: Python :: 3.13",
13
+ "Programming Language :: Python :: 3.14",
14
+ "Programming Language :: Python :: 3.15",
15
+ ]
16
+ dependencies=[]
17
+
18
+ [project.optional-dependencies]
19
+ runner = [
20
+ "cryptography>=45.0.0",
21
+ "packaging>=24.0",
22
+ "pytest>=8.0",
23
+ "tba-primitives-identity==0.4.0.dev2",
24
+ "tomli>=2.0; python_version < '3.11'",
25
+ ]
26
+ [build-system]
27
+ requires=["poetry-core>=1.0.0"]
28
+ build-backend="poetry.core.masonry.api"
29
+ [tool.poetry]
30
+ packages=[{include="tba_tests_workload_credential_conformance",from="src"}]
@@ -0,0 +1,2 @@
1
+ from .vectors import ArtifactVector, VECTORS
2
+ __all__ = ["ArtifactVector", "VECTORS"]
@@ -0,0 +1,296 @@
1
+ import hashlib
2
+ import json
3
+ from types import SimpleNamespace
4
+
5
+ from cryptography import x509
6
+ from cryptography.exceptions import InvalidSignature
7
+ from cryptography.hazmat.primitives import hashes
8
+ from cryptography.hazmat.primitives.asymmetric import ec, utils
9
+ from tba_primitives_identity import base64url_encode
10
+
11
+ WIMSE = "wimse://example.org/workload"
12
+ SPIFFE = "spiffe://example.org/workload"
13
+ AUDIENCE = "https://service.example.org/resource"
14
+
15
+
16
+ def _jwk(private_key, **metadata):
17
+ numbers = private_key.public_key().public_numbers()
18
+ return {
19
+ "kty": "EC",
20
+ "crv": "P-256",
21
+ "alg": "ES256",
22
+ "x": base64url_encode(numbers.x.to_bytes(32, "big")),
23
+ "y": base64url_encode(numbers.y.to_bytes(32, "big")),
24
+ **metadata,
25
+ }
26
+
27
+
28
+ def _jwt(key, claims, **header):
29
+ header = {"alg": "ES256", **header}
30
+ segments = [
31
+ base64url_encode(json.dumps(value).encode()) for value in (header, claims)
32
+ ]
33
+ message = ".".join(segments)
34
+ r, s = utils.decode_dss_signature(
35
+ key.sign(message.encode(), ec.ECDSA(hashes.SHA256()))
36
+ )
37
+ return (
38
+ message + "." + base64url_encode(r.to_bytes(32, "big") + s.to_bytes(32, "big"))
39
+ )
40
+
41
+
42
+ class Replay:
43
+ def __init__(self):
44
+ self.keys = set()
45
+
46
+ def check_and_store(self, key, *, now, ttl_s):
47
+ if key in self.keys:
48
+ return False
49
+ self.keys.add(key)
50
+ return True
51
+
52
+
53
+ class PathValidator:
54
+ def __init__(self, ca):
55
+ self.ca = ca
56
+
57
+ def validate(self, request):
58
+ leaf = x509.load_der_x509_certificate(request.leaf.der)
59
+ try:
60
+ leaf.verify_directly_issued_by(self.ca)
61
+ except (ValueError, TypeError, InvalidSignature):
62
+ valid = False
63
+ else:
64
+ valid = True
65
+ return SimpleNamespace(
66
+ valid=valid, indeterminate=False, profile=request.leaf.profile
67
+ )
68
+
69
+
70
+ class StatusProvider:
71
+ def __init__(self, status):
72
+ self._status = status
73
+
74
+ def status(self, der):
75
+ return SimpleNamespace(status=self._status)
76
+
77
+
78
+ def _certificate(subject, *, issuer=None, dns=None):
79
+ from datetime import datetime, timedelta, timezone
80
+
81
+ from cryptography import x509
82
+ from cryptography.hazmat.primitives import hashes
83
+ from cryptography.hazmat.primitives.asymmetric import ec
84
+ from cryptography.x509.oid import NameOID
85
+
86
+ now = datetime.now(timezone.utc)
87
+ key = ec.generate_private_key(ec.SECP256R1())
88
+ name = x509.Name(
89
+ [
90
+ x509.NameAttribute(
91
+ NameOID.COMMON_NAME, "Workload CA" if issuer is None else "Workload"
92
+ )
93
+ ]
94
+ )
95
+ builder = (
96
+ x509.CertificateBuilder()
97
+ .subject_name(name)
98
+ .issuer_name(issuer[0].subject if issuer else name)
99
+ .public_key(key.public_key())
100
+ .serial_number(x509.random_serial_number())
101
+ .not_valid_before(now - timedelta(minutes=1))
102
+ .not_valid_after(now + timedelta(hours=1))
103
+ .add_extension(
104
+ x509.BasicConstraints(ca=issuer is None, path_length=None), critical=True
105
+ )
106
+ .add_extension(
107
+ x509.KeyUsage(
108
+ digital_signature=True,
109
+ content_commitment=False,
110
+ key_encipherment=False,
111
+ data_encipherment=False,
112
+ key_agreement=False,
113
+ key_cert_sign=issuer is None,
114
+ crl_sign=issuer is None,
115
+ encipher_only=False,
116
+ decipher_only=False,
117
+ ),
118
+ critical=True,
119
+ )
120
+ )
121
+ names = [x509.UniformResourceIdentifier(uri) for uri in subject]
122
+ if dns:
123
+ names.append(x509.DNSName(dns))
124
+ if names:
125
+ builder = builder.add_extension(
126
+ x509.SubjectAlternativeName(names), critical=False
127
+ )
128
+ return builder.sign(issuer[1] if issuer else key, hashes.SHA256()), key
129
+
130
+
131
+ def _tls_context(tmp_path, name, leaf, root, *, server):
132
+ import ssl
133
+
134
+ from cryptography.hazmat.primitives import serialization
135
+
136
+ certificate, key = leaf
137
+ pem = tmp_path / f"{name}.pem"
138
+ private_key = tmp_path / f"{name}.key"
139
+ pem.write_bytes(certificate.public_bytes(serialization.Encoding.PEM))
140
+ private_key.write_bytes(
141
+ key.private_bytes(
142
+ serialization.Encoding.PEM,
143
+ serialization.PrivateFormat.PKCS8,
144
+ serialization.NoEncryption(),
145
+ )
146
+ )
147
+ context = ssl.SSLContext(
148
+ ssl.PROTOCOL_TLS_SERVER if server else ssl.PROTOCOL_TLS_CLIENT
149
+ )
150
+ context.load_cert_chain(pem, private_key)
151
+ context.load_verify_locations(
152
+ cadata=root.public_bytes(serialization.Encoding.PEM).decode()
153
+ )
154
+ context.verify_mode = ssl.CERT_REQUIRED
155
+ return context
156
+
157
+
158
+ def _mutual_tls_peers(tmp_path, identity, *, client_identifiers=None):
159
+ import ssl
160
+
161
+ root = _certificate(())
162
+ server_context = _tls_context(
163
+ tmp_path,
164
+ "server",
165
+ _certificate(
166
+ ("wimse://example.org/workload/server",),
167
+ issuer=root,
168
+ dns="service.example.org",
169
+ ),
170
+ root[0],
171
+ server=True,
172
+ )
173
+ client_context = _tls_context(
174
+ tmp_path,
175
+ "client",
176
+ _certificate(
177
+ (identity,) if client_identifiers is None else client_identifiers,
178
+ issuer=root,
179
+ ),
180
+ root[0],
181
+ server=False,
182
+ )
183
+ client_in, client_out = ssl.MemoryBIO(), ssl.MemoryBIO()
184
+ server_in, server_out = ssl.MemoryBIO(), ssl.MemoryBIO()
185
+ server = server_context.wrap_bio(server_in, server_out, server_side=True)
186
+ client = client_context.wrap_bio(
187
+ client_in, client_out, server_hostname="service.example.org"
188
+ )
189
+ complete = set()
190
+ for _ in range(16):
191
+ for endpoint, outgoing, remote in (
192
+ (client, client_out, server_in),
193
+ (server, server_out, client_in),
194
+ ):
195
+ if endpoint not in complete:
196
+ try:
197
+ endpoint.do_handshake()
198
+ except ssl.SSLWantReadError:
199
+ pass
200
+ else:
201
+ complete.add(endpoint)
202
+ if outgoing.pending:
203
+ remote.write(outgoing.read())
204
+ if len(complete) == 2:
205
+ break
206
+ assert len(complete) == 2
207
+ return (
208
+ root[0],
209
+ server.getpeercert(binary_form=True),
210
+ client.getpeercert(binary_form=True),
211
+ )
212
+
213
+
214
+ def exercise_wimse_mtls_round_trip():
215
+ from pathlib import Path
216
+ from tempfile import TemporaryDirectory
217
+
218
+ from cryptography import x509
219
+ from cryptography.exceptions import InvalidSignature
220
+ from tba_concrete_certificate_x509 import parse_x509_certificate
221
+ from tba_contracts_security_trust import (
222
+ CertificatePathValidationResult,
223
+ CertificateStatus,
224
+ )
225
+ from tba_profile_workload_authentication_wimse_mtls import (
226
+ TLSPeer,
227
+ verify_wimse_peer,
228
+ )
229
+ from tba_provider_certificate_status import SnapshotCertificateStatusProvider
230
+
231
+ identity = "wimse://example.org/workload"
232
+ with TemporaryDirectory() as directory:
233
+ ca, client_der, server_der = _mutual_tls_peers(Path(directory), identity)
234
+ status = SnapshotCertificateStatusProvider()
235
+
236
+ class DirectPath:
237
+ def __init__(self, anchor):
238
+ self.anchor = anchor
239
+
240
+ def validate(self, request):
241
+ leaf = x509.load_der_x509_certificate(request.leaf.der)
242
+ try:
243
+ leaf.verify_directly_issued_by(self.anchor)
244
+ except (ValueError, TypeError, InvalidSignature):
245
+ return CertificatePathValidationResult(False, request.leaf.profile)
246
+ return CertificatePathValidationResult(True, request.leaf.profile)
247
+
248
+ client = TLSPeer(parse_x509_certificate(client_der))
249
+ server = TLSPeer(
250
+ parse_x509_certificate(server_der), server_name="service.example.org"
251
+ )
252
+ anchors = {"example.org": DirectPath(ca)}
253
+ for peer, expected in ((client, identity), (server, identity + "/server")):
254
+ status.publish(peer.certificate.der, CertificateStatus.GOOD, "acceptance-ca")
255
+ assert (
256
+ verify_wimse_peer(
257
+ peer,
258
+ expected_identity=expected,
259
+ validators_by_domain=anchors,
260
+ status_provider=status,
261
+ ).workload_identifier
262
+ == expected
263
+ )
264
+ wrong_anchor = {"example.org": DirectPath(_certificate(())[0])}
265
+ for expected, validators, reason in (
266
+ (identity, {}, "no configured"),
267
+ (identity, wrong_anchor, "path"),
268
+ (identity + "/other", anchors, "unexpected"),
269
+ (identity, anchors, "status"),
270
+ ):
271
+ if reason == "status":
272
+ status.publish(client_der, CertificateStatus.REVOKED, "acceptance-ca")
273
+ try:
274
+ verify_wimse_peer(
275
+ client,
276
+ expected_identity=expected,
277
+ validators_by_domain=validators,
278
+ status_provider=status,
279
+ )
280
+ except ValueError as error:
281
+ assert reason in str(error)
282
+ else:
283
+ raise AssertionError(f"mTLS verifier accepted the {reason} case")
284
+
285
+
286
+ def _wpt(private, wit):
287
+ return _jwt(
288
+ private,
289
+ {
290
+ "aud": AUDIENCE,
291
+ "exp": 120,
292
+ "jti": "proof",
293
+ "wth": base64url_encode(hashlib.sha256(wit.encode()).digest()),
294
+ },
295
+ typ="wpt+jwt",
296
+ )
@@ -0,0 +1,98 @@
1
+ def exercise_wimse():
2
+ from tba_profile_workload_credential_wimse_wit import validate_wit
3
+ from tba_profile_workload_proof_wimse_wpt import validate_wpt
4
+
5
+ wit_header = {"typ": "wit+jwt", "alg": "ES256"}
6
+ wit = {
7
+ "iss": "https://example.org/issuer",
8
+ "sub": "wimse://example.org/workload",
9
+ "cnf": {"jkt": "test-key-thumbprint"},
10
+ "exp": 2,
11
+ "iat": 1,
12
+ }
13
+ validate_wit(wit_header, wit)
14
+ try:
15
+ validate_wit(wit_header, {**wit, "aud": "service"})
16
+ except ValueError as error:
17
+ assert "aud" in str(error)
18
+ else:
19
+ raise AssertionError("WIT profile accepted an audience")
20
+
21
+ wpt_header = {"typ": "wpt+jwt", "alg": "ES256"}
22
+ wpt = {"aud": "service", "exp": 2, "jti": "proof", "wth": "expected-hash"}
23
+ validate_wpt(
24
+ wpt_header, wpt, expected_audience="service", expected_wit_hash="expected-hash"
25
+ )
26
+ try:
27
+ validate_wpt(
28
+ wpt_header, wpt, expected_audience="service", expected_wit_hash="wrong-hash"
29
+ )
30
+ except ValueError as error:
31
+ assert "bind" in str(error)
32
+ else:
33
+ raise AssertionError("WPT profile accepted a mismatched WIT hash")
34
+
35
+
36
+ def exercise_wic():
37
+ from datetime import datetime, timedelta, timezone
38
+
39
+ from cryptography import x509
40
+ from cryptography.hazmat.primitives import hashes, serialization
41
+ from cryptography.hazmat.primitives.asymmetric import ec
42
+ from cryptography.x509.oid import NameOID
43
+ from tba_concrete_certificate_x509 import parse_x509_certificate
44
+ from tba_profile_workload_credential_wimse_wic import validate_wic
45
+
46
+ key = ec.generate_private_key(ec.SECP256R1())
47
+ name = x509.Name([x509.NameAttribute(NameOID.COMMON_NAME, "Fixture")])
48
+ now = datetime.now(timezone.utc)
49
+ identity = "wimse://example.org/workload"
50
+ cert = (
51
+ x509.CertificateBuilder()
52
+ .subject_name(name)
53
+ .issuer_name(name)
54
+ .public_key(key.public_key())
55
+ .serial_number(1)
56
+ .not_valid_before(now)
57
+ .not_valid_after(now + timedelta(minutes=1))
58
+ .add_extension(
59
+ x509.SubjectAlternativeName([x509.UniformResourceIdentifier(identity)]),
60
+ False,
61
+ )
62
+ .sign(key, hashes.SHA256())
63
+ )
64
+ parsed = parse_x509_certificate(cert.public_bytes(serialization.Encoding.DER))
65
+ assert validate_wic(parsed).workload_identifier == identity
66
+
67
+
68
+ def exercise_spiffe():
69
+ from tba_protocol_workload_spiffe_svid import (
70
+ validate_jwt_svid,
71
+ validate_spiffe_id,
72
+ validate_x509_svid,
73
+ )
74
+
75
+ subject = "spiffe://example.org/workload"
76
+ assert validate_spiffe_id(subject) == ("example.org", "/workload")
77
+ header = {"alg": "ES256"}
78
+ jwt_svid = {"sub": subject, "aud": ["service"], "exp": 2, "iat": 1}
79
+ validate_jwt_svid(header, jwt_svid, expected_audience="service")
80
+ try:
81
+ validate_jwt_svid(header, jwt_svid, expected_audience="other-service")
82
+ except ValueError as error:
83
+ assert "audience" in str(error)
84
+ else:
85
+ raise AssertionError("JWT-SVID profile accepted a different audience")
86
+
87
+ options = {
88
+ "dns_sans": (),
89
+ "key_usage_digital_signature": True,
90
+ "basic_constraints_ca": False,
91
+ }
92
+ assert validate_x509_svid(uri_sans=(subject,), **options) == subject
93
+ try:
94
+ validate_x509_svid(uri_sans=("wimse://example.org/workload",), **options)
95
+ except ValueError:
96
+ pass
97
+ else:
98
+ raise AssertionError("X.509-SVID profile accepted a WIMSE identifier")
@@ -0,0 +1,17 @@
1
+ from dataclasses import dataclass
2
+ from typing import Mapping
3
+ @dataclass(frozen=True, slots=True)
4
+ class ArtifactVector:
5
+ identifier: str
6
+ profile: str
7
+ headers: Mapping[object, object]
8
+ claims: Mapping[object, object]
9
+ expected_valid: bool
10
+ reason: str
11
+ VECTORS = (
12
+ ArtifactVector("jwt-svid-valid", "jwt-svid", {"alg": "ES256"}, {"sub": "spiffe://example.org/w", "aud": "service", "exp": 2, "iat": 1}, True, "stable bearer profile"),
13
+ ArtifactVector("jwt-svid-cnf-confusion", "jwt-svid", {"alg": "ES256"}, {"sub": "spiffe://example.org/w", "aud": "service", "exp": 2, "iat": 1, "cnf": {}}, False, "WIT semantics in JWT-SVID"),
14
+ ArtifactVector("wit-svid-aud-confusion", "wit-svid", {"typ": "wit+jwt", "kid": "k", "alg": "ES256"}, {"iss": "i", "sub": "spiffe://example.org/w", "aud": "service", "cnf": {"jkt": "k"}, "exp": 2}, False, "aud belongs on WPT"),
15
+ ArtifactVector("wpt-wrong-wit", "wpt", {"typ": "wpt+jwt", "alg": "ES256"}, {"aud": "service", "exp": 2, "jti": "p", "wth": "wrong"}, False, "proof binds a different WIT"),
16
+ ArtifactVector("cwt-svid-bearer", "cwt-svid-extension", {1: -7, 4: b"k"}, {1: "i", 2: "spiffe://example.org/w", 3: "service", 4: 2, 6: 1, 8: {1: b"k"}}, False, "experimental credential cannot be bearer"),
17
+ )
@@ -0,0 +1,120 @@
1
+ import json
2
+ import os
3
+ import subprocess
4
+ import sys
5
+ import textwrap
6
+
7
+ import pytest
8
+ from packaging.requirements import Requirement
9
+ from packaging.utils import canonicalize_name
10
+
11
+ try:
12
+ import tomllib
13
+ except ModuleNotFoundError:
14
+ import tomli as tomllib
15
+
16
+
17
+ def run_command(*args, cwd, env=None):
18
+ result = subprocess.run(
19
+ args, cwd=cwd, env=env, capture_output=True, text=True, timeout=180
20
+ )
21
+ assert result.returncode == 0, result.stdout + result.stderr
22
+ return result.stdout
23
+
24
+
25
+ @pytest.fixture(scope="module")
26
+ def wheelhouse(tmp_path_factory, pytestconfig):
27
+ directory = tmp_path_factory.mktemp("workload_wheels")
28
+ manifests = {}
29
+ for manifest in pytestconfig.rootpath.glob("pkgs/*/*/pyproject.toml"):
30
+ project = tomllib.loads(manifest.read_text(encoding="utf-8")).get("project")
31
+ if project:
32
+ manifests[canonicalize_name(project["name"])] = (manifest.parent, project)
33
+ return directory, manifests
34
+
35
+
36
+ def run_installed(wheelhouse, directory, roots, exercises, excluded, *, helpers=()):
37
+ import inspect
38
+
39
+ wheels, manifests = wheelhouse
40
+ pending = list(roots)
41
+ built = set()
42
+ env = os.environ.copy()
43
+ env.pop("PYTHONPATH", None)
44
+ env.setdefault("UV_CACHE_DIR", str(wheels / "uv-cache"))
45
+ env.setdefault("UV_LINK_MODE", "copy")
46
+ while pending:
47
+ name = pending.pop()
48
+ if name in built or name not in manifests:
49
+ continue
50
+ source, project = manifests[name]
51
+ if not list(wheels.glob(f"{name.replace('-', '_')}-*.whl")):
52
+ if env.get("TBA_TEST_POETRY_CORE_PATH"):
53
+ build_env = {**env, "PYTHONPATH": env["TBA_TEST_POETRY_CORE_PATH"]}
54
+ run_command(
55
+ sys.executable,
56
+ "-c",
57
+ "from poetry.core.masonry.api import build_wheel; import sys; build_wheel(sys.argv[1])",
58
+ str(wheels),
59
+ cwd=source,
60
+ env=build_env,
61
+ )
62
+ else:
63
+ run_command(
64
+ "uv",
65
+ "build",
66
+ "--wheel",
67
+ "--out-dir",
68
+ str(wheels),
69
+ str(source),
70
+ cwd=directory,
71
+ env=env,
72
+ )
73
+ built.add(name)
74
+ pending.extend(
75
+ canonicalize_name(Requirement(dep).name)
76
+ for dep in project.get("dependencies", [])
77
+ )
78
+
79
+ venv = directory / "venv"
80
+ run_command(
81
+ "uv", "venv", "--python", sys.executable, str(venv), cwd=directory, env=env
82
+ )
83
+ python = venv / ("Scripts/python.exe" if os.name == "nt" else "bin/python")
84
+ wheel_source = env.get("TBA_TEST_EXTERNAL_WHEELS")
85
+ dependency_links = ("--find-links", wheel_source) if wheel_source else ()
86
+ run_command(
87
+ "uv",
88
+ "pip",
89
+ "install",
90
+ "--python",
91
+ str(python),
92
+ "--find-links",
93
+ str(wheels),
94
+ *dependency_links,
95
+ *(f"{name}=={manifests[name][1]['version']}" for name in roots),
96
+ cwd=directory,
97
+ env=env,
98
+ )
99
+ run_command("uv", "pip", "check", "--python", str(python), cwd=directory, env=env)
100
+ script = directory / "verify.py"
101
+ script.write_text(
102
+ "from importlib.metadata import distributions\nimport json\n"
103
+ + "\n".join(
104
+ textwrap.dedent(inspect.getsource(exercise))
105
+ for exercise in (*helpers, *exercises)
106
+ )
107
+ + "\n".join(f"{exercise.__name__}()" for exercise in exercises)
108
+ + "\nprint(json.dumps({d.metadata['Name']: d.version for d in distributions()}, sort_keys=True))\n",
109
+ encoding="utf-8",
110
+ )
111
+ inventory = json.loads(
112
+ run_command(str(python), "-I", str(script), cwd=directory, env=env)
113
+ )
114
+ assert set(roots) <= {canonicalize_name(name) for name in inventory}
115
+ assert not {
116
+ name
117
+ for name in inventory
118
+ if set(canonicalize_name(name).split("-")).intersection(excluded)
119
+ }
120
+ return inventory