-
Notifications
You must be signed in to change notification settings - Fork 58
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
Ensure temp_url_key setting is the correct type for use as HMAC key #72
Conversation
@pomegranited, just saw this cross my inbox and wanted to double-check: does this work in Python3? If this needs a bytes-like object, you'd want to do |
@haikuginger @pomegranited Write a quick test in The temp-url feature is one of the very few things that are not in existing tests, but coverage is at least 90%+. I can help with that if needed. Just poke me. |
544b6cf
to
0e7b782
Compare
Thanks for the pointer, @haikuginger ! |
@pomegranited Tests looks fine at first glance. TBH just having someone caring to write tests is a miracle on its own 👏 For the last test: You could compare the input value type with EDIT: You could also just specify The reason why the test do not fail in py3 is that |
try: | ||
backend.temp_url_key = backend.temp_url_key.encode('latin-1') | ||
backend.temp_url_key = backend.temp_url_key.encode() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
encode('ascii')
so python 3 don't use utf-8. This will of course assume that we always configure the key as a string. I think that's acceptable.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@einarf Thank you for your help, and for building a great django-storage package! Let me know if you're happy with this PR, and I'll squash my commits. |
@pomegranited Blame @Blacktorn for this package, not me. He will probable stop by and merge this very soon. He normally use the auto-squash feature here in github so you don't have to think about that. This looks ready for merge as far as I can see. 👍 |
...so it can be used as the HMAC key. Also adds tests for temp URLs.
d2a1405
to
09bcd69
Compare
Thanks for the changes and also for writing the temp url tests @pomegranited ! |
I've also pushed the v1.2.15 release to PyPI |
Thank you, @Blacktorn and @einarf ! |
This change assists with the generation of temporary URLs for private SWIFT content, by ensuring that the
SWIFT_TEMP_URL_KEY
is converted to a (non-unicode) string.If
SWIFT_TEMP_URL_KEY
is a unicode string, which happens if django app settings are parsed from JSON, then an error like this one is thrown during temporary URL creation:HMAC TypeError: character mapping must return integer, None or unicode
Manual Testing instructions:
Setup:
Create a file called 'env.json', which contains your SWIFT credentials and container name, e.g.,
In the same location as
env.json
, create thisweb.py
script to run a minimal Django app:To verify the error:
pip install django django-storage-swift
python web.py runserver
TypeError: character mapping must return integer, None or unicode
To verify this change:
python setup.py sdist && pip install dist/dist/django-storage-swift-1.2.15.tar.gz
python web.py runserver