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 unit test banned path check to allow access to project folder #749

Merged
merged 3 commits into from
Jan 29, 2025

Conversation

rtuck99
Copy link
Contributor

@rtuck99 rtuck99 commented Jan 15, 2025

Fixes

This change adjusts the check for unit tests trying to open files so that files in the project folder are allowed

Copy link

codecov bot commented Jan 15, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 87.01%. Comparing base (7bf9b6f) to head (2f5b629).
Report is 1 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #749   +/-   ##
=======================================
  Coverage   87.01%   87.01%           
=======================================
  Files         101      101           
  Lines        6968     6968           
=======================================
  Hits         6063     6063           
  Misses        905      905           
Components Coverage Δ
i24 SSX 72.84% <ø> (ø)
hyperion 96.55% <ø> (ø)
other 96.58% <ø> (ø)

Copy link
Contributor

@DominicOram DominicOram 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 but as a suggestion how about we make it a whitelist instead? It looks like the only places the tests are writing to are:

  • The package folder (which we're now checking)
  • /tmp

So we could just check for one of those rather than check against the banned?

@rtuck99
Copy link
Contributor Author

rtuck99 commented Jan 28, 2025

Looks good but as a suggestion how about we make it a whitelist instead? It looks like the only places the tests are writing to are:

* The package folder (which we're now checking)

* `/tmp`

So we could just check for one of those rather than check against the banned?

I tried this, however it seems to run into problems, somehow running the test some packages using importlib.resources.files seem to resolve files from the workspace, others resolve to site-packages. I can't reproduce this on my local system.

However I think in any case to handle this properly we ought to whitelist files from every conceivable folder that python might resolve packages from, esp if 3rd party code ever loads any resources. Unfortunately this might be difficult to cover not only CI but also dev machines what with system packages, virtual environments etc.

@DominicOram
Copy link
Contributor

Looks good but as a suggestion how about we make it a whitelist instead? It looks like the only places the tests are writing to are:

* The package folder (which we're now checking)

* `/tmp`

So we could just check for one of those rather than check against the banned?

I tried this, however it seems to run into problems, somehow running the test some packages using importlib.resources.files seem to resolve files from the workspace, others resolve to site-packages. I can't reproduce this on my local system.

However I think in any case to handle this properly we ought to whitelist files from every conceivable folder that python might resolve packages from, esp if 3rd party code ever loads any resources. Unfortunately this might be difficult to cover not only CI but also dev machines what with system packages, virtual environments etc.

Sure, happy to keep as is

@rtuck99 rtuck99 force-pushed the 533_fix_unit_test_banned_paths branch from f349d53 to 2f5b629 Compare January 29, 2025 10:48
@rtuck99 rtuck99 merged commit 00f759a into main Jan 29, 2025
22 checks passed
@rtuck99 rtuck99 deleted the 533_fix_unit_test_banned_paths branch January 29, 2025 10:53
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.

None yet

2 participants