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

Fix tests and make path handling more robust #23

Merged
merged 4 commits into from
Dec 23, 2020

Conversation

sysvinit
Copy link
Contributor

These commits make the tests work again, and use the path and path/filepath libraries for path manipulation. This means the file data path doesn't need to have a trailing slash in order to work correctly, and that the upload sub directory can be given as an absolute path with a leading slash. Further details are in the commit messages.

The tests did not have a correct HMAC for the example file, which causes them
to fail to verify the token correctly.

The new HMAC was generated with the following Python REPL session:

    >>> import hmac
    >>> h = hmac.new(b'mysecret', digestmod='sha256')
    >>> h.update(b'thomas/abc/catmetal.jpg 23026')
    >>> h.hexdigest()
    '7b8879e2d1c733b423a70cde30cecc3a3c64a03f790d1b5bcbb2a6aca52b477e'

In addition, the filer returns 201 Created when a file is
created, not 200 Okay, which is consistent with the behaviour of
https://github.com/horazont/xmpp-http-upload
Previous versions of this code relied on the upload subdir configuration
parameter being set to a relative pathname, and then prepending a leading slash
to make it absolute. This is a little fragile, especially where the config
parameter is specified with a leading slash, so replace this with path.Join to
get consistent behaviour in both of these cases.

The store directory's pathname is also assumed to be given with a trailing
slash, with the request filename being simply appended to this; use
filepath.Join to get consistent behaviour here too, in case the trailing slash
is not provided.

Note that http.Server performs path canonicalisation and sanitisation on the
request URL path internally before invoking the specified handler function, so
this doesn't need to be done manually.
This fixes a regression introduced in the path handling safety cleanup
commit. http.ServeMux needs a trailing slash to detect rooted subtrees instead
of individual file paths.
@ThomasLeister
Copy link
Owner

ThomasLeister commented Dec 22, 2020

Thanks for your contribution to code quality, @sysvinit ! I'll check it out in the next few days and merge it into develop :-)

@ThomasLeister ThomasLeister self-assigned this Dec 22, 2020
@ThomasLeister ThomasLeister added the enhancement New feature or request label Dec 22, 2020
@ThomasLeister ThomasLeister merged commit 13f5ac9 into ThomasLeister:develop Dec 23, 2020
@sysvinit
Copy link
Contributor Author

Thanks for merging! I've got a couple of other changes and fixes which I'll clean up and then open separate PRs for.

@sysvinit sysvinit deleted the path-handling branch December 23, 2020 22:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants