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

Check for common permissions issues with scratch area #765

Merged
merged 15 commits into from
Jan 7, 2025

Conversation

callumforrester
Copy link
Contributor

Fixes #747

Copy link

codecov bot commented Dec 19, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 93.32%. Comparing base (21a6cf5) to head (a9d6b74).
Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #765      +/-   ##
==========================================
+ Coverage   92.92%   93.32%   +0.40%     
==========================================
  Files          37       38       +1     
  Lines        2063     2083      +20     
==========================================
+ Hits         1917     1944      +27     
+ Misses        146      139       -7     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

directory_path_no_permissions: Path,
):
config = ScratchConfig(root=directory_path_no_permissions, repositories=[])
with pytest.raises(PermissionError):
Copy link
Contributor Author

Choose a reason for hiding this comment

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

TODO: Match raisesses

@callumforrester callumforrester marked this pull request as ready for review December 19, 2024 15:20
@callumforrester callumforrester changed the title Check that SGID bit is enabled for scratch area Check for common permissions issues with scratch area Dec 19, 2024
Copy link
Contributor

@tpoliaw tpoliaw left a comment

Choose a reason for hiding this comment

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

Looks good. Mainly minor bikeshedding comments

def _validate_root_directory(root_path: Path, required_gid: int | None) -> None:
_validate_directory(root_path)

if not is_sgid_enabled(root_path):
Copy link
Contributor

Choose a reason for hiding this comment

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

minor: I think it's more common/natural to talk about sgid being 'set' rather than enabled.

bool: True if the SGID bit is enabled
"""

mask = os.stat(path).st_mode
Copy link
Contributor

Choose a reason for hiding this comment

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

minor: if we're expecting a Path here we could use the stat() method directly

Suggested change
mask = os.stat(path).st_mode
mask = path.stat().st_mode

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Nice, I didn't know about that



@pytest.fixture
def directory_path() -> Generator[Path]:
def directory_path_no_permissions() -> Generator[Path]:
Copy link
Contributor

Choose a reason for hiding this comment

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

directory_path_no_sgid? The directory does have some permissions. Could also make sense to keep the directory_path fixture as it was and have a new sgid_directory_path fixture with the added permission set.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

How about directory_path_unchanged_permissions? I'm expecting that as we catch more issues over time we will need more tests that deal with a variety of different permissions setups

Copy link
Contributor

Choose a reason for hiding this comment

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

_unchanged_permissions would be better but in that case I'd err on the side of leaving directory_path as the default and adding the changed versions as directory_path_with_sgid etc.

Or keep them all explicit (if a bit verbose) with directory_path_2766, directory_path_0666 etc

(I am aware this is getting pretty picky though - definitely not something that would block the PR)

tests/unit_tests/utils/test_file_permissions.py Outdated Show resolved Hide resolved
tests/unit_tests/utils/test_file_permissions.py Outdated Show resolved Hide resolved
tests/__init__.py Outdated Show resolved Hide resolved
tests/unit_tests/utils/test_file_permissions.py Outdated Show resolved Hide resolved
src/blueapi/cli/scratch.py Outdated Show resolved Hide resolved
@@ -74,9 +76,6 @@ def scratch_install(path: Path, timeout: float = _DEFAULT_INSTALL_TIMEOUT) -> No

_validate_directory(path)

# Set umask to DLS standard
os.umask(stat.S_IWOTH)
Copy link
Contributor

Choose a reason for hiding this comment

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

Should this be removed from ensure_repo as well?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hmm, there's another test which clones to a tempdir that only passes because of this line (because the test calls ensure_repo directly rather than invoking the CLI. Maybe the test should use mocks instead, although I do worry that sticking the umask set in the CLI isn't as robust as I thought. Might be better to pepper the code with some ensure_correct_umask function in strategic places...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

...I now think we'll have to mock out all the directories in these tests anyway because of a separate issue that is breaking the CI with test_setup_scratch_succeeds_on_required_gid. I'll make an issue for that.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

tests/unit_tests/utils/test_file_permissions.py Outdated Show resolved Hide resolved
src/blueapi/cli/scratch.py Outdated Show resolved Hide resolved
src/blueapi/cli/scratch.py Outdated Show resolved Hide resolved
@callumforrester callumforrester merged commit 82b208f into main Jan 7, 2025
31 checks passed
@callumforrester callumforrester deleted the 747-file-lock branch January 7, 2025 09:31
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.

Scratch area files are locked to owner
2 participants