Skip to content

Commit

Permalink
Fix flakey sigv4 test (#1222)
Browse files Browse the repository at this point in the history
Signed-off-by: Andre Kurait <[email protected]>
  • Loading branch information
AndreKurait authored Jan 3, 2025
1 parent c79186d commit 933ef76
Showing 1 changed file with 8 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -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
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 933ef76

Please sign in to comment.