Skip to content

Commit

Permalink
testing aide
Browse files Browse the repository at this point in the history
  • Loading branch information
chanakyavasantha committed Dec 15, 2023
1 parent a0a4117 commit 743543d
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 38 deletions.
7 changes: 1 addition & 6 deletions .github/workflows/workflow.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,4 @@ jobs:
run: sudo apt install usbguard

- name: Run test scripts
run: |
export PYTHONPATH="${PYTHONPATH}:/home/runner/work/HardeningHub/HardeningHub"
for script in tests/*.sh; do
chmod +x "$script"
./"$script"
done
run: python3 tests/test_aide.py
42 changes: 42 additions & 0 deletions tests/test_aide.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import subprocess
from harden import config_file

def get_script(config):
file_systems_config = config["file-systems"]
# Start with an empty script and build it up
script = ""

if file_systems_config['enable_aide']:
# Each file system gets its own set of commands
script += """
apt install aide aide-common
aideinit
mv /var/lib/aide/aide.db.new /var/lib/aide/aide.db
"""
return script

def run_bash_script(script):
try:
# Run the script and capture the output
result = subprocess.run(script, shell=True, check=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True)
return result.stdout, result.stderr
except subprocess.CalledProcessError as e:
return e.stdout, e.stderr

def test_bash_script():
# Run the script and capture the output
audit = "dpkg-query -W -f='${binary:Package}\t${Status}\t${db:Status-Status}\n' aide aide-common"
result = subprocess.run(audit, shell=True, check=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True)
return result.stdout, result.stderr

if __name__ == "__main__":
config = config_file.read()
bash_script = get_script(config)
stdout, stderr = run_bash_script(bash_script)

print("STDOUT:\n", stdout)
print("STDERR:\n", stderr)

stdout, stderr = test_bash_script()
print("AUDIT:", stdout)
print("AUDITERR:", stderr)
32 changes: 0 additions & 32 deletions tests/test_aide.sh

This file was deleted.

12 changes: 12 additions & 0 deletions tests/test_cramfs_output.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,16 @@ echo "$script_output"
echo "Executing the generated Bash script..."
bash -c "$script_output"

# Execute dpkg-query command and check the output
echo "Executing dpkg-query..."
dpkg_output=$(dpkg-query -W -f='${binary:Package}\t${Status}\t${db:Status-Status}\n')

# Check if dpkg-query output contains the specific line
if echo "$dpkg_output" | grep -q ""; then
echo "pre-link is not installed."
else
echo "pre-link may be installed."
fi


echo "Script executed successfully."

0 comments on commit 743543d

Please sign in to comment.