From 2db5d743dae11ce01fb5250dd7e9095208be3c78 Mon Sep 17 00:00:00 2001 From: Mauricio Magnani Date: Tue, 14 May 2024 10:02:24 -0300 Subject: [PATCH] [AAP-23958] - Investigate errors in unit tests in eda collection --- .../eda/plugins/event_source/alertmanager.py | 2 +- .../test_webhook_source.py | 8 +++---- tests/unit/event_source/test_alertmanager.py | 6 ++--- tests/unit/event_source/test_webhook.py | 24 +++++++++---------- 4 files changed, 20 insertions(+), 20 deletions(-) diff --git a/extensions/eda/plugins/event_source/alertmanager.py b/extensions/eda/plugins/event_source/alertmanager.py index 7384b347..ffd1f032 100644 --- a/extensions/eda/plugins/event_source/alertmanager.py +++ b/extensions/eda/plugins/event_source/alertmanager.py @@ -6,7 +6,7 @@ Arguments: --------- host: The webserver hostname to listen to. Set to 0.0.0.0 to listen on all - interfaces. Defaults to 127.0.0.1 + interfaces. Defaults to localhost port: The TCP port to listen to. Defaults to 5000 data_alerts_path: The json path to find alert data. Default to "alerts" Use empty string "" to treat the whole payload data as diff --git a/tests/integration/event_source_webhook/test_webhook_source.py b/tests/integration/event_source_webhook/test_webhook_source.py index 0a65bef6..efe36254 100644 --- a/tests/integration/event_source_webhook/test_webhook_source.py +++ b/tests/integration/event_source_webhook/test_webhook_source.py @@ -40,7 +40,7 @@ def test_webhook_source_sanity(subprocess_teardown, port: int): json.dumps({"shutdown": ""}).encode("ascii"), ] - url = f"http://127.0.0.1:{port}/webhook" + url = f"http://localhost:{port}/webhook" env = os.environ.copy() env["WH_PORT"] = str(port) @@ -66,7 +66,7 @@ def test_webhook_source_sanity(subprocess_teardown, port: int): stdout, _unused_stderr = proc.communicate() assert "Rule fired successfully" in stdout.decode() - assert f"'Host': '127.0.0.1:{port}'" in stdout.decode() + assert f"'Host': 'localhost:{port}'" in stdout.decode() assert proc.returncode == 0 @@ -105,7 +105,7 @@ def test_webhook_source_hmac_sanity(subprocess_teardown): ] port = 5000 - url = f"http://127.0.0.1:{port}/webhook" + url = f"http://localhost:{port}/webhook" env = os.environ.copy() env["WH_PORT"] = str(port) @@ -132,7 +132,7 @@ def test_webhook_source_hmac_sanity(subprocess_teardown): stdout, _unused_stderr = proc.communicate() assert "Rule fired successfully" in stdout.decode() - assert f"'Host': '127.0.0.1:{port}'" in stdout.decode() + assert f"'Host': 'localhost:{port}'" in stdout.decode() assert proc.returncode == 0 diff --git a/tests/unit/event_source/test_alertmanager.py b/tests/unit/event_source/test_alertmanager.py index 678116b9..bb88e0b4 100644 --- a/tests/unit/event_source/test_alertmanager.py +++ b/tests/unit/event_source/test_alertmanager.py @@ -29,7 +29,7 @@ async def cancel_code(server_task): async def test_cancel(): queue = asyncio.Queue() - args = {"host": "127.0.0.1", "port": 8001} + args = {"host": "localhost", "port": 8001} plugin_task = asyncio.create_task(start_server(queue, args)) cancel_task = asyncio.create_task(cancel_code(plugin_task)) @@ -41,7 +41,7 @@ async def test_cancel(): async def test_post_endpoint_with_default(): queue = asyncio.Queue() - args = {"host": "127.0.0.1", "port": 8002} + args = {"host": "localhost", "port": 8002} plugin_task = asyncio.create_task(start_server(queue, args)) task_info = { @@ -86,7 +86,7 @@ async def test_post_endpoint_with_options(): queue = asyncio.Queue() args = { - "host": "127.0.0.1", + "host": "localhost", "port": 8003, "data_alerts_path": "", "data_host_path": "node", diff --git a/tests/unit/event_source/test_webhook.py b/tests/unit/event_source/test_webhook.py index 70e34c33..b9c3b1fe 100644 --- a/tests/unit/event_source/test_webhook.py +++ b/tests/unit/event_source/test_webhook.py @@ -52,7 +52,7 @@ async def cancel_code(server_task): async def test_cancel(): queue = asyncio.Queue() - args = {"host": "127.0.0.1", "port": 8000, "token": "secret"} + args = {"host": "localhost", "port": 8000, "token": "secret"} plugin_task = asyncio.create_task(start_server(queue, args)) cancel_task = asyncio.create_task(cancel_code(plugin_task)) @@ -64,7 +64,7 @@ async def test_cancel(): async def test_post_endpoint(): queue = asyncio.Queue() - args = {"host": "127.0.0.1", "port": 8000, "token": "secret"} + args = {"host": "localhost", "port": 8000, "token": "secret"} plugin_task = asyncio.create_task(start_server(queue, args)) task_info = { @@ -86,7 +86,7 @@ async def test_post_endpoint(): @pytest.mark.asyncio async def test_post_unsupported_body(): queue = asyncio.Queue() - args = {"host": "127.0.0.1", "port": 8000} + args = {"host": "localhost", "port": 8000} async def do_request(): async with aiohttp.ClientSession() as session: @@ -105,7 +105,7 @@ async def test_post_hmac_hex_endpoint(): queue = asyncio.Queue() args = { - "host": "127.0.0.1", + "host": "localhost", "port": 8000, "hmac_secret": "secret", "hmac_algo": "sha256", @@ -138,7 +138,7 @@ async def test_post_hmac_hex_wo_digest_prefix_endpoint(): queue = asyncio.Queue() args = { - "host": "127.0.0.1", + "host": "localhost", "port": 8000, "hmac_secret": "secret", "hmac_algo": "sha256", @@ -171,7 +171,7 @@ async def test_post_hmac_hex_endpoint_invalid_signature(): queue = asyncio.Queue() args = { - "host": "127.0.0.1", + "host": "localhost", "port": 8000, "hmac_secret": "secret", "hmac_algo": "sha256", @@ -201,7 +201,7 @@ async def test_post_hmac_hex_endpoint_missing_signature(): queue = asyncio.Queue() args = { - "host": "127.0.0.1", + "host": "localhost", "port": 8000, "hmac_secret": "secret", "hmac_algo": "sha256", @@ -231,7 +231,7 @@ async def test_post_hmac_base64_endpoint(): queue = asyncio.Queue() args = { - "host": "127.0.0.1", + "host": "localhost", "port": 8000, "hmac_secret": "secret", "hmac_algo": "sha256", @@ -264,7 +264,7 @@ async def test_post_hmac_base64_endpoint_invalid_signature(): queue = asyncio.Queue() args = { - "host": "127.0.0.1", + "host": "localhost", "port": 8000, "hmac_secret": "secret", "hmac_algo": "sha256", @@ -294,7 +294,7 @@ async def test_post_token_and_hmac_hex_endpoint(): queue = asyncio.Queue() args = { - "host": "127.0.0.1", + "host": "localhost", "port": 8000, "token": "secret", "hmac_secret": "secret", @@ -326,7 +326,7 @@ async def test_post_token_and_hmac_hex_endpoint_invalid_signature(): queue = asyncio.Queue() args = args = { - "host": "127.0.0.1", + "host": "localhost", "port": 8000, "token": "secret", "hmac_secret": "secret", @@ -356,7 +356,7 @@ async def test_post_token_and_hmac_hex_endpoint_invalid_token(): queue = asyncio.Queue() args = { - "host": "127.0.0.1", + "host": "localhost", "port": 8000, "token": "secret", "hmac_secret": "secret",