From a2790cc7b7d1310cd84b7f41763b3f74b9f5d97d Mon Sep 17 00:00:00 2001 From: Fred <323546+fguillot@users.noreply.github.com> Date: Tue, 24 Mar 2026 17:40:03 -0700 Subject: [PATCH] test: add coverage for SSL, user agent, and async execution Add tests for cafile, insecure, and ignore_hostname_verification SSL parameters, custom and default user agent headers, and actual async call execution with result verification. --- tests/test_kanboard.py | 49 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/tests/test_kanboard.py b/tests/test_kanboard.py index 08c3be7..03f42a0 100644 --- a/tests/test_kanboard.py +++ b/tests/test_kanboard.py @@ -105,6 +105,55 @@ def test_async_call_generates_coro(self): method = self.client.my_method_async() self.assertIsInstance(method, types.CoroutineType) + def test_async_call_returns_result(self): + body = b'{"jsonrpc": "2.0", "result": 42, "id": 123}' + self.urlopen.return_value.read.return_value = body + loop = self.client._event_loop + result = loop.run_until_complete(self.client.my_method_async()) + self.assertEqual(42, result) + + def test_custom_user_agent(self): + client = kanboard.Client(self.url, "username", "password", user_agent="CustomAgent/1.0") + body = b'{"jsonrpc": "2.0", "result": true, "id": 123}' + self.urlopen.return_value.read.return_value = body + client.remote_procedure() + _, kwargs = self.request.call_args + self.assertEqual("CustomAgent/1.0", kwargs["headers"]["User-Agent"]) + + def test_default_user_agent(self): + body = b'{"jsonrpc": "2.0", "result": true, "id": 123}' + self.urlopen.return_value.read.return_value = body + self.client.remote_procedure() + _, kwargs = self.request.call_args + self.assertEqual("Kanboard Python API Client", kwargs["headers"]["User-Agent"]) + + @mock.patch("ssl.create_default_context") + def test_insecure_disables_ssl_verification(self, mock_ssl_context): + client = kanboard.Client(self.url, "username", "password", insecure=True) + ctx = mock_ssl_context.return_value + body = b'{"jsonrpc": "2.0", "result": true, "id": 123}' + self.urlopen.return_value.read.return_value = body + client.remote_procedure() + self.assertFalse(ctx.check_hostname) + self.assertEqual(ctx.verify_mode, __import__("ssl").CERT_NONE) + + @mock.patch("ssl.create_default_context") + def test_ignore_hostname_verification(self, mock_ssl_context): + client = kanboard.Client(self.url, "username", "password", ignore_hostname_verification=True) + ctx = mock_ssl_context.return_value + body = b'{"jsonrpc": "2.0", "result": true, "id": 123}' + self.urlopen.return_value.read.return_value = body + client.remote_procedure() + self.assertFalse(ctx.check_hostname) + + @mock.patch("ssl.create_default_context") + def test_cafile_passed_to_ssl_context(self, mock_ssl_context): + client = kanboard.Client(self.url, "username", "password", cafile="/path/to/ca.pem") + body = b'{"jsonrpc": "2.0", "result": true, "id": 123}' + self.urlopen.return_value.read.return_value = body + client.remote_procedure() + mock_ssl_context.assert_called_once_with(cafile="/path/to/ca.pem") + @staticmethod def _create_mocks(): request_patcher = mock.patch("urllib.request.Request")