mirror of
https://github.com/GSA/notifications-api.git
synced 2026-01-31 15:15:38 -05:00
Merge pull request #3325 from alphagov/prevent-empty-areas-178986763
Add validation to prevent blank area names
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
import re
|
||||
|
||||
WAINFLEET = """
|
||||
<alert xmlns="urn:oasis:names:tc:emergency:cap:1.2">
|
||||
<identifier>50385fcb0ab7aa447bbd46d848ce8466E</identifier>
|
||||
@@ -235,3 +237,4 @@ WITH_PLACEHOLDER_FOR_CONTENT = """
|
||||
|
||||
LONG_GSM7 = WITH_PLACEHOLDER_FOR_CONTENT.format('a' * 1396)
|
||||
LONG_UCS2 = WITH_PLACEHOLDER_FOR_CONTENT.format('ŵ' * 616)
|
||||
MISSING_AREA_NAMES = re.sub("<areaDesc>.*</areaDesc>", "<areaDesc> </areaDesc>", WAINFLEET)
|
||||
|
||||
@@ -28,7 +28,7 @@ def test_broadcast_for_service_without_permission_returns_400(
|
||||
)
|
||||
|
||||
|
||||
def test_valid_post_broadcast_returns_201(
|
||||
def test_post_broadcast_non_cap_xml_returns_415(
|
||||
client,
|
||||
sample_broadcast_service,
|
||||
):
|
||||
@@ -229,3 +229,24 @@ def test_content_too_long_returns_400(
|
||||
}],
|
||||
'status_code': 400,
|
||||
}
|
||||
|
||||
|
||||
def test_invalid_areas_returns_400(
|
||||
client,
|
||||
sample_broadcast_service
|
||||
):
|
||||
auth_header = create_service_authorization_header(service_id=sample_broadcast_service.id)
|
||||
response = client.post(
|
||||
path='/v2/broadcast',
|
||||
data=sample_cap_xml_documents.MISSING_AREA_NAMES,
|
||||
headers=[('Content-Type', 'application/cap+xml'), auth_header],
|
||||
)
|
||||
|
||||
assert json.loads(response.get_data(as_text=True)) == {
|
||||
'errors': [{
|
||||
'error': 'ValidationError',
|
||||
# the blank spaces represent the blank areaDesc in the XML
|
||||
'message': 'areas does not match ([a-zA-Z1-9]+ )*[a-zA-Z1-9]+',
|
||||
}],
|
||||
'status_code': 400,
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user