-
Notifications
You must be signed in to change notification settings - Fork 32
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
Add test to check if files can be accessed while FIM has them opened #705
Conversation
Windows results
|
Linux results
|
Results above are performed in the |
8a99c14
to
f2f43f4
Compare
c22a1c6
to
09b277b
Compare
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.
GJ, but some changes are required.
@@ -0,0 +1,105 @@ | |||
# Copyright (C) 2015-2020, Wazuh Inc. |
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.
Update Copyright
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.
Done in commit d19040b
p, m = generate_params(extra_params=conf_params) | ||
|
||
configurations = load_wazuh_configurations(configurations_path, __name__, params=p, metadata=m) |
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.
p, m = generate_params(extra_params=conf_params) | |
configurations = load_wazuh_configurations(configurations_path, __name__, params=p, metadata=m) | |
parameters, metadata = generate_params(extra_params=conf_params) | |
configurations = load_wazuh_configurations(configurations_path, __name__, params=parameters, metadata=metadata) |
Variables with just a single letter are not allowed, they should have descriptive names
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.
Done in commit c678fdf
@pytest.fixture(scope='function') | ||
def create_and_restore_large_file(request): | ||
if not os.path.exists(testdir1): | ||
os.mkdir(testdir1) | ||
|
||
file_size = 1024 * 1024 * 768 # 805 MB | ||
chunksize = 1024 * 768 | ||
file_path = os.path.join(testdir1, 'large_file') | ||
changed_path = os.path.join(testdir1, 'changed_name') | ||
|
||
if os.path.exists(changed_path): | ||
os.rename(changed_path, file_path) | ||
elif not os.path.exists(file_path): | ||
with open(file_path, "a") as f: | ||
while os.stat(file_path).st_size < file_size: | ||
f.write(random.choice(string.printable) * chunksize) |
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.
This fixture should create and delete the file at the end of the test, so when we are finished, the environment is clean. This will create a new file for each test case, instead of renaming the file for the second test case. You can take a look at this example:
wazuh-qa/tests/integration/test_fim/test_files/test_report_changes/test_disk_quota_values.py
Lines 53 to 64 in fe154ff
@pytest.fixture(scope='function') | |
def create_specific_size_file(get_configuration, request): | |
"""Create a file with a specific size requested from test configuration""" | |
test_file = os.path.join(temp_dir, 'test') | |
# Translate given size from string to number in bytes | |
translated_size = translate_size(configured_size=get_configuration['metadata']['disk_quota_limit']) | |
write_file(test_file, random_string(translated_size*compression_ratio)) | |
yield | |
remove_file(test_file) |
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.
Done in commit d9cdee7
try: | ||
os.rename(file_path, changed_path) | ||
except (OSError, IOError, PermissionError): | ||
pytest.fail("Could not rename file") |
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.
pytest.fail("Could not rename file") | |
pytest.fail('Could not rename file') |
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.
Done in commit c806811
try: | ||
os.remove(file_path) | ||
except (OSError, IOError, PermissionError): | ||
pytest.fail("Could not delete file") |
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.
pytest.fail("Could not delete file") | |
pytest.fail('Could not delete file') |
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.
Done in commit c806811
Package
Testingthe test failed, I still work on this
|
09b277b
to
4573a51
Compare
After rebase the test continued with failures I working on this in a temporal branch https:/wazuh/wazuh-qa/tree/tmp_705 |
tests/integration/test_fim/test_files/test_basic_usage/test_basic_usage_access_opened_files.py
Outdated
Show resolved
Hide resolved
tests/integration/test_fim/test_files/test_basic_usage/test_basic_usage_access_opened_files.py
Outdated
Show resolved
Hide resolved
tests/integration/test_fim/test_files/test_basic_usage/test_basic_usage_access_opened_files.py
Outdated
Show resolved
Hide resolved
can modified (renamed/deleted), and that wazuh is not | ||
blocking the files. | ||
|
||
wazuh_min_version: 4.3 |
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.
Could you check if the min version that covers it is 4.3, please? I think that it also works to 4.2
tests/integration/test_fim/test_files/test_basic_usage/test_basic_usage_access_opened_files.py
Outdated
Show resolved
Hide resolved
tests/integration/test_fim/test_files/test_basic_usage/test_basic_usage_access_opened_files.py
Outdated
Show resolved
Hide resolved
tests/integration/test_fim/test_files/test_basic_usage/test_basic_usage_access_opened_files.py
Show resolved
Hide resolved
tests/integration/test_fim/test_files/test_basic_usage/test_basic_usage_access_opened_files.py
Outdated
Show resolved
Hide resolved
tests/integration/test_fim/test_files/test_basic_usage/test_basic_usage_access_opened_files.py
Outdated
Show resolved
Hide resolved
tests/integration/test_fim/test_files/test_basic_usage/test_basic_usage_access_opened_files.py
Outdated
Show resolved
Hide resolved
tests/integration/test_fim/test_files/test_basic_usage/test_basic_usage_access_opened_files.py
Outdated
Show resolved
Hide resolved
tests/integration/test_fim/test_files/test_basic_usage/test_basic_usage_access_opened_files.py
Outdated
Show resolved
Hide resolved
tests/integration/test_fim/test_files/test_basic_usage/test_basic_usage_access_opened_files.py
Show resolved
Hide resolved
tests/integration/test_fim/test_files/test_basic_usage/test_basic_usage_access_opened_files.py
Outdated
Show resolved
Hide resolved
tests/integration/test_fim/test_files/test_basic_usage/test_basic_usage_access_opened_files.py
Outdated
Show resolved
Hide resolved
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.
GJ, but some changes are required
tests/integration/test_fim/test_files/test_basic_usage/test_basic_usage_access_opened_files.py
Outdated
Show resolved
Hide resolved
tests/integration/test_fim/test_files/test_basic_usage/test_basic_usage_access_opened_files.py
Outdated
Show resolved
Hide resolved
tests/integration/test_fim/test_files/test_basic_usage/test_basic_usage_access_opened_files.py
Outdated
Show resolved
Hide resolved
tests/integration/test_fim/test_files/test_basic_usage/test_basic_usage_access_opened_files.py
Show resolved
Hide resolved
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.
Test Results
Test Path | OS | Version | Date | Status |
---|---|---|---|---|
test_fim/test_files/test_basic_usage/test_basic_usage_access_while_open.py | Windows - Agent | 4.3.0 | 2021/12/06 | 🟢 |
test_fim/test_files/test_basic_usage/test_basic_usage_access_while_open.py | Windows - Agent | 4.3.0 | 2021/12/06 | 🟢 |
test_fim/test_files/test_basic_usage/test_basic_usage_access_while_open.py | Windows - Agent | 4.3.0 | 2021/12/06 | 🟢 |
test_fim/ | Windows - Agent | 4.3.0 | 2021/12/06 | 🟢 |
test_fim/ | Windows - Agent | 4.3.0 | 2021/12/06 | 🟢 |
test_fim/ | Windows - Agent | 4.3.0 | 2021/12/06 | 🟢 |
test_fim/ | Linux - Agent | 4.3.0 | 2021/12/06 | 🟢 |
test_fim/ | Macos- Agent | 4.3.0 | 2021/12/06 | 🟢 |
test_fim/ | Solaris - Agent | 4.3.0 | 2021/12/06 | 🟢 |
test_fim/ | Linux - Manager | 4.3.0 | 2021/12/06 | 🟢 |
Description
This pull request adds a test that checks if a file can be accessed while FIM has it opened. This test creates a big file (~960MB), waits for the initial scan to start, and modifies or deletes the file. If Wazuh doesn't allow for it to be opened by any other process, a
PermissionError
exception is raised and the test fails. To pass, the test does the following assertions:Note:
The test only works forscheduled
scans, since there is no current way of knowing when a scan will start for a file monitored withrealtime
orwhodata
modes.This pull request closes #697.
Packages
Testing
test_basic_usage_access_opened_files.py
Update 2021/12/03