Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add tests for signature/Host header mismatch #68

Merged
merged 1 commit into from May 15, 2023

Conversation

phillipberndt
Copy link
Contributor

This adds the unit tests we discussed in #65.

Pytest output:

================================================================================================================= FAILURES =================================================================================================================
_____________________________________________________________________________ AWS4Auth_GetCanonicalHeaders_Test.test_netloc_port_is_kept_for_non_standard_port _____________________________________________________________________________

self = <requests_aws4auth.test.test_requests_aws4auth.AWS4Auth_GetCanonicalHeaders_Test testMethod=test_netloc_port_is_kept_for_non_standard_port>

    def test_netloc_port_is_kept_for_non_standard_port(self):
        """
        When urllib3 is used, the Host header is not part of the prepared request,
        but generated later, and the port is kept in the header if it is not the
        standard HTTPS port. d190dcb has a bug that also strips non-standard ports
        from the signature, causing signature and host header to mismatch. This is
        a regression test for that bug.
    
        """
        req = requests.Request('GET', 'https://amazonaws.com:8443')
        preq = req.prepare()
        self.assertNotIn('host', preq.headers)
        result = AWS4Auth.get_canonical_headers(preq, include=['host'])
        cano_hdrs, signed_hdrs = result
        expected = 'host:amazonaws.com:8443\n'
>       self.assertEqual(cano_hdrs, expected)
E       AssertionError: 'host:amazonaws.com\n' != 'host:amazonaws.com:8443\n'
E       - host:amazonaws.com
E       + host:amazonaws.com:8443
E       ?                   +++++

requests_aws4auth/test/test_requests_aws4auth.py:977: AssertionError

..which is exactly the issue others complained about in #34, I fixed in 8e1417 and that it then turned out another user relied on in #65.

See tedder#65 and tedder#34. This adds a failing test that would be fixed by 8e1417.
@tedder
Copy link
Owner

tedder commented May 15, 2023

Phillip, this is great, thanks. It fails as we expect and communicates it very well.

@tedder
Copy link
Owner

tedder commented May 15, 2023

Merging but I won't cut a release for it.

@tedder tedder merged commit 9e9e7bf into tedder:main May 15, 2023
2 of 5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants