-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
64 additions
and
114 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import pytest | ||
import testinfra | ||
|
||
|
||
|
||
@pytest.fixture(scope="module") | ||
def install_dependencies(host): | ||
"""Install dependencies and run the install script.""" | ||
os = host.system_info.distribution | ||
|
||
if os in ["ubuntu", "debian"]: | ||
host.run("apt-get update") | ||
host.run("apt-get install -y curl gnupg2 iproute2") | ||
|
||
elif os == "alpine": | ||
host.run("apk update") | ||
host.run("apk add curl gnupg2 iproute2") | ||
|
||
else: | ||
pytest.fail("Unsupported OS for dependency installation") | ||
|
||
|
||
@pytest.mark.usefixtures("install_dependencies") | ||
def test_snort_is_installed(host): | ||
"""Test if Snort is installed.""" | ||
snort = host.package("snort") | ||
assert snort.is_installed, "Snort should be installed" | ||
|
||
|
||
def test_snort_conf_file_exists(host): | ||
"""Test if snort.conf file exists.""" | ||
snort_conf = host.file("/etc/snort/snort.conf") | ||
assert snort_conf.exists, "snort.conf file should exist" | ||
|
||
|
||
def test_snort_interface_configuration(host): | ||
# Retrieve the default network interface | ||
interface = host.run("ip route | grep default | awk '{print $5}'").stdout.strip() | ||
|
||
# Check if the interface is present in the snort.debian.conf file | ||
snort_conf = host.file("/etc/snort/snort.debian.conf") | ||
assert interface in snort_conf.content_string, "Interface should be present in snort.debian.conf" | ||
|
||
|
||
|
||
def test_update_ossec_conf_linux(host): | ||
"""Test if ossec.conf is updated on Linux.""" | ||
ossec_conf_path = "/var/ossec/etc/ossec.conf" | ||
expected_content = """ | ||
<!-- snort --> | ||
<localfile> | ||
<log_format>snort-full</log_format> | ||
<location>/var/log/snort/snort.alert.fast</location> | ||
""" | ||
|
||
ossec_conf = host.file(ossec_conf_path) | ||
assert ( | ||
expected_content.strip() in ossec_conf.content_string.strip() | ||
), "ossec.conf should be updated on Linux" | ||
|
||
|
||
|
||
|
||
|
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.