-
Notifications
You must be signed in to change notification settings - Fork 136
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
Make xattr dependency conditional, add stub xattr library #228
Merged
rbs-jacob
merged 9 commits into
redballoonsecurity:master
from
marczalik:feature/removexattrs
Feb 21, 2023
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
40a6dbf
Remove xattr references
marczalik 3d85b87
Update calls to add_file/add_folder
marczalik eff7894
Revert "Update calls to add_file/add_folder"
marczalik b73964e
Revert "Remove xattr references"
marczalik 4207d29
Conditionally require xattr based on platform, add stub library to wa…
marczalik 5cf6b88
Ignore redefinitions of module imports
marczalik 9f3f972
Add tests and proper return types to shadow xattr library functions
marczalik b4fa2d4
Add stub return type testing, test filesystem with and without xattr …
marczalik 72b63b6
Run subprocess calls inside of test function
marczalik File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,151 @@ | ||
import inspect | ||
import logging | ||
|
||
|
||
LOGGER = logging.getLogger(__name__) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this LOGGER ever used? |
||
|
||
|
||
class xattr: | ||
""" | ||
Stub library to support OFRAK on Windows and other platforms where xattr is not available. | ||
""" | ||
|
||
def __init__(self, obj, options=0): | ||
frame = inspect.currentframe() | ||
_warn_user_no_xattr(inspect.getframeinfo(frame).function) | ||
|
||
def __repr__(self): | ||
frame = inspect.currentframe() | ||
_warn_user_no_xattr(inspect.getframeinfo(frame).function) | ||
return "" | ||
|
||
def _call(self, name_func, fd_func, *args): | ||
frame = inspect.currentframe() | ||
_warn_user_no_xattr(inspect.getframeinfo(frame).function) | ||
|
||
def get(self, name, options=0): | ||
frame = inspect.currentframe() | ||
_warn_user_no_xattr(inspect.getframeinfo(frame).function) | ||
return b"" | ||
|
||
def set(self, name, value, options=0): | ||
frame = inspect.currentframe() | ||
_warn_user_no_xattr(inspect.getframeinfo(frame).function) | ||
return None | ||
|
||
def remove(self, name, options=0): | ||
frame = inspect.currentframe() | ||
_warn_user_no_xattr(inspect.getframeinfo(frame).function) | ||
return None | ||
|
||
def list(self, options=0): | ||
frame = inspect.currentframe() | ||
_warn_user_no_xattr(inspect.getframeinfo(frame).function) | ||
return [] | ||
|
||
def __len__(self): | ||
frame = inspect.currentframe() | ||
_warn_user_no_xattr(inspect.getframeinfo(frame).function) | ||
return 0 | ||
|
||
def __delitem__(self, item): | ||
frame = inspect.currentframe() | ||
_warn_user_no_xattr(inspect.getframeinfo(frame).function) | ||
return None | ||
|
||
def __setitem__(self, item, value): | ||
frame = inspect.currentframe() | ||
_warn_user_no_xattr(inspect.getframeinfo(frame).function) | ||
return None | ||
|
||
def __getitem__(self, item): | ||
frame = inspect.currentframe() | ||
_warn_user_no_xattr(inspect.getframeinfo(frame).function) | ||
return b"" | ||
|
||
def iterkeys(self): | ||
frame = inspect.currentframe() | ||
_warn_user_no_xattr(inspect.getframeinfo(frame).function) | ||
return iter(list()) | ||
|
||
def has_key(self, item): | ||
frame = inspect.currentframe() | ||
_warn_user_no_xattr(inspect.getframeinfo(frame).function) | ||
return False | ||
|
||
def clear(self): | ||
frame = inspect.currentframe() | ||
_warn_user_no_xattr(inspect.getframeinfo(frame).function) | ||
return None | ||
|
||
def update(self, seq): | ||
frame = inspect.currentframe() | ||
_warn_user_no_xattr(inspect.getframeinfo(frame).function) | ||
return None | ||
|
||
def copy(self): | ||
frame = inspect.currentframe() | ||
_warn_user_no_xattr(inspect.getframeinfo(frame).function) | ||
return dict() | ||
|
||
def setdefault(self, k, d=""): | ||
frame = inspect.currentframe() | ||
_warn_user_no_xattr(inspect.getframeinfo(frame).function) | ||
return b"" | ||
|
||
def keys(self): | ||
frame = inspect.currentframe() | ||
_warn_user_no_xattr(inspect.getframeinfo(frame).function) | ||
return [] | ||
|
||
def itervalues(self): | ||
frame = inspect.currentframe() | ||
_warn_user_no_xattr(inspect.getframeinfo(frame).function) | ||
yield b"" | ||
|
||
def values(self): | ||
frame = inspect.currentframe() | ||
_warn_user_no_xattr(inspect.getframeinfo(frame).function) | ||
return [] | ||
|
||
def iteritems(self): | ||
frame = inspect.currentframe() | ||
_warn_user_no_xattr(inspect.getframeinfo(frame).function) | ||
yield tuple() | ||
|
||
def items(self): | ||
frame = inspect.currentframe() | ||
_warn_user_no_xattr(inspect.getframeinfo(frame).function) | ||
return [] | ||
|
||
|
||
def listxattr(f, symlink=False): | ||
frame = inspect.currentframe() | ||
_warn_user_no_xattr(inspect.getframeinfo(frame).function) | ||
return tuple() | ||
|
||
|
||
def getxattr(f, attr, symlink=False): | ||
frame = inspect.currentframe() | ||
_warn_user_no_xattr(inspect.getframeinfo(frame).function) | ||
return b"" | ||
|
||
|
||
def setxattr(f, attr, value, options=0, symlink=False): | ||
frame = inspect.currentframe() | ||
_warn_user_no_xattr(inspect.getframeinfo(frame).function) | ||
return None | ||
|
||
|
||
def removexattr(f, attr, symlink=False): | ||
frame = inspect.currentframe() | ||
_warn_user_no_xattr(inspect.getframeinfo(frame).function) | ||
return None | ||
|
||
|
||
def _warn_user_no_xattr(function_name: str) -> None: | ||
logging.warning( | ||
f"Function {function_name} not found. Library xattr is not available on Windows platforms. \ | ||
Extended attributes will not be properly handled while using OFRAK on this platform. \ | ||
If you require extended attributes, please use a platform that supports xattr." | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,4 @@ | ||
[pytest] | ||
asyncio_mode = auto | ||
markers = | ||
serial: force tests to run in serial |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
ofrak_core/test_ofrak/components/test_filesystem_without_xattr.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import os | ||
import subprocess | ||
|
||
|
||
import pytest | ||
|
||
|
||
@pytest.mark.serial | ||
async def test_filesystem_without_xattr(): | ||
subprocess.run(["pip", "uninstall", "xattr", "-y"]) | ||
cwd = os.getcwd() | ||
os.chdir(os.path.dirname(__file__)) | ||
result = subprocess.run(["pytest", "./test_filesystem_component.py"]) | ||
assert result.returncode == 0 | ||
os.chdir(cwd) | ||
subprocess.run(["pip", "install", "xattr"]) | ||
Comment on lines
+10
to
+16
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Am I understanding correctly that the "serial" tests need to be run in a specified order?
If so, this is not ideal -- each "test" should be standalone, and any setup or teardown for it should be handled by a fixture (and not be a side-effect of a previously run test).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The order of the serial tests does not matter. What matters is that the two tests are not run in parallel, since one test requires the real
xattr
library be installed, while the other requires it be uninstalled. So to guarantee that they are not run in parallel I have set them to run in serial.