From 933ef768bc4ec54bd74edfc985bb92c84357d3e5 Mon Sep 17 00:00:00 2001 From: Andre Kurait Date: Fri, 3 Jan 2025 16:08:28 -0600 Subject: [PATCH] Fix flakey sigv4 test (#1222) Signed-off-by: Andre Kurait --- .../lib/console_link/tests/test_cluster.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/TrafficCapture/dockerSolution/src/main/docker/migrationConsole/lib/console_link/tests/test_cluster.py b/TrafficCapture/dockerSolution/src/main/docker/migrationConsole/lib/console_link/tests/test_cluster.py index ca0636e39..76e18ad97 100644 --- a/TrafficCapture/dockerSolution/src/main/docker/migrationConsole/lib/console_link/tests/test_cluster.py +++ b/TrafficCapture/dockerSolution/src/main/docker/migrationConsole/lib/console_link/tests/test_cluster.py @@ -5,6 +5,8 @@ import pytest import re import json +import datetime +from unittest.mock import patch from base64 import b64encode from botocore.auth import SigV4Auth @@ -426,7 +428,6 @@ def test_run_benchmark_executes_correctly_basic_auth_and_https(mocker): f"basic_auth_password:{auth_details['password']}", shell=True) -@pytest.mark.skip(reason="Flaky test needs fix: https://opensearch.atlassian.net/browse/MIGRATIONS-2294") @pytest.mark.parametrize("method, endpoint, data, has_body", [ (HttpMethod.GET, "/_cluster/health", None, False), (HttpMethod.POST, "/_search", {"query": {"match_all": {}}}, True) @@ -449,8 +450,11 @@ def test_sigv4_authentication_signature(requests_mock, method, endpoint, data, h requests_mock.get(url, json={'status': 'green'}) elif method == HttpMethod.POST: requests_mock.post(url, json={'hits': {'total': 0, 'hits': []}}) + # Mock datetime to return a specific timestamp + specific_time = datetime.datetime(2025, 1, 1, 12, 0, 0) + with mock_aws() and patch("datetime.datetime") as mock_datetime: + mock_datetime.utcnow.return_value = specific_time - with mock_aws(): # Add default headers to the request headers = { # These headers are excluded from signing since they are in default request headers @@ -532,6 +536,8 @@ def test_sigv4_authentication_signature(requests_mock, method, endpoint, data, h new_auth_header = aws_request.headers.get('Authorization') assert new_auth_header is not None, "Failed to generate new Authorization header" + # Compare timestamp + assert amz_date_header == aws_request.headers.get("x-amz-date") # Compare signatures original_signature = signature_match.group(1) new_signature_match = re.search(r"Signature=([a-f0-9]+)", new_auth_header)