Repository navigation
Fix upload to a public share path - #22
allexzander wants to merge 7 commits into
Conversation
…ncoded urlencode() encodes the exclamation mark of a public share token as %21. The server expects it unencoded, as the web UI sends it. The fix-up in upload() never applied because it searched for "%%2FSHARED%2F%21" with a doubled percent sign, so uploads to a public upload-only share failed. Its guard was also always true since str.find() returns -1 when nothing matches. Replace "%2FSHARED%2F%21" with "%2FSHARED%2F!" in both the empty file and the chunked branch, and add unit tests for both branches plus a path outside /SHARED/ that keeps its encoded !. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
krzysztofFC
left a comment
There was a problem hiding this comment.
Reviewed and verified locally on a clean clone (Python 3.11 venv).
filecloudapi/tests: 5 passed. black, isort and mypy are clean.- The two new public share tests fail when run against the
fcserver.pyofmain(the empty file branch and the chunked branch), so they catch the bug. - The query this builds matches the workaround in the FCD integration tests (
test/util/fcserver_testcompat.py,upload_str_to_public_share), which uploads to a public upload-only share on a real server. After this is merged and 0.5.4 is on PyPI, a follow-up PR in the FCD repo can bumptest/requirements.txtto 0.5.4 and replace that workaround with a plainupload_strcall (one caller,test_shares.pytest_public_share_upload_only).
Not verified end to end against a server with this branch.
| "%%2FSHARED%2F%21", "%2FSHARED%2F!" | ||
| ) # WEBUI DOES NOT ENCODE THE ! | ||
| # WEBUI DOES NOT ENCODE THE ! of a public share path (/SHARED/!<token>/...) | ||
| params_str = params_str.replace("%2FSHARED%2F%21", "%2FSHARED%2F!") |
There was a problem hiding this comment.
Nit, optional: the same two lines are also in the empty file branch above. A small helper (for example _upload_query(params)) would keep the two from drifting apart again. Fine as is.
There was a problem hiding this comment.
Thanks, all addressed in the last 3 commits:
_upload_query helper for both upload branches (5f182c0)
PolicyList and ServerSettings keep their entries per instance. ServerSettings had the same class level dict (0bed0f0)
admin_createnewgroup returns the group id, deleteshare takes adminproxyuserid, new wrappers for updateshare, deleteuserfromshare, getsystemstatus, admin_deletememberfromgroup, admin_addusertoexternal, admin_deleteuserfromexternal, admin_deleteexternal, and FileListEntry gets createdepochutc and systemcreatedepochutc (139c1b9)
Response shapes are taken from the server source. Unit tests cover the request of each wrapper and the failure path. 21 passed, black, isort and mypy clean. Still 0.5.4, so one release lets the FCD tests drop all of these workarounds.
There was a problem hiding this comment.
Thanks for the server run. All addressed in f26d3fd:
deleteuserfromshare: the docstring says userid is the email (kept the name to match the server parameter and the other wrappers)
createdepochutc: comment reworded as you suggested
admin_deletegroup returns True on result 1
admin_addnewuser sends authtype without the trailing space. /admin/adduser requires it as an integer (AdminUserRouter.php)
Unit tests added for both bugs, they fail on the old code. 24 passed, black, isort and mypy clean. On HTTPError vs ServerError: agreed, a 400 raises from raise_for_status in _api_call before the command result is read, the fake 200 with result 0 covers the other path.
|
The FCD integration tests still work around more of filecloudapi in Bugs:
Missing parameter:
Missing endpoints:
Missing field:
Once these are released, the FCD tests can drop the workarounds and move to the new version. |
…anches cannot drift apart Review comment on codelathe#22. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
entries was a class attribute (a list in PolicyList, a dict in ServerSettings), so every instance in the process appended to the same object. A filtered get_all_policies returned the policies of all earlier listings and admin_get_config_settings returned the settings of earlier calls. Set entries in __init__ instead. Review comment on codelathe#22. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- admin_createnewgroup returns the group id the server answers with - deleteshare takes adminproxyuserid, so a share owned by another user (for example a team folder share) can be deleted through the admin proxy - New wrappers: updateshare, deleteuserfromshare, getsystemstatus (appversion and uploadchunksize as SystemStatus), admin_deletememberfromgroup, admin_addusertoexternal, admin_deleteuserfromexternal, admin_deleteexternal - FileListEntry carries createdepochutc (getfilelist and fileinfo, servers 23.253 and later) and systemcreatedepochutc (fileinfo, when the server stores the OS creation date). Both default to "" so code that builds a FileListEntry positionally keeps working. updateshare answers with the share on success and with a meta error or a command result on failure, both raise ServerError. The others answer with a command result. Unit tests check the request each wrapper sends and that a failed command raises. Review comment on codelathe#22. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Checked against the server: ShareController::updateShare fills defaults for missing parameters. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
krzysztofFC
left a comment
There was a problem hiding this comment.
Re-checked 02bff8a. 21 unit tests pass, isort and mypy are clean. I also ran every new wrapper against a local 23.263.3 server with throwaway users, a group, an external and a share, all removed afterwards.
- Works:
getsystemstatus,PolicyListper instance (two listings return the same count),admin_createnewgroupreturns the id,admin_deletememberfromgroup,admin_addusertoexternal,admin_deleteuserfromexternal,admin_deleteexternal,updateshare(new name and public flag visible afterwards, a deleted share raisesServerError),deleteuserfromshare,deletesharewithadminproxyuserid,createdepochutcfromgetfilelistand fromfileinfoof a file. - A bad id on
admin_deletememberfromgroup,admin_deleteexternalanddeleteuserfromshareis answered with HTTP 400, so these raiseHTTPErrorfrom_api_call, notServerError. Still a failure, just not the command result 0 shape the unit tests fake.
Two small things inline.
Two older bugs I hit on the way, both outside this PR (the first one is mine):
admin_deletegroupreturns True only whencommand/resultis 0, so it returns False when the group was deleted. From PR 13.admin_addnewusersends the key"authtype "with a trailing space, so the server never getsauthtypeand answers 422 on 23.263.3.
Fine to fix them here while 0.5.4 is unreleased, or I can do it in a follow-up.
| ) | ||
| self._raise_exception_from_server_message(message) | ||
|
|
||
| def deleteuserfromshare(self, share: FCShare, userid: str) -> None: |
There was a problem hiding this comment.
userid has to be the user's email. The server validates it as one (ShareRouter.php, addRequiredParam('userid', Valid::VALID_EMAIL, Filter::LOWER_CASE)) and answers 422 for a user name. Worth naming it email or saying so in the docstring.
| isdatasyncable: bool | ||
| etag: ETag | ||
| # Empty when the server does not report them: createdepochutc (getfilelist | ||
| # and fileinfo, 23.253 and later), systemcreatedepochutc (fileinfo, only when |
There was a problem hiding this comment.
On 23.263.3 fileinfo reports createdepochutc only for a file. For a folder it is empty, while getfilelist has it. Maybe "(getfilelist, and fileinfo of a file, 23.253 and later)".
…omshare and createdepochutc limits - admin_deletegroup returned True only when command/result was 0, so it reported a deleted group as not deleted. It now returns True on result 1. - admin_addnewuser sent the key "authtype " with a trailing space, so the server never got authtype, which /admin/adduser requires as an integer (HTTP 422 on 23.263.3). - deleteuserfromshare: the server validates userid as an email. - FileListEntry.createdepochutc: fileinfo reports it only for a file, getfilelist also for a folder. Review comments on codelathe#22. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
krzysztofFC
left a comment
There was a problem hiding this comment.
Approved on f26d3fd: 24 unit tests, black, isort and mypy pass locally, and the new and fixed wrappers work against a 23.263.3 server.
urlencode() encodes the ! of
/SHARED/!<token>as%21. The fix-up inupload()never ran because it searched for"%%2FSHARED%2F%21"(doubled percent sign), so uploads to a public upload-only share failed. Fixed in both the empty file and the chunked branch, and removed theif find()guard, which was always true.Verified with new unit tests for both branches and for a path outside
/SHARED/. They fail on the old code and pass with the fix. isort, black and mypy are clean. Version bumped to 0.5.4.Please merge and publish a 0.5.4 GitHub release so the release workflow pushes it to PyPI.