From 4fd2ce57e9e9178c6ece4dadd8c156bcebcd01e1 Mon Sep 17 00:00:00 2001 From: Michael Graeb Date: Fri, 1 May 2020 16:51:02 -0700 Subject: [PATCH] Fix bug in binding of aws_input_stream_seek() (#143) --- setup.py | 2 +- source/io.c | 2 +- test/test_auth.py | 37 +++++++++++++++++++++++++++++++++++++ 3 files changed, 39 insertions(+), 2 deletions(-) diff --git a/setup.py b/setup.py index 48d97aaea..6ebcca94b 100644 --- a/setup.py +++ b/setup.py @@ -244,7 +244,7 @@ def awscrt_ext(): setuptools.setup( name="awscrt", - version="0.5.13", + version="0.5.14", author="Amazon Web Services, Inc", author_email="aws-sdk-common-runtime@amazon.com", description="A common runtime for AWS Python projects", diff --git a/source/io.c b/source/io.c index 8e3585791..0d412bb5f 100644 --- a/source/io.c +++ b/source/io.c @@ -655,7 +655,7 @@ static int s_aws_input_stream_py_seek( return AWS_OP_ERR; /* Python has shut down. Nothing matters anymore, but don't crash */ } - method_result = PyObject_CallMethod(impl->io, "seek", "(li)", &offset, &basis); + method_result = PyObject_CallMethod(impl->io, "seek", "(li)", offset, basis); if (!method_result) { aws_result = aws_py_raise_error(); goto done; diff --git a/test/test_auth.py b/test/test_auth.py index e4f09a66f..a37fb548a 100644 --- a/test/test_auth.py +++ b/test/test_auth.py @@ -15,6 +15,7 @@ import awscrt.auth import awscrt.io import datetime +from io import BytesIO import os from test import NativeResourceTest, TIMEOUT @@ -257,3 +258,39 @@ def test_signing_sigv4_headers(self): # signed headers must be present for signed_header in SIGV4TEST_SIGNED_HEADERS: self.assertIn(signed_header, http_request.headers) + + def test_signing_sigv4_body(self): + + credentials_provider = awscrt.auth.AwsCredentialsProvider.new_static( + SIGV4TEST_ACCESS_KEY_ID, SIGV4TEST_SECRET_ACCESS_KEY, SIGV4TEST_SESSION_TOKEN) + + signing_config = awscrt.auth.AwsSigningConfig( + algorithm=awscrt.auth.AwsSigningAlgorithm.SigV4Header, + credentials_provider=credentials_provider, + region=SIGV4TEST_REGION, + service=SIGV4TEST_SERVICE, + date=SIGV4TEST_DATE, + body_signing_type=awscrt.auth.AwsBodySigningConfigType.BodySigningOn) + + body_stream = BytesIO(b'hello') + + http_request = awscrt.http.HttpRequest( + method='POST', + path='/', + headers=awscrt.http.HttpHeaders([('Host', 'example.amazonaws.com'), ('Content-Length', '5')]), + body_stream=body_stream) + + signing_future = awscrt.auth.aws_sign_request(http_request, signing_config) + + signing_result = signing_future.result(TIMEOUT) + + self.assertIs(http_request, signing_result) # should be same object + + self.assertEqual('2cf24dba5fb0a30e26e83b2ac5b9e29e1b161e5c1fa7425e73043362938b9824', + signing_result.headers.get('x-amz-content-sha256')) + self.assertEqual( + 'AWS4-HMAC-SHA256 Credential=AKIDEXAMPLE/20150830/us-east-1/service/aws4_request, SignedHeaders=content-length;host;x-amz-content-sha256;x-amz-date, Signature=8e17c5b22b7bb28da47f44b08691c087a0993d0965bfab053376360790d44d6c', + signing_result.headers.get('Authorization')) + + # stream should be seeked back to initial position + self.assertEqual(0, body_stream.tell())