From 29255c2063818bb6838723a3ecdca14d7a5f5644 Mon Sep 17 00:00:00 2001 From: Chris Caron Date: Sat, 18 Nov 2023 12:36:22 -0500 Subject: [PATCH] altered synology payload --- apprise/plugins/NotifySynology.py | 5 ++-- test/test_plugin_synology.py | 43 +++++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+), 2 deletions(-) diff --git a/apprise/plugins/NotifySynology.py b/apprise/plugins/NotifySynology.py index 7609aa9a0..faea159e1 100644 --- a/apprise/plugins/NotifySynology.py +++ b/apprise/plugins/NotifySynology.py @@ -215,7 +215,8 @@ def send(self, body, title='', notify_type=NotifyType.INFO, **kwargs): # Prepare HTTP Headers headers = { 'User-Agent': self.app_id, - 'Content-Type': 'application/json' + 'Content-Type': 'application/x-www-form-urlencoded', + 'Accept': '*/*', } # Apply any/all header over-rides defined @@ -262,7 +263,7 @@ def send(self, body, title='', notify_type=NotifyType.INFO, **kwargs): try: r = requests.post( url, - data=dumps(payload), + data=f"payload={dumps(payload)}", params=params, headers=headers, auth=auth, diff --git a/test/test_plugin_synology.py b/test/test_plugin_synology.py index ae03ce10d..a702f812d 100644 --- a/test/test_plugin_synology.py +++ b/test/test_plugin_synology.py @@ -31,6 +31,7 @@ # POSSIBILITY OF SUCH DAMAGE. import requests +from unittest import mock from apprise.plugins.NotifySynology import NotifySynology from helpers import AppriseURLTester @@ -133,3 +134,45 @@ def test_plugin_custom_synology_urls(): # Run our general tests AppriseURLTester(tests=apprise_url_tests).run_all() + + +@mock.patch('requests.post') +def test_plugin_synology_edge_cases(mock_post): + """ + NotifySynology() Edge Cases + + """ + + # Prepare our response + response = requests.Request() + response.status_code = requests.codes.ok + + # Prepare Mock + mock_post.return_value = response + + # This string also tests that type is set to nothing + results = NotifySynology.parse_url( + 'synology://user:pass@localhost:8080/token') + + assert isinstance(results, dict) + assert results['user'] == 'user' + assert results['password'] == 'pass' + assert results['port'] == 8080 + assert results['host'] == 'localhost' + assert results['fullpath'] == '' + assert results['path'] == '/' + assert results['query'] == 'token' + assert results['schema'] == 'synology' + assert results['url'] == 'synology://user:pass@localhost:8080/token' + + instance = NotifySynology(**results) + assert isinstance(instance, NotifySynology) + + response = instance.send(title='title', body='body') + assert response is True + assert mock_post.call_count == 1 + + details = mock_post.call_args_list[0] + assert details[0][0] == 'http://localhost:8080/webapi/entry.cgi' + + assert details[1]['data'].startswith('payload=')