Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion contract-version.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"},
Expand Down
29 changes: 29 additions & 0 deletions tests/test_email_validation.py
Original file line number Diff line number Diff line change
@@ -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}