forked from mtusi2026/mtusi2026lab7
fix(pki): bind operator token cache to the active certificate
This commit is contained in:
@@ -154,3 +154,65 @@ def test_bootstrap_renews_when_replacement_ca_has_the_same_subject(
|
||||
assert (
|
||||
bootstrap.OPERATOR / "service-secrets.json"
|
||||
).read_bytes() == original
|
||||
|
||||
|
||||
def test_operator_token_cache_is_invalidated_when_client_certificate_changes(
|
||||
tmp_path, monkeypatch
|
||||
):
|
||||
from scripts import bao_operator as bao
|
||||
from scripts import bootstrap_security as bootstrap
|
||||
|
||||
monkeypatch.setattr(bootstrap, "OPERATOR", tmp_path / "operator")
|
||||
monkeypatch.setattr(bootstrap, "SECRET", tmp_path / "secrets")
|
||||
monkeypatch.setattr(bootstrap, "TRUST", tmp_path / "trust")
|
||||
bootstrap.generate()
|
||||
monkeypatch.setattr(bao, "OPERATOR", bootstrap.OPERATOR)
|
||||
monkeypatch.setattr(bao, "TRUST", bootstrap.TRUST)
|
||||
first = bao.Operator()
|
||||
monkeypatch.setattr(
|
||||
first,
|
||||
"call",
|
||||
lambda *args: {
|
||||
"auth": {
|
||||
"client_token": "synthetic-test-token-one",
|
||||
"lease_duration": 120,
|
||||
}
|
||||
},
|
||||
)
|
||||
try:
|
||||
assert first.authenticate() == "synthetic-test-token-one"
|
||||
first_fingerprint = first.cert_fingerprint
|
||||
finally:
|
||||
first.close()
|
||||
key, root = bootstrap.ca()
|
||||
client_key, client_cert = bootstrap.sign_leaf(
|
||||
key, root, "operator", ["operator"]
|
||||
)
|
||||
bootstrap.write_private(
|
||||
bootstrap.OPERATOR / "client/key.pem", bootstrap.key_bytes(client_key)
|
||||
)
|
||||
bootstrap.write_private(
|
||||
bootstrap.OPERATOR / "client/cert.pem",
|
||||
bootstrap.public(client_cert) + bootstrap.public(root),
|
||||
)
|
||||
second = bao.Operator()
|
||||
calls = []
|
||||
|
||||
def login(*args):
|
||||
calls.append(args)
|
||||
return {
|
||||
"auth": {
|
||||
"client_token": "synthetic-test-token-two",
|
||||
"lease_duration": 120,
|
||||
}
|
||||
}
|
||||
|
||||
monkeypatch.setattr(second, "call", login)
|
||||
try:
|
||||
assert second.cert_fingerprint != first_fingerprint
|
||||
assert second.authenticate() == "synthetic-test-token-two"
|
||||
assert len(calls) == 1
|
||||
assert second.authenticate() == "synthetic-test-token-two"
|
||||
assert len(calls) == 1
|
||||
finally:
|
||||
second.close()
|
||||
|
||||
Reference in New Issue
Block a user