-
-
Notifications
You must be signed in to change notification settings - Fork 61
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Server-side handling of new apprise:// schema (#56)
- Loading branch information
Showing
6 changed files
with
261 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -492,3 +492,99 @@ def test_notify_with_filters(self, mock_send): | |
|
||
# nothing was changed | ||
assert apprise.plugins.SCHEMA_MAP['mailto'].enabled is True | ||
|
||
@override_settings(APPRISE_RECURSION_MAX=1) | ||
@patch('apprise.Apprise.notify') | ||
def test_stateful_notify_recursion(self, mock_notify): | ||
""" | ||
Test recursion an id header details as part of post | ||
""" | ||
|
||
# Set our return value | ||
mock_notify.return_value = True | ||
|
||
# our key to use | ||
key = 'test_stateful_notify_recursion' | ||
|
||
# Add some content | ||
response = self.client.post( | ||
'/add/{}'.format(key), | ||
{'urls': 'mailto://user:[email protected]'}) | ||
assert response.status_code == 200 | ||
|
||
# Form data | ||
form_data = { | ||
'body': 'test notifiction', | ||
} | ||
|
||
# Define our headers we plan to pass along with our request | ||
headers = { | ||
'HTTP_X-APPRISE-ID': 'abc123', | ||
'HTTP_X-APPRISE-RECURSION-COUNT': str(1), | ||
} | ||
|
||
# Send our notification | ||
response = self.client.post( | ||
'/notify/{}'.format(key), data=form_data, **headers) | ||
assert response.status_code == 200 | ||
assert mock_notify.call_count == 1 | ||
|
||
headers = { | ||
# Header specified but with whitespace | ||
'HTTP_X-APPRISE-ID': ' ', | ||
# No Recursion value specified | ||
} | ||
|
||
# Reset our count | ||
mock_notify.reset_mock() | ||
|
||
# Recursion limit reached | ||
response = self.client.post( | ||
'/notify/{}'.format(key), data=form_data, **headers) | ||
assert response.status_code == 200 | ||
assert mock_notify.call_count == 1 | ||
|
||
headers = { | ||
'HTTP_X-APPRISE-ID': 'abc123', | ||
# Recursion Limit hit | ||
'HTTP_X-APPRISE-RECURSION-COUNT': str(2), | ||
} | ||
|
||
# Reset our count | ||
mock_notify.reset_mock() | ||
|
||
# Recursion limit reached | ||
response = self.client.post( | ||
'/notify/{}'.format(key), data=form_data, **headers) | ||
assert response.status_code == 406 | ||
assert mock_notify.call_count == 0 | ||
|
||
headers = { | ||
'HTTP_X-APPRISE-ID': 'abc123', | ||
# Negative recursion value (bad request) | ||
'HTTP_X-APPRISE-RECURSION-COUNT': str(-1), | ||
} | ||
|
||
# Reset our count | ||
mock_notify.reset_mock() | ||
|
||
# invalid recursion specified | ||
response = self.client.post( | ||
'/notify/{}'.format(key), data=form_data, **headers) | ||
assert response.status_code == 400 | ||
assert mock_notify.call_count == 0 | ||
|
||
headers = { | ||
'HTTP_X-APPRISE-ID': 'abc123', | ||
# Invalid recursion value (bad request) | ||
'HTTP_X-APPRISE-RECURSION-COUNT': 'invalid', | ||
} | ||
|
||
# Reset our count | ||
mock_notify.reset_mock() | ||
|
||
# invalid recursion specified | ||
response = self.client.post( | ||
'/notify/{}'.format(key), data=form_data, **headers) | ||
assert response.status_code == 400 | ||
assert mock_notify.call_count == 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -113,6 +113,93 @@ def test_partial_notify(self, mock_notify): | |
assert response.status_code == 424 | ||
assert mock_notify.call_count == 2 | ||
|
||
@override_settings(APPRISE_RECURSION_MAX=1) | ||
@patch('apprise.Apprise.notify') | ||
def test_stateless_notify_recursion(self, mock_notify): | ||
""" | ||
Test recursion an id header details as part of post | ||
""" | ||
|
||
# Set our return value | ||
mock_notify.return_value = True | ||
|
||
headers = { | ||
'HTTP_X-APPRISE-ID': 'abc123', | ||
'HTTP_X-APPRISE-RECURSION-COUNT': str(1), | ||
} | ||
|
||
# Preare our form data (without url specified) | ||
# content will fall back to default configuration | ||
form_data = { | ||
'urls': 'mailto://user:[email protected]', | ||
'body': 'test notifiction', | ||
} | ||
|
||
# At a minimum 'body' is requred | ||
form = NotifyByUrlForm(data=form_data) | ||
assert form.is_valid() | ||
|
||
# recursion value is within correct limits | ||
response = self.client.post('/notify', form.cleaned_data, **headers) | ||
assert response.status_code == 200 | ||
assert mock_notify.call_count == 1 | ||
|
||
headers = { | ||
# Header specified but with whitespace | ||
'HTTP_X-APPRISE-ID': ' ', | ||
# No Recursion value specified | ||
} | ||
|
||
# Reset our count | ||
mock_notify.reset_mock() | ||
|
||
# Recursion limit reached | ||
response = self.client.post('/notify', form.cleaned_data, **headers) | ||
assert response.status_code == 200 | ||
assert mock_notify.call_count == 1 | ||
|
||
headers = { | ||
'HTTP_X-APPRISE-ID': 'abc123', | ||
# Recursion Limit hit | ||
'HTTP_X-APPRISE-RECURSION-COUNT': str(2), | ||
} | ||
|
||
# Reset our count | ||
mock_notify.reset_mock() | ||
|
||
# Recursion limit reached | ||
response = self.client.post('/notify', form.cleaned_data, **headers) | ||
assert response.status_code == 406 | ||
assert mock_notify.call_count == 0 | ||
|
||
headers = { | ||
'HTTP_X-APPRISE-ID': 'abc123', | ||
# Negative recursion value (bad request) | ||
'HTTP_X-APPRISE-RECURSION-COUNT': str(-1), | ||
} | ||
|
||
# Reset our count | ||
mock_notify.reset_mock() | ||
|
||
# invalid recursion specified | ||
response = self.client.post('/notify', form.cleaned_data, **headers) | ||
assert response.status_code == 400 | ||
assert mock_notify.call_count == 0 | ||
|
||
headers = { | ||
'HTTP_X-APPRISE-ID': 'abc123', | ||
# Invalid recursion value (bad request) | ||
'HTTP_X-APPRISE-RECURSION-COUNT': 'invalid', | ||
} | ||
|
||
# Reset our count | ||
mock_notify.reset_mock() | ||
|
||
# invalid recursion specified | ||
response = self.client.post('/notify', form.cleaned_data, **headers) | ||
assert response.status_code == 400 | ||
assert mock_notify.call_count == 0 | ||
|
||
@override_settings(APPRISE_STATELESS_URLS="mailto://user:pass@localhost") | ||
@patch('apprise.Apprise.notify') | ||
def test_notify_default_urls(self, mock_notify): | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,4 @@ | ||
django | ||
cryptography == 3.3.2 | ||
apprise == 0.9.6 | ||
|
||
# 3rd party service support | ||
|