From 74f8ff41750c3ae50ad3b41b750c66d26011c1c2 Mon Sep 17 00:00:00 2001 From: Igor Okulist Date: Mon, 19 Aug 2024 22:36:47 -0500 Subject: [PATCH] Update test to pass headers as dict --- awscurl/awscurl.py | 4 +++- tests/stages_test.py | 6 ++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/awscurl/awscurl.py b/awscurl/awscurl.py index 5b662d8..9f03493 100755 --- a/awscurl/awscurl.py +++ b/awscurl/awscurl.py @@ -12,6 +12,7 @@ import sys import re +from typing import Dict import urllib from urllib.parse import quote @@ -156,7 +157,7 @@ def remove_default_port(parsed_url): # pylint: disable=too-many-arguments,too-many-locals def task_1_create_a_canonical_request( query, - headers, + headers: Dict, port, host, amzdate, @@ -187,6 +188,7 @@ def task_1_create_a_canonical_request( # If the host was specified in the HTTP header, ensure that the canonical # headers are set accordingly + headers = requests.structures.CaseInsensitiveDict(headers) if 'host' in headers: fullhost = headers['host'] else: diff --git a/tests/stages_test.py b/tests/stages_test.py index 954b036..7682dd1 100644 --- a/tests/stages_test.py +++ b/tests/stages_test.py @@ -3,6 +3,8 @@ Test cases for seprate header calculation stages. """ +import json + from unittest import TestCase from awscurl.awscurl import ( @@ -25,7 +27,7 @@ def test_task_1_create_a_canonical_request(self): """ canonical_request, payload_hash, signed_headers = task_1_create_a_canonical_request( query="Action=DescribeInstances&Version=2013-10-15", - headers="{'Content-Type': 'application/json', 'Accept': 'application/xml'}", + headers=json.loads('{"Content-Type": "application/json", "Accept": "application/xml"}'), port=None, host="ec2.amazonaws.com", amzdate="20190921T022008Z", @@ -52,7 +54,7 @@ def test_task_1_create_a_canonical_request_url_encode_querystring(self): """ canonical_request, payload_hash, signed_headers = task_1_create_a_canonical_request( query="arg1=true&arg3=c,b,a&arg2=false&noEncoding=ABC-abc_1.23~tilde/slash", - headers="{'Content-Type': 'application/json', 'Accept': 'application/xml'}", + headers=json.loads('{"Content-Type": "application/json", "Accept": "application/xml"}'), port=None, host="my-gateway-id.execute-api.us-east-1.amazonaws.com", amzdate="20190921T022008Z",