From 1cef9276edf765eb0179ab8f87370d7c5022eb1c Mon Sep 17 00:00:00 2001 From: Thanasis Daglis Date: Wed, 9 Sep 2026 12:53:02 +0300 Subject: [PATCH] fix: align bundled email schema with delivery validation --- contract-version.json | 2 +- .../contract/schemas/ticket-1.0.schema.json | 2 +- tests/test_email_validation.py | 29 +++++++++++++++++++ 3 files changed, 31 insertions(+), 2 deletions(-) create mode 100644 tests/test_email_validation.py diff --git a/contract-version.json b/contract-version.json index 10e4bd9..80a06a5 100644 --- a/contract-version.json +++ b/contract-version.json @@ -14,7 +14,7 @@ }, { "path": "src/intryc_delivery/contract/schemas/ticket-1.0.schema.json", - "sha256": "9389b3be4da3b58a81276d874b36ba8eee4876d6d2ae15ba604b2703a0673944" + "sha256": "3fa1ebcffbaac6e372182083a31c3a131d8036d3715954e092f0b5b288092a0f" }, { "path": "src/intryc_delivery/contract/schemas/ticket-delivery-1.0.schema.json", diff --git a/src/intryc_delivery/contract/schemas/ticket-1.0.schema.json b/src/intryc_delivery/contract/schemas/ticket-1.0.schema.json index a29a791..5d3fe93 100644 --- a/src/intryc_delivery/contract/schemas/ticket-1.0.schema.json +++ b/src/intryc_delivery/contract/schemas/ticket-1.0.schema.json @@ -68,7 +68,7 @@ "properties": { "source_user_id": {"$ref": "#/$defs/userReference"}, "name": {"type": "string", "minLength": 1, "pattern": "\\S", "maxLength": 1024}, - "email": {"type": "string", "format": "email"}, + "email": {"type": "string", "format": "email", "pattern": "^\\s*[^@\\s]+@[^@\\s]+\\.[^@\\s]+\\s*$", "description": "Use a basic name@domain.tld email address. Surrounding whitespace is trimmed and letters are lowercased during import."}, "role": {"$ref": "#/$defs/role"}, "active": {"type": "boolean"}, "created_at": {"type": "string", "format": "date-time"}, diff --git a/tests/test_email_validation.py b/tests/test_email_validation.py new file mode 100644 index 0000000..4e8351a --- /dev/null +++ b/tests/test_email_validation.py @@ -0,0 +1,29 @@ +import json + +import pytest + +from intryc_delivery.contract.semantic import ContractValidationError, parse_ticket +from intryc_delivery.validation import schema_validators + + +@pytest.mark.parametrize( + "email,accepted", + [ + ("agent@example.com", True), + (" Agent+support@Sub.Example.com ", True), + ("agent@localhost", False), + ("agent@@example.com", False), + ("agent name@example.com", False), + ], +) +def test_email_schema_matches_validation(root, email, accepted): + ticket = json.loads((root / "ticket_details/written.json").read_bytes()) + ticket["users"][0]["email"] = email + assert schema_validators()["ticket-1.0.schema.json"].is_valid(ticket) is accepted + if accepted: + validated = parse_ticket(ticket, expected_source_ticket_id=ticket["source_ticket_id"]) + assert validated.data["users"][0]["email"] == email.strip().lower() + else: + with pytest.raises(ContractValidationError) as error: + parse_ticket(ticket, expected_source_ticket_id=ticket["source_ticket_id"]) + assert "INVALID_USER_EMAIL" in {issue.code for issue in error.value.issues}