Skip to content

Commit

Permalink
chore: testing using bats
Browse files Browse the repository at this point in the history
  • Loading branch information
stephane-segning committed Aug 16, 2024
1 parent 5b41527 commit e9a4d85
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 58 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test-script.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name: Test Script
on: [ push, pull_request ]

jobs:
test_yara:
test_script:
runs-on: ubuntu-latest
strategy:
matrix:
Expand Down
Empty file modified scripts/install.sh
100644 → 100755
Empty file.
18 changes: 0 additions & 18 deletions scripts/tests/alpine/Dockerfile

This file was deleted.

19 changes: 0 additions & 19 deletions scripts/tests/debian/Dockerfile

This file was deleted.

64 changes: 64 additions & 0 deletions scripts/tests/test-script.bats
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
#!/usr/bin/env bats

WAZUH_MANAGER="10.0.0.2"

if [ "$(uname -o)" = "GNU/Linux" ] && command -v groupadd >/dev/null 2>&1; then
apt-get update && apt-get install -y curl gnupg2
(curl -s https://packages.wazuh.com/key/GPG-KEY-WAZUH | gpg --no-default-keyring --keyring gnupg-ring:/usr/share/keyrings/wazuh.gpg --import)
chmod 644 /usr/share/keyrings/wazuh.gpg
echo "deb [signed-by=/usr/share/keyrings/wazuh.gpg] https://packages.wazuh.com/4.x/apt/ stable main" | tee -a /etc/apt/sources.list.d/wazuh.list
apt-get update
apt-get install wazuh-agent -y
sed -i "s|MANAGER_IP|$WAZUH_MANAGER|g" /var/ossec/etc/ossec.conf
elif [ "$(which apk)" = "/sbin/apk" ]; then
wget -O /etc/apk/keys/[email protected] https://packages.wazuh.com/key/alpine-devel%40wazuh.com-633d7457.rsa.pub
echo "https://packages.wazuh.com/4.x/alpine/v3.12/main" >> /etc/apk/repositories
apk update
apk add wazuh-agent
sed -i "s|MANAGER_IP|$WAZUH_MANAGER|g" /var/ossec/etc/ossec.conf
/var/ossec/bin/wazuh-control start
else
log ERROR "Unsupported OS for creating user."
exit 1
fi

chmod +x /app/scripts/install.sh

# Test if the script runs without errors
@test "script runs without errors" {
run /usr/local/bin/test-script.sh
[ "$status" -eq 0 ]
}

# Test if Snort is installed
@test "Snort is installed" {
run dpkg -l | grep -q snort
[ "$status" -eq 0 ]
}

# Test if Snort directories were created
@test "Snort directories were created" {
/usr/local/bin/test-script.sh
[ -d "/var/log/snort" ]
[ -d "/etc/snort/rules" ]
}

# Test if Snort local rules file was created
@test "Snort local rules file created" {
/usr/local/bin/test-script.sh
[ -f "/etc/snort/rules/local.rules" ]
}

# Test if ossec.conf was updated
@test "ossec.conf updated" {
/usr/local/bin/test-script.sh
grep -q '<log_format>snort-full<\/log_format>' "$OSSEC_CONF_PATH"
grep -q '<location>\/var\/log\/snort\/snort.alert.fast<\/location>' "$OSSEC_CONF_PATH"
}

# Test if Snort was started
@test "Snort started" {
/usr/local/bin/test-script.sh
run systemctl status snort
[ "$status" -eq 0 ]
}
20 changes: 0 additions & 20 deletions scripts/tests/ubuntu/Dockerfile

This file was deleted.

0 comments on commit e9a4d85

Please sign in to comment.