From c4aa34bf5c00a6eded73c08d748533527c89f583 Mon Sep 17 00:00:00 2001 From: Dan Helfman Date: Sat, 30 Nov 2019 14:51:32 -0800 Subject: [PATCH] Fix for missing Healthchecks monitoring payload or HTTP 500 due to incorrect unicode encoding (#260). --- NEWS | 3 +++ borgmatic/hooks/healthchecks.py | 2 +- setup.py | 2 +- tests/unit/hooks/test_healthchecks.py | 16 +++++++++------- 4 files changed, 14 insertions(+), 9 deletions(-) diff --git a/NEWS b/NEWS index 7e41121..9233382 100644 --- a/NEWS +++ b/NEWS @@ -1,3 +1,6 @@ +1.4.16 + * Fix for missing Healthchecks monitoring payload or HTTP 500 due to incorrect unicode encoding. + 1.4.15 * Fix for database dump removal incorrectly skipping some database dumps. * #123: Support for mounting an archive as a FUSE filesystem via "borgmatic mount" action, and diff --git a/borgmatic/hooks/healthchecks.py b/borgmatic/hooks/healthchecks.py index 19201d0..a116205 100644 --- a/borgmatic/hooks/healthchecks.py +++ b/borgmatic/hooks/healthchecks.py @@ -97,4 +97,4 @@ def ping_monitor(ping_url_or_uuid, config_filename, state, dry_run): if not dry_run: logging.getLogger('urllib3').setLevel(logging.ERROR) - requests.post(ping_url, data=payload) + requests.post(ping_url, data=payload.encode('utf-8')) diff --git a/setup.py b/setup.py index cf16442..46871a9 100644 --- a/setup.py +++ b/setup.py @@ -1,6 +1,6 @@ from setuptools import find_packages, setup -VERSION = '1.4.15' +VERSION = '1.4.16' setup( diff --git a/tests/unit/hooks/test_healthchecks.py b/tests/unit/hooks/test_healthchecks.py index cbb9cc7..24e8fca 100644 --- a/tests/unit/hooks/test_healthchecks.py +++ b/tests/unit/hooks/test_healthchecks.py @@ -60,7 +60,7 @@ def test_ping_monitor_hits_ping_url_for_start_state(): flexmock(module).should_receive('Forgetful_buffering_handler') ping_url = 'https://example.com' flexmock(module.requests).should_receive('post').with_args( - '{}/{}'.format(ping_url, 'start'), data='' + '{}/{}'.format(ping_url, 'start'), data=''.encode('utf-8') ) module.ping_monitor(ping_url, 'config.yaml', state=module.monitor.State.START, dry_run=False) @@ -68,19 +68,21 @@ def test_ping_monitor_hits_ping_url_for_start_state(): def test_ping_monitor_hits_ping_url_for_finish_state(): ping_url = 'https://example.com' - payload = flexmock() + payload = 'data' flexmock(module).should_receive('format_buffered_logs_for_payload').and_return(payload) - flexmock(module.requests).should_receive('post').with_args(ping_url, data=payload) + flexmock(module.requests).should_receive('post').with_args( + ping_url, data=payload.encode('utf-8') + ) module.ping_monitor(ping_url, 'config.yaml', state=module.monitor.State.FINISH, dry_run=False) def test_ping_monitor_hits_ping_url_for_fail_state(): ping_url = 'https://example.com' - payload = flexmock() + payload = 'data' flexmock(module).should_receive('format_buffered_logs_for_payload').and_return(payload) flexmock(module.requests).should_receive('post').with_args( - '{}/{}'.format(ping_url, 'fail'), data=payload + '{}/{}'.format(ping_url, 'fail'), data=payload.encode('utf') ) module.ping_monitor(ping_url, 'config.yaml', state=module.monitor.State.FAIL, dry_run=False) @@ -88,10 +90,10 @@ def test_ping_monitor_hits_ping_url_for_fail_state(): def test_ping_monitor_with_ping_uuid_hits_corresponding_url(): ping_uuid = 'abcd-efgh-ijkl-mnop' - payload = flexmock() + payload = 'data' flexmock(module).should_receive('format_buffered_logs_for_payload').and_return(payload) flexmock(module.requests).should_receive('post').with_args( - 'https://hc-ping.com/{}'.format(ping_uuid), data=payload + 'https://hc-ping.com/{}'.format(ping_uuid), data=payload.encode('utf-8') ) module.ping_monitor(ping_uuid, 'config.yaml', state=module.monitor.State.FINISH, dry_run=False)