|
28 | 28 | from unittest.mock import mock_open |
29 | 29 | from ..utils import Attachment, HTTPAttachment |
30 | 30 | from ..utils import parse_attachments |
| 31 | +from ..urlfilter import AppriseURLFilter |
| 32 | +from .. import utils |
31 | 33 | from django.test.utils import override_settings |
| 34 | +from django.conf import settings |
32 | 35 | from tempfile import TemporaryDirectory |
33 | 36 | from shutil import rmtree |
34 | 37 | import base64 |
@@ -92,8 +95,25 @@ def test_form_file_attachment_parsing(self): |
92 | 95 | """ |
93 | 96 | Test the parsing of file attachments |
94 | 97 | """ |
95 | | - # Get ourselves a file to work with |
| 98 | + # Variation tests without any data |
| 99 | + result = parse_attachments(None, None) |
| 100 | + assert isinstance(result, list) |
| 101 | + assert len(result) == 0 |
| 102 | + |
| 103 | + result = parse_attachments([], []) |
| 104 | + assert isinstance(result, list) |
| 105 | + assert len(result) == 0 |
| 106 | + |
| 107 | + with override_settings(APPRISE_ATTACH_SIZE=0): |
| 108 | + result = parse_attachments(None, None) |
| 109 | + assert isinstance(result, list) |
| 110 | + assert len(result) == 0 |
96 | 111 |
|
| 112 | + result = parse_attachments([], []) |
| 113 | + assert isinstance(result, list) |
| 114 | + assert len(result) == 0 |
| 115 | + |
| 116 | + # Get ourselves a file to work with |
97 | 117 | files_request = { |
98 | 118 | 'file1': SimpleUploadedFile( |
99 | 119 | "attach.txt", b"content here", content_type="text/plain") |
@@ -229,6 +249,20 @@ def test(*args, **kwargs): |
229 | 249 | assert isinstance(result, list) |
230 | 250 | assert len(result) == 3 |
231 | 251 |
|
| 252 | + with override_settings(APPRISE_ATTACH_DENY_URLS='*'): |
| 253 | + utils.ATTACH_URL_FILTER = AppriseURLFilter( |
| 254 | + settings.APPRISE_ATTACH_ALLOW_URLS, |
| 255 | + settings.APPRISE_ATTACH_DENY_URLS) |
| 256 | + |
| 257 | + # We will fail to parse our URL based attachment |
| 258 | + with self.assertRaises(ValueError): |
| 259 | + parse_attachments(attachment_payload, {}) |
| 260 | + |
| 261 | + # Reload our configuration to default values |
| 262 | + utils.ATTACH_URL_FILTER = AppriseURLFilter( |
| 263 | + settings.APPRISE_ATTACH_ALLOW_URLS, |
| 264 | + settings.APPRISE_ATTACH_DENY_URLS) |
| 265 | + |
232 | 266 | # Garbage handling (integer, float, object, etc is invalid) |
233 | 267 | attachment_payload = 5 |
234 | 268 | result = parse_attachments(attachment_payload, {}) |
|
0 commit comments