Skip to content

tests/functional: assert R_OK/W_OK for XDG dirs #16322

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

Merged
merged 9 commits into from
Jul 22, 2024

Conversation

woodruffw
Copy link
Member

This follows #16304 -- this test passes for local and CI runs because they don't use the nobody user, which then fails at runtime (in deployment) to access these dirs.

cabotage/cabotage-app#85 fixes the above by moving the XDG dir creation to within Cabotage's wrapper; this updates the backstop test to be permission/access based, rather than existence based.

@woodruffw woodruffw requested a review from a team as a code owner July 22, 2024 15:29
Comment on lines +22 to +23
user_data = platformdirs.user_data_dir(ensure_exists=True)
user_cache = platformdirs.user_cache_dir(ensure_exists=True)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NB: With ensure_exists this is now partially a no-op test, at least in local/CI testing (since these dirs don't exist). However for Cabotage/deployment it'll end up testing something useful, per cabotage/cabotage-app#85

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just for clarity, we do not execute tests in the cabotage environment. should this be a runtime check?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, didn't realize that -- yeah, in that case it probably makes more sense as a runtime check. I'll look at putting it somewhere early in python -m warehouse's initialization 🙂

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've put this in warehouse/config.py, as part of the early initialization that happens there. But I'm not 100% sure if that's the best place 🙂

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In smoke testing this, it looks like this doesn't correctly detect that things are working.

I rolled out a new release of test.pypi.org using this wrapper and you can see results in cabotage/cabotage-app#85 (comment)

platformdirs.user_data_dir(ensure_exists=True) succeeds, but platformdirs.user_data_dir('app', ensure_exists=True) fails, indicating that this wouldn't actually ensure success for xdg/platformdirs use later on.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

appears this is due to the existing /tmp/{share, cache} files created by the Dockerfile on main :)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

validated this locally!

I still think it may be wise to change these to platformdirs.user_cache_dir(secrets.token_urlsafe(), ensure_exists=True) and similar to ensure not only that the dirs exist but that they're writable.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

appears this is due to the existing /tmp/{share, cache} files created by the Dockerfile on main :)

Whoops 🤦 -- I think merging this first should fix that then, since we won't be doing mkdir in the Dockerfile anymore.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I still think it may be wise to change these to platformdirs.user_cache_dir(secrets.token_urlsafe(), ensure_exists=True) and similar to ensure not only that the dirs exist but that they're writable.

Done!

Signed-off-by: William Woodruff <[email protected]>
@woodruffw woodruffw self-assigned this Jul 22, 2024
Signed-off-by: William Woodruff <[email protected]>
Signed-off-by: William Woodruff <[email protected]>
@ewdurbin ewdurbin merged commit 4bbdb32 into pypi:main Jul 22, 2024
17 checks passed
@ewdurbin ewdurbin deleted the ww/xdg-perms branch July 22, 2024 17:05
@ewdurbin
Copy link
Member

Note: this successfully deployed, so appears to be working end-to-end with the changes from cabotage-app.

@woodruffw
Copy link
Member Author

Note: this successfully deployed, so appears to be working end-to-end with the changes from cabotage-app.

Awesome. I'll attempt to kick the tires again 🙂

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants