Skip to content

Commit

Permalink
Fix bug in binding of aws_input_stream_seek() (#143)
Browse files Browse the repository at this point in the history
  • Loading branch information
graebm authored May 1, 2020
1 parent 7ed7639 commit 4fd2ce5
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 2 deletions.
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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="[email protected]",
description="A common runtime for AWS Python projects",
Expand Down
2 changes: 1 addition & 1 deletion source/io.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
37 changes: 37 additions & 0 deletions test/test_auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import awscrt.auth
import awscrt.io
import datetime
from io import BytesIO
import os
from test import NativeResourceTest, TIMEOUT

Expand Down Expand Up @@ -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())

0 comments on commit 4fd2ce5

Please sign in to comment.