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

feat(test): Add docstrings to test_redaction #295

Merged
merged 1 commit into from
Sep 27, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
111 changes: 99 additions & 12 deletions integration-tests/test_redaction.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
"""
:casecomponent: insights-client
:requirement: RHSS-291297
:subsystemteam: sst_csi_client_tools
:caseautomation: Automated
:upstream: Yes
"""

import pytest
import subprocess
import tarfile
Expand All @@ -16,17 +24,47 @@
@pytest.mark.parametrize("not_removed_command", TEST_CMD)
def test_redaction_not_on_cmd(insights_client, tmp_path, not_removed_command):
"""
Do not configure commands in /etc/insights-client/file-redaction.yaml,
so related commands should exist in collection archive.
:id: 264d1d8f-47a5-49ce-800c-d349aaacdb01
:title: Test commands are collected when redaction not configured
:description:
This test verifies that when no commands are configured for redaction in
`/etc/insights-client/file-redaction.yaml`, the outputs of the related
commands are included in the collection archive
:reference:
:tier: Tier 1
:steps:
1. Ensure no command redaction is configured
2. Run the insights client to collect data
3. Check the archive for the specified command output
:expectedresults:
1. No commands are specified for redaction in the configuration file
2. Data collection completes successfully
3. The output of the command is present in the archive
"""
assert check_archive(insights_client, tmp_path, not_removed_command)


@pytest.mark.parametrize("removed_command", TEST_CMD)
def test_redaction_on_cmd(insights_client, tmp_path, removed_command):
"""
Configure command redaction in /etc/insights-client/file-redaction.yaml,
so related commands should not exist in collection archive.
:id: a2d7b71c-205d-4545-8a6b-b0be9ff57611
:title: Test commands are redacted when configured
:description:
This test verifies that when commands are configured for redaction in
`/etc/insights-client/file-redaction.yaml`, the outputs of the related
commands are excluded from the collection archive
:reference:
:tier: Tier 1
:steps:
1. Configure command redaction for the specified command
2. Run the insights client to collect data
3. Check the archive for the specified command output
4. Clean up by removing the redaction configuration file
:expectedresults:
1. The command is added to the redaction configuration successfully
2. Data collection completes successfully
3. The output of the command is not present in the archive
4. Configuration file is removed successfully
"""
try:
configure_file_redaction("Command", removed_command)
Expand All @@ -38,17 +76,47 @@ def test_redaction_on_cmd(insights_client, tmp_path, removed_command):
@pytest.mark.parametrize("not_removed_file", TEST_FILE)
def test_redaction_not_on_file(insights_client, tmp_path, not_removed_file):
"""
Do not configure files in /etc/insights-client/file-redaction.yaml,
so related files should exist in collection archive.
:id: cb2ee8b8-fd82-48ad-bebc-3e044f277c55
:title: Test files are collected when redaction not configured
:description:
This test verifies that when no files are configured for redaction in
`/etc/insights-client/file-redaction.yaml`, the related files are
included in the collection archive
:reference:
:tier: Tier 1
:steps:
1. Ensure no file redaction is configured
2. Run the insights client to collect data
3. Check the archive for the specified file
:expectedresults:
1. No files are specified for redaction in the configuration file
2. Data collection completes successfully
3. The file is present in the archive
"""
assert check_archive(insights_client, tmp_path, not_removed_file)


@pytest.mark.parametrize("removed_file", TEST_FILE)
def test_redaction_on_file(insights_client, tmp_path, removed_file):
"""
Redact files in /etc/insights-client/file-redaction.yaml,
so related files should not exist in collection archive.
:id: 849cc4ac-d45e-44b8-b307-797935085eda
:title: Test files are redacted when configured
:description:
This test verifies that when files are configured for redaction in
`/etc/insights-client/file-redaction.yaml`, the related files are
excluded from the collection archive
:reference:
:tier: Tier 1
:steps:
1. Configure file redaction for the specified file
2. Run the insights client to collect data
3. Check the archive for the specified file
4. Clean up by removing the redaction configuration file
:expectedresults:
1. The file is added to the redaction configuration successfully
2. Data collection completes successfully
3. The file is not present in the archive
4. Configuration file is removed successfully
"""
try:
configure_file_redaction("File", removed_file)
Expand All @@ -59,11 +127,30 @@ def test_redaction_on_file(insights_client, tmp_path, removed_file):

def test_redaction_on_pattern_hostname(insights_client, tmp_path):
"""
Test if the system hostname is obfuscated
Related to https://issues.redhat.com/browse/RHEL-2471

:id: 641edf11-ace1-4a98-9fb4-198cf9e5e4d0
:title: Test hostname is redacted when pattern is configured
:description:
This test verifies that when a pattern matching the system's
hostname is configured for content redaction in
`/etc/insights-client/content-redaction.yaml`, the hostname is
obfuscated in the collected data
:reference: https://issues.redhat.com/browse/RHEL-2471
:tier: Tier 1
:steps:
1. Record the current system hostname
2. Set a new hostname for testing
3. Configure content redaction for the test hostname
4. Run the insights client and collect data
5. Check the archive to verify the hostname is redacted
6. Restore the original hostname and clean up
:expectedresults:
1. The current hostname is recorded successfully
2. The system hostname is updated to the test hostname
3. The test hostname is added to the content redaction configuration
4. Data collection completes successfully
5. The test hostname is not present in the collected data
6. Original hostname is restored, and configuration files are removed
"""

# Record the current hostname
with open("/etc/hostname", "r") as f:
previous_hostname = f.read().strip()
Expand Down
Loading