Add encrypted envelope recipient state

This commit is contained in:
2026-07-31 22:48:07 +02:00
parent dc6f81dd33
commit e3daf400f3
10 changed files with 272 additions and 2 deletions
+63
View File
@@ -29,7 +29,9 @@ from govoplan_core.core.organizations import (
from govoplan_core.core.postbox import (
PostboxActorRef,
PostboxDeliveryRequest,
PostboxExternalRecipientTokenRef,
PostboxTargetRef,
PostboxWrappedKeyRef,
)
from govoplan_core.db.base import Base
from govoplan_core.security.time import utc_now
@@ -1173,6 +1175,67 @@ class PostboxServiceTests(unittest.TestCase):
self.assertFalse(summaries[expired.delivery_id].currently_readable)
self.assertEqual(1, summaries[expired.delivery_id].expired_message_count)
def test_encrypted_envelope_and_external_grant_state_cross_capability(self) -> None:
self.idm.assignments.append(self.assignment)
expires_at = utc_now() + timedelta(days=1)
with Session(self.engine) as session:
postbox = self._create_exact(session)
delivered = self.service.deliver(
session,
PostboxDeliveryRequest(
tenant_id="tenant-1",
target=PostboxTargetRef(postbox_id=postbox.id),
producer_module="campaigns",
producer_resource_type="campaign_recipient",
producer_resource_id="recipient-encrypted",
idempotency_key="encrypted-message",
subject="Encrypted decision",
ciphertext_ref="files:ciphertext-1",
signed_manifest_ref="files:manifest-1",
wrapped_keys=(
PostboxWrappedKeyRef(
recipient_type="function_postbox",
recipient_id=postbox.id,
key_epoch=postbox.key_epoch,
wrapped_key_ref="trust:wrapped-key-1",
algorithm="HPKE-v1",
),
),
external_recipient_tokens=(
PostboxExternalRecipientTokenRef(
token_id="grant-1",
state="available",
expires_at=expires_at,
one_time=True,
assurance_profile="email-otp",
),
),
),
)
message = self.service.get_message(
session,
tenant_id="tenant-1",
message_id=delivered.message_id,
actor=self.actor,
)
assert message is not None
self.assertEqual("files:ciphertext-1", message.ciphertext_ref)
self.assertEqual(
"trust:wrapped-key-1",
message.wrapped_keys[0].wrapped_key_ref,
)
self.assertEqual("grant-1", message.external_recipient_tokens[0].token_id)
self.assertEqual("available", message.external_recipient_tokens[0].state)
assert message.external_recipient_tokens[0].expires_at is not None
self.assertEqual(
expires_at.replace(microsecond=0),
message.external_recipient_tokens[0].expires_at.replace(
microsecond=0
),
)
def test_hierarchy_linked_copy_snapshots_path_and_independent_state(
self,
) -> None: