Skip to content

Commit

Permalink
Update test to pass headers as dict
Browse files Browse the repository at this point in the history
  • Loading branch information
okigan committed Aug 20, 2024
1 parent 7ed3762 commit 74f8ff4
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
4 changes: 3 additions & 1 deletion awscurl/awscurl.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import sys
import re

from typing import Dict
import urllib
from urllib.parse import quote

Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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:
Expand Down
6 changes: 4 additions & 2 deletions tests/stages_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
Test cases for seprate header calculation stages.
"""

import json

from unittest import TestCase

from awscurl.awscurl import (
Expand All @@ -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",
Expand All @@ -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",
Expand Down

0 comments on commit 74f8ff4

Please # to comment.