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

PostObject tests: fix policy form generation #46

Open
evgeniiz321 opened this issue Oct 14, 2023 · 0 comments
Open

PostObject tests: fix policy form generation #46

evgeniiz321 opened this issue Oct 14, 2023 · 0 comments
Labels
bug Something isn't working I4 No visible changes S4 Routine U3 Regular

Comments

@evgeniiz321
Copy link

evgeniiz321 commented Oct 14, 2023

Currently PostObject tests that include authentication fails due to invalid policy generation. (e.g.: test_post_object_authenticated_request).
The problem is in the malformed policy form. But it is not obvious what is exactly wrong -

<?xml version="1.0" encoding="UTF-8"?>
<Error><Code>AuthorizationQueryParametersError</Code><Message>Error parsing the X-Amz-Credential parameter; the Credential is mal-formed; expecting &#34;&lt;YOUR-AKID&gt;/YYYYMMDD/REGION/SERVICE/aws4_request&#34;.</Message><BucketName>yournamehere-ns24t1094wwfebma-1</BucketName><Resource>/yournamehere-ns24t1094wwfebma-1</Resource><RequestId>178DD0B3BB5250D0</RequestId><HostId>f25fd5b4-787e-4670-97d2-f1bed82c70ab</HostId></Error>

Adding X-Amz-Credential doesn't fix tests, so there should be more errors, need to investigate it deeply.

There is probably an error during signature generation, there should be something like:

    hmac_date = hmac.new(bytes(f"AWS4{aws_secret_access_key}", "utf-8"), bytes(current_date.strftime('%Y%m%d'), 'utf-8'), hashlib.sha256).digest()
    hmac_region = hmac.new(hmac_date, bytes(f"us-east-1", "utf-8"), hashlib.sha256).digest()
    hmac_service = hmac.new(hmac_region, bytes(f"s3", "utf-8"), hashlib.sha256).digest()
    creds = hmac.new(hmac_service, bytes(f"aws4_request", "utf-8"), hashlib.sha256).digest()

    signature = base64.b64encode(hmac.new(creds, policy, hashlib.sha256).digest())

But the above thing doesn't work as well. Maybe it is better to try to do this request via boto3 and then compare request/headers

@evgeniiz321 evgeniiz321 added the bug Something isn't working label Oct 14, 2023
@evgeniiz321 evgeniiz321 self-assigned this Oct 14, 2023
@roman-khimov roman-khimov added U3 Regular S4 Routine I4 No visible changes labels Dec 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working I4 No visible changes S4 Routine U3 Regular
Projects
None yet
Development

No branches or pull requests

2 participants