diff --git a/.github/actions/generate-artifacts/action.yml b/.github/actions/generate-artifacts/action.yml deleted file mode 100644 index 2ee85a4a5b..0000000000 --- a/.github/actions/generate-artifacts/action.yml +++ /dev/null @@ -1,14 +0,0 @@ -name: 'Generate artifacts' -description: 'Generating artifacts according changes' -inputs: - artifact: - required: true -runs: - using: "composite" - steps: - - name: Generate artifacts - shell: bash - run: | - if [ "${{ inputs.artifact }}" != "builder.sh" ]; then - bash unattended_installer/builder.sh --${{ inputs.artifact }} - fi \ No newline at end of file diff --git a/.github/actions/get-tools/action.yml b/.github/actions/get-tools/action.yml deleted file mode 100644 index 5fea62bb07..0000000000 --- a/.github/actions/get-tools/action.yml +++ /dev/null @@ -1,58 +0,0 @@ -name: 'Get Tools' -description: 'Getting tools to generate .sh' -inputs: - tool: - required: true -runs: - using: "composite" - steps: - - name: Set cert_tool - shell: bash - if: contains(inputs.tool, 'cert_tool') - run: | - if [ -z "${{ env.VAR }}" ]; then - echo 'VAR={\"key\":\"cert-tool\",\"path\":\"unattended_installer/cert_tool\"}' >> $GITHUB_ENV - else - echo 'VAR=${{ env.VAR }},{\"key\":\"cert-tool\",\"path\":\"unattended_installer/cert_tool\"}' >> $GITHUB_ENV - fi - - name: Set passwords_tool - shell: bash - if: contains(inputs.tool, 'passwords_tool') - run: | - if [ -z "${{ env.VAR }}" ]; then - echo 'VAR={\"key\":\"password-tool\",\"path\":\"unattended_installer/passwords_tool\"}' >> $GITHUB_ENV - else - echo 'VAR=${{ env.VAR }},{\"key\":\"password-tool\",\"path\":\"unattended_installer/passwords_tool\"}' >> $GITHUB_ENV - fi - - name: Set installer - shell: bash - if: contains(inputs.tool, 'install_functions') - run: | - if [ -z "${{ env.VAR }}" ]; then - echo 'VAR={\"key\":\"installer\",\"path\":\"unattended_installer/install_functions\"}' >> $GITHUB_ENV - else - echo 'VAR=${{ env.VAR }},{\"key\":\"installer\",\"path\":\"unattended_installer/install_functions\"}' >> $GITHUB_ENV - fi - - name: Set downloader - shell: bash - if: contains(inputs.tool, 'downloader') - run: | - if [ -z "${{ env.VAR }}" ]; then - echo 'VAR={\"key\":\"installer\",\"path\":\"unattended_installer/downloader\"}' >> $GITHUB_ENV - else - echo 'VAR=${{ env.VAR }},{\"key\":\"installer\",\"path\":\"unattended_installer/downloader\"}' >> $GITHUB_ENV - fi - - name: Set all - shell: bash - if: contains(inputs.tool, 'common_functions') - run: | - echo 'VAR={\"key\":\"cert-tool\",\"path\":\"unattended_installer/cert_tool\"},{\"key\":\"password-tool\",\"path\":\"unattended_installer/passwords_tool\"},{\"key\":\"installer\",\"path\":\"unattended_installer/install_functions\"},{\"key\":\"installer\",\"path\":\"unattended_installer/downloader\"}' >> $GITHUB_ENV - - name: Set builder.sh - shell: bash - if: contains(inputs.tool, 'builder.sh') - run: | - if [ -z "${{ env.VAR }}" ]; then - echo 'VAR={\"key\":\"builder.sh\",\"path\":\"unattended_installer/builder.sh\"}' >> $GITHUB_ENV - else - echo 'VAR=${{ env.VAR }},{\"key\":\"builder.sh\",\"path\":\"unattended_installer/builder.sh\"}' >> $GITHUB_ENV - fi \ No newline at end of file diff --git a/.github/actions/offline-installation/common.sh b/.github/actions/offline-installation/common.sh deleted file mode 100644 index 6330ce271b..0000000000 --- a/.github/actions/offline-installation/common.sh +++ /dev/null @@ -1,317 +0,0 @@ -#!/bin/bash - -function check_package() { - - if [ "${sys_type}" == "deb" ]; then - if ! apt list --installed 2>/dev/null | grep -q "${1}"; then - echo "INFO: The package "${1}" is not installed." - return 1 - fi - elif [ "${sys_type}" == "rpm" ]; then - if ! yum list installed 2>/dev/null | grep -q "${1}"; then - echo "INFO: The package "${1}" is not installed." - return 1 - fi - fi - return 0 - -} - -function check_system() { - - if [ -n "$(command -v yum)" ]; then - sys_type="rpm" - echo "INFO: RPM system detected." - elif [ -n "$(command -v apt-get)" ]; then - sys_type="deb" - echo "INFO: DEB system detected." - else - echo "ERROR: could not detect the system." - exit 1 - fi - -} - -function check_file() { - - if [ ! -f "${1}" ]; then - echo "ERROR: The ${1} file could not be downloaded." - exit 1 - fi - -} - -function check_shards() { - - retries=0 - until [ "$(curl -s -k -u admin:admin "https://127.0.0.1:9200/_template/wazuh?pretty&filter_path=wazuh.settings.index.number_of_shards" | grep "number_of_shards")" ] || [ "${retries}" -eq 5 ]; do - sleep 5 - retries=$((retries+1)) - done - - if [ ${retries} -eq 5 ]; then - echo "ERROR: Could not get the number of shards." - exit 1 - fi - curl -s -k -u admin:admin "https://127.0.0.1:9200/_template/wazuh?pretty&filter_path=wazuh.settings.index.number_of_shards" - echo "INFO: Number of shards detected." - -} - -function dashboard_installation() { - - install_package "wazuh-dashboard" - check_package "wazuh-dashboard" - - echo "INFO: Generating certificates of the Wazuh dashboard..." - NODE_NAME=dashboard - mkdir /etc/wazuh-dashboard/certs - mv -n wazuh-certificates/$NODE_NAME.pem /etc/wazuh-dashboard/certs/dashboard.pem - mv -n wazuh-certificates/$NODE_NAME-key.pem /etc/wazuh-dashboard/certs/dashboard-key.pem - cp wazuh-certificates/root-ca.pem /etc/wazuh-dashboard/certs/ - chmod 500 /etc/wazuh-dashboard/certs - chmod 400 /etc/wazuh-dashboard/certs/* - chown -R wazuh-dashboard:wazuh-dashboard /etc/wazuh-dashboard/certs - - if [ "${sys_type}" == "deb" ]; then - enable_start_service "wazuh-dashboard" - elif [ "${sys_type}" == "rpm" ]; then - /usr/share/wazuh-dashboard/bin/opensearch-dashboards "-c /etc/wazuh-dashboard/opensearch_dashboards.yml" --allow-root > /dev/null 2>&1 & - fi - - retries=0 - # In this context, 302 HTTP code refers to SSL certificates warning: success. - until [ "$(curl -k -s -I -w "%{http_code}" https://127.0.0.1 -o /dev/null --fail)" -ne "302" ] || [ "${retries}" -eq 5 ]; do - echo "INFO: Sleeping 10 seconds." - sleep 10 - retries=$((retries+1)) - done - if [ ${retries} -eq 5 ]; then - echo "ERROR: The Wazuh dashboard installation has failed." - exit 1 - else - echo "INFO: The Wazuh dashboard is ready." - fi - -} - -function download_resources() { - - check_file "${ABSOLUTE_PATH}"/wazuh-install.sh - bash "${ABSOLUTE_PATH}"/wazuh-install.sh -dw "${sys_type}" - echo "INFO: Downloading the resources..." - - curl -sO https://packages.wazuh.com/4.3/config.yml - check_file "config.yml" - - sed -i -e '0,// s//127.0.0.1/' config.yml - sed -i -e '0,// s//127.0.0.1/' config.yml - sed -i -e '0,// s//127.0.0.1/' config.yml - - curl -sO https://packages.wazuh.com/4.3/wazuh-certs-tool.sh - check_file "wazuh-certs-tool.sh" - chmod 744 wazuh-certs-tool.sh - ./wazuh-certs-tool.sh --all - - tar xf wazuh-offline.tar.gz - echo "INFO: Download finished." - - if [ ! -d ./wazuh-offline ]; then - echo "ERROR: Could not download the resources." - exit 1 - fi - -} - -function enable_start_service() { - - systemctl daemon-reload - systemctl enable "${1}" - systemctl start "${1}" - - retries=0 - until [ "$(systemctl status "${1}" | grep "active")" ] || [ "${retries}" -eq 3 ]; do - sleep 2 - retries=$((retries+1)) - systemctl start "${1}" - done - - if [ ${retries} -eq 3 ]; then - echo "ERROR: The "${1}" service could not be started." - exit 1 - fi - -} - -function filebeat_installation() { - - install_package "filebeat" - check_package "filebeat" - - cp ./wazuh-offline/wazuh-files/filebeat.yml /etc/filebeat/ &&\ - cp ./wazuh-offline/wazuh-files/wazuh-template.json /etc/filebeat/ &&\ - chmod go+r /etc/filebeat/wazuh-template.json - - sed -i 's|\("index.number_of_shards": \)".*"|\1 "1"|' /etc/filebeat/wazuh-template.json - filebeat keystore create - echo admin | filebeat keystore add username --stdin --force - echo admin | filebeat keystore add password --stdin --force - tar -xzf ./wazuh-offline/wazuh-files/wazuh-filebeat-0.4.tar.gz -C /usr/share/filebeat/module - - echo "INFO: Generating certificates of Filebeat..." - NODE_NAME=wazuh-1 - mkdir /etc/filebeat/certs - mv -n wazuh-certificates/$NODE_NAME.pem /etc/filebeat/certs/filebeat.pem - mv -n wazuh-certificates/$NODE_NAME-key.pem /etc/filebeat/certs/filebeat-key.pem - cp wazuh-certificates/root-ca.pem /etc/filebeat/certs/ - chmod 500 /etc/filebeat/certs - chmod 400 /etc/filebeat/certs/* - chown -R root:root /etc/filebeat/certs - - if [ "${sys_type}" == "deb" ]; then - enable_start_service "filebeat" - elif [ "${sys_type}" == "rpm" ]; then - /usr/share/filebeat/bin/filebeat --environment systemd -c /etc/filebeat/filebeat.yml --path.home /usr/share/filebeat --path.config /etc/filebeat --path.data /var/lib/filebeat --path.logs /var/log/filebeat & - fi - - sleep 10 - check_shards - eval "filebeat test output" - if [ "${PIPESTATUS[0]}" != 0 ]; then - echo "ERROR: The Filebeat installation has failed." - exit 1 - fi - -} - -function indexer_initialize() { - - retries=0 - until [ "$(cat /var/log/wazuh-indexer/wazuh-cluster.log | grep "Node started")" ] || [ "${retries}" -eq 5 ]; do - sleep 5 - retries=$((retries+1)) - done - - if [ ${retries} -eq 5 ]; then - echo "ERROR: The indexer node is not started." - exit 1 - fi - /usr/share/wazuh-indexer/bin/indexer-security-init.sh - -} - -function indexer_installation() { - - if [ "${sys_type}" == "rpm" ]; then - rpm --import ./wazuh-offline/wazuh-files/GPG-KEY-WAZUH - fi - - install_package "wazuh-indexer" - check_package "wazuh-indexer" - - echo "INFO: Generating certificates of the Wazuh indexer..." - NODE_NAME=node-1 - mkdir /etc/wazuh-indexer/certs - mv -n wazuh-certificates/$NODE_NAME.pem /etc/wazuh-indexer/certs/indexer.pem - mv -n wazuh-certificates/$NODE_NAME-key.pem /etc/wazuh-indexer/certs/indexer-key.pem - mv wazuh-certificates/admin-key.pem /etc/wazuh-indexer/certs/ - mv wazuh-certificates/admin.pem /etc/wazuh-indexer/certs/ - cp wazuh-certificates/root-ca.pem /etc/wazuh-indexer/certs/ - chmod 500 /etc/wazuh-indexer/certs - chmod 400 /etc/wazuh-indexer/certs/* - chown -R wazuh-indexer:wazuh-indexer /etc/wazuh-indexer/certs - - sed -i 's|\(network.host: \)"0.0.0.0"|\1"127.0.0.1"|' /etc/wazuh-indexer/opensearch.yml - - if [ "${sys_type}" == "rpm" ]; then - runuser "wazuh-indexer" --shell="/bin/bash" --command="OPENSEARCH_PATH_CONF=/etc/wazuh-indexer /usr/share/wazuh-indexer/bin/opensearch" > /dev/null 2>&1 & - sleep 5 - elif [ "${sys_type}" == "deb" ]; then - enable_start_service "wazuh-indexer" - fi - - indexer_initialize - sleep 10 - eval "curl -s -XGET https://127.0.0.1:9200 -u admin:admin -k --fail" - if [ "${PIPESTATUS[0]}" != 0 ]; then - echo "ERROR: The Wazuh indexer installation has failed." - exit 1 - fi - -} - -function install_dependencies() { - - if [ "${sys_type}" == "rpm" ]; then - dependencies=( util-linux initscripts openssl ) - not_installed=() - for dep in "${dependencies[@]}"; do - if [ "${dep}" == "openssl" ]; then - if ! yum list installed 2>/dev/null | grep -q "${dep}\.";then - not_installed+=("${dep}") - fi - elif ! yum list installed 2>/dev/null | grep -q "${dep}";then - not_installed+=("${dep}") - fi - done - - if [ "${#not_installed[@]}" -gt 0 ]; then - echo "--- Dependencies ---" - for dep in "${not_installed[@]}"; do - echo "Installing $dep." - eval "yum install ${dep} -y" - if [ "${PIPESTATUS[0]}" != 0 ]; then - echo "ERROR: Cannot install dependency: ${dep}." - exit 1 - fi - done - fi - - elif [ "${sys_type}" == "deb" ]; then - eval "apt-get update -q > /dev/null" - dependencies=( openssl ) - not_installed=() - - for dep in "${dependencies[@]}"; do - if ! apt list --installed 2>/dev/null | grep -q "${dep}"; then - not_installed+=("${dep}") - fi - done - - if [ "${#not_installed[@]}" -gt 0 ]; then - echo "--- Dependencies ----" - for dep in "${not_installed[@]}"; do - echo "Installing $dep." - apt-get install -y "${dep}" - if [ "${install_result}" != 0 ]; then - echo "ERROR: Cannot install dependency: ${dep}." - exit 1 - fi - done - fi - fi - -} - -function install_package() { - - if [ "${sys_type}" == "deb" ]; then - dpkg -i ./wazuh-offline/wazuh-packages/"${1}"*.deb - elif [ "${sys_type}" == "rpm" ]; then - rpm -ivh ./wazuh-offline/wazuh-packages/"${1}"*.rpm - fi - -} - -function manager_installation() { - - install_package "wazuh-manager" - check_package "wazuh-manager" - - if [ "${sys_type}" == "deb" ]; then - enable_start_service "wazuh-manager" - elif [ "${sys_type}" == "rpm" ]; then - /var/ossec/bin/wazuh-control start - fi - -} diff --git a/.github/actions/offline-installation/offline-installation.sh b/.github/actions/offline-installation/offline-installation.sh deleted file mode 100644 index 787b20bf66..0000000000 --- a/.github/actions/offline-installation/offline-installation.sh +++ /dev/null @@ -1,21 +0,0 @@ -#!/bin/bash - -# Gets the absolute path of the script, used to load the common.sh file -ABSOLUTE_PATH="$( cd $(dirname ${0}) ; pwd -P )" -. ${ABSOLUTE_PATH}/common.sh - -check_system -install_dependencies -download_resources - -indexer_installation -echo "INFO: Wazuh indexer installation completed." - -manager_installation -echo "INFO: Wazuh manager installation completed." - -filebeat_installation -echo "INFO: Filebeat installation completed." - -dashboard_installation -echo "INFO: Wazuh dashboard installation completed." diff --git a/.github/actions/passwords-tool/tests-stack-failure.sh b/.github/actions/passwords-tool/tests-stack-failure.sh deleted file mode 100644 index 632251c3fa..0000000000 --- a/.github/actions/passwords-tool/tests-stack-failure.sh +++ /dev/null @@ -1,20 +0,0 @@ -#!/bin/bash - -apiPass="$(cat wazuh-install-files/wazuh-passwords.txt | awk "/username: 'wazuh'/{getline;print;}" | awk '{ print $2 }' | tr -d \' )" -adminPass="$(cat wazuh-install-files/wazuh-passwords.txt | awk "/username: 'admin'/{getline;print;}" | awk '{ print $2 }' | tr -d \')" - -if ! bash wazuh-passwords-tool.sh -u wazuuuh | grep "ERROR"; then - exit 1 -elif ! sudo bash wazuh-passwords-tool.sh -u admin -p password | grep "ERROR"; then - exit 1 -elif ! sudo bash wazuh-passwords-tool.sh -au wazuh -ap "${adminPass}" -u wazuh -p password -A | grep "ERROR"; then - exit 1 -elif ! curl -s -u wazuh:wazuh -k -X POST "https://localhost:55000/security/user/authenticate" | grep "Invalid credentials"; then - exit 1 -elif ! curl -s -u wazuuh:"${apiPass}" -k -X POST "https://localhost:55000/security/user/authenticate" | grep "Invalid credentials"; then - exit 1 -elif ! curl -s -XGET https://localhost:9200/ -u admin:admin -k | grep "Unauthorized"; then - exit 1 -elif ! curl -s -XGET https://localhost:9200/ -u adminnnn:"${adminPass}" -k | grep "Unauthorized"; then - exit 1 -fi diff --git a/.github/actions/passwords-tool/tests-stack-success.sh b/.github/actions/passwords-tool/tests-stack-success.sh deleted file mode 100644 index f1dd2fa3bc..0000000000 --- a/.github/actions/passwords-tool/tests-stack-success.sh +++ /dev/null @@ -1,91 +0,0 @@ -#!/bin/bash - -users=( admin kibanaserver kibanaro logstash readall snapshotrestore ) -api_users=( wazuh wazuh-wui ) - -echo '::group:: Change indexer password, password providing it.' - -bash wazuh-passwords-tool.sh -u admin -p LN*X1v.VNtCZ5sESEtLfijPAd39LXGAI -if curl -s -XGET https://localhost:9200/ -u admin:LN*X1v.VNtCZ5sESEtLfijPAd39LXGAI -k -w %{http_code} | grep "401"; then - exit 1 -fi -echo '::endgroup::' - -echo '::group:: Change indexer password without providing it.' - -indx_pass="$(bash wazuh-passwords-tool.sh -u admin | awk '/admin/{ print $NF }' | tr -d \' )" -if curl -s -XGET https://localhost:9200/ -u admin:"${indx_pass}" -k -w %{http_code} | grep "401"; then - exit 1 -fi - -echo '::endgroup::' - -echo '::group:: Change all passwords except Wazuh API ones.' - -mapfile -t pass < <(bash wazuh-passwords-tool.sh -a | grep 'The password for' | awk '{ print $NF }') -for i in "${!users[@]}"; do - if curl -s -XGET https://localhost:9200/ -u "${users[i]}":"${pass[i]}" -k -w %{http_code} | grep "401"; then - exit 1 - fi -done - -echo '::endgroup::' - -echo '::group:: Change all passwords.' - -wazuh_pass="$(cat wazuh-install-files/wazuh-passwords.txt | awk "/username: 'wazuh'/{getline;print;}" | awk '{ print $2 }' | tr -d \' )" - -mapfile -t passall < <(bash wazuh-passwords-tool.sh -a -au wazuh -ap "${wazuh_pass}" | grep 'The password for' | awk '{ print $NF }' ) -passindexer=("${passall[@]:0:6}") -passapi=("${passall[@]:(-2)}") - -for i in "${!users[@]}"; do - if curl -s -XGET https://localhost:9200/ -u "${users[i]}":"${passindexer[i]}" -k -w %{http_code} | grep "401"; then - exit 1 - fi -done - -for i in "${!api_users[@]}"; do - if curl -s -u "${api_users[i]}":"${passapi[i]}" -w "%{http_code}" -k -X POST "https://localhost:55000/security/user/authenticate" | grep "401"; then - exit 1 - fi -done - -echo '::endgroup::' - -echo '::group:: Change single Wazuh API user.' - -bash wazuh-passwords-tool.sh -au wazuh -ap "${passapi[0]}" -u wazuh -p BkJt92r*ndzN.CkCYWn?d7i5Z7EaUt63 -A - if curl -s -w "%{http_code}" -u wazuh:BkJt92r*ndzN.CkCYWn?d7i5Z7EaUt63 -k -X POST "https://localhost:55000/security/user/authenticate" | grep "401"; then - exit 1 - fi -echo '::endgroup::' - -echo '::group:: Change all passwords except Wazuh API ones using a file.' - -mapfile -t passfile < <(bash wazuh-passwords-tool.sh -f wazuh-install-files/wazuh-passwords.txt | grep 'The password for' | awk '{ print $NF }' ) -for i in "${!users[@]}"; do - if curl -s -XGET https://localhost:9200/ -u "${users[i]}":"${passfile[i]}" -k -w %{http_code} | grep "401"; then - exit 1 - fi -done -echo '::endgroup::' - -echo '::group:: Change all passwords from a file.' -mapfile -t passallf < <(bash wazuh-passwords-tool.sh -f wazuh-install-files/wazuh-passwords.txt -au wazuh -ap BkJt92r*ndzN.CkCYWn?d7i5Z7EaUt63 | grep 'The password for' | awk '{ print $NF }' ) -passindexerf=("${passallf[@]:0:6}") -passapif=("${passallf[@]:(-2)}") - -for i in "${!users[@]}"; do - if curl -s -XGET https://localhost:9200/ -u "${users[i]}":"${passindexerf[i]}" -k -w %{http_code} | grep "401"; then - exit 1 - fi -done - -for i in "${!api_users[@]}"; do - if curl -s -u "${api_users[i]}":"${passapif[i]}" -w "%{http_code}" -k -X POST "https://localhost:55000/security/user/authenticate" | grep "401"; then - exit 1 - fi -done - -echo '::endgroup::' diff --git a/.github/actions/shellcheck/action.yml b/.github/actions/shellcheck/action.yml deleted file mode 100755 index a2dca90456..0000000000 --- a/.github/actions/shellcheck/action.yml +++ /dev/null @@ -1,77 +0,0 @@ -name: 'Run shellcheck with reviewdog' -description: '🐶 Run shellcheck with reviewdog on pull requests to improve code review experience.' -inputs: - github_token: - description: 'GITHUB_TOKEN.' - default: '${{ github.token }}' - required: false - level: - description: 'Report level for reviewdog [info,warning,error]' - default: 'error' - required: false - reporter: - description: | - Reporter of reviewdog command [github-pr-check,github-pr-review,github-check]. - Default is github-pr-check. - github-pr-review can use Markdown and add a link to rule page in reviewdog reports. - default: 'github-pr-check' - required: false - filter_mode: - description: | - Filtering mode for the reviewdog command [added,diff_context,file,nofilter]. - Default is `file`. - default: 'file' - required: false - fail_on_error: - description: | - Exit code for reviewdog when errors are found [true,false] - Default is `false`. - default: 'false' - required: false - reviewdog_flags: - description: 'Additional reviewdog flags' - default: '' - required: false - path: - description: "Base directory to run shellcheck. Same as `[path]` of `find` command." - default: '.' - required: false - pattern: - description: "File patterns of target files. Same as `-name [pattern]` of `find` command." - default: '*.sh' - required: false - check_all_files_with_shebangs: - description: | - Checks all files with shebangs in the repository even if they do not match the pattern. - Default is `false`. - default: 'false' - required: false - exclude: - description: "Exclude patterns of target files. Same as `-not -path [exclude]` of `find` command." - default: '*/.git/*' - required: false - shellcheck_flags: - description: "Flags of shellcheck command." - default: '--external-sources' - required: false -runs: - using: "composite" - steps: - - uses: reviewdog/action-setup@v1 - with: - reviewdog_version: v0.14.0 - - run: .github/actions/shellcheck/script.sh - shell: bash - env: - SHELLCHECK_VERSION: 0.8.0 - INPUT_GITHUB_TOKEN: ${{ inputs.github_token }} - INPUT_LEVEL: ${{ inputs.level }} - INPUT_REPORTER: ${{ inputs.reporter }} - INPUT_FILTER_MODE: ${{ inputs.filter_mode }} - INPUT_FAIL_ON_ERROR: ${{ inputs.fail_on_error }} - INPUT_REVIEWDOG_FLAGS: ${{ inputs.reviewdog_flags }} - INPUT_PATH: ${{ inputs.path }} - INPUT_PATTERN: ${{ inputs.pattern }} - INPUT_EXCLUDE: ${{ inputs.exclude }} - INPUT_CHECK_ALL_FILES_WITH_SHEBANGS: ${{ inputs.check_all_files_with_shebangs }} - INPUT_SHELLCHECK_FLAGS: ${{ inputs.shellcheck_flags }} \ No newline at end of file diff --git a/.github/actions/shellcheck/script.sh b/.github/actions/shellcheck/script.sh deleted file mode 100755 index 9b86ce3c48..0000000000 --- a/.github/actions/shellcheck/script.sh +++ /dev/null @@ -1,93 +0,0 @@ -#!/usr/bin/env bash - -set -u - -echo '::group:: Installing shellcheck ... https://github.com/koalaman/shellcheck' -TEMP_PATH="$(mktemp -d)" -cd "${TEMP_PATH}" || exit -wget -qO- "https://github.com/koalaman/shellcheck/releases/download/v${SHELLCHECK_VERSION}/shellcheck-v${SHELLCHECK_VERSION}.linux.x86_64.tar.xz" | tar -xJf - -mkdir bin -cp "shellcheck-v$SHELLCHECK_VERSION/shellcheck" ./bin -PATH="${TEMP_PATH}/bin:$PATH" -echo '::endgroup::' - -cd "${GITHUB_WORKSPACE}" || exit - -export REVIEWDOG_GITHUB_API_TOKEN="${INPUT_GITHUB_TOKEN}" - -paths=() -while read -r pattern; do - [[ -n ${pattern} ]] && paths+=("${pattern}") -done <<< "${INPUT_PATH:-.}" - -names=() -if [[ "${INPUT_PATTERN:-*}" != '*' ]]; then - while read -r pattern; do - [[ -n ${pattern} ]] && names+=(-o -name "${pattern}") - done <<< "${INPUT_PATTERN}" - (( ${#names[@]} )) && { names[0]='('; names+=(')'); } -fi - -excludes=() -while read -r pattern; do - [[ -n ${pattern} ]] && excludes+=(-not -path "${pattern}") -done <<< "${INPUT_EXCLUDE:-}" - - -# Match all files matching the pattern -files_with_pattern=$(find "${paths[@]}" "${excludes[@]}" -type f "${names[@]}") - -# Match all files with a shebang (e.g. "#!/usr/bin/env zsh" or even "#!bash") in the first line of a file -# Ignore files which match "$pattern" in order to avoid duplicates -if [ "${INPUT_CHECK_ALL_FILES_WITH_SHEBANGS}" = "true" ]; then - files_with_shebang=$(find "${paths[@]}" "${excludes[@]}" -not "${names[@]}" -type f -print0 | xargs -0 awk 'FNR==1 && /^#!.*sh/ { print FILENAME }') -fi - -# Exit early if no files have been found -if [ -z "${files_with_pattern}" ] && [ -z "${files_with_shebang:-}" ]; then - echo "No matching files found to check." - exit 0 -fi - -FILES="${files_with_pattern} ${files_with_shebang:-}" -echo "CHECKING FILES:" -echo $FILES - -echo '::group:: Running shellcheck ...' -if [ "${INPUT_REPORTER}" = 'github-pr-review' ]; then - shellcheck -f json ${INPUT_SHELLCHECK_FLAGS:-'--external-sources'} $FILES \ - | jq -r '.[] | "\(.file):\(.line):\(.column):\(.level):\(.message) [SC\(.code)](https://github.com/koalaman/shellcheck/wiki/SC\(.code))"' \ - | reviewdog \ - -efm="%f:%l:%c:%t%*[^:]:%m" \ - -name="shellcheck" \ - -reporter=github-pr-review \ - -filter-mode="${INPUT_FILTER_MODE}" \ - -fail-on-error="${INPUT_FAIL_ON_ERROR}" \ - -level="${INPUT_LEVEL}" \ - ${INPUT_REVIEWDOG_FLAGS} - EXIT_CODE=$? -else - shellcheck -f json ${INPUT_SHELLCHECK_FLAGS:-'--external-sources'} ${FILES} | jq -r '.[] | "\(.file):\(.line):\(.column):\(.level):\(.message)"' > output.md - EXIT_CODE=$? -fi -echo '::endgroup::' - -echo '::group:: Running shellcheck (suggestion) ...' -shellcheck -f diff $FILES \ - | reviewdog \ - -name="shellcheck (suggestion)" \ - -f=diff \ - -f.diff.strip=1 \ - -reporter="github-pr-review" \ - -filter-mode="${INPUT_FILTER_MODE}" \ - -fail-on-error="${INPUT_FAIL_ON_ERROR}" \ - ${INPUT_REVIEWDOG_FLAGS} -EXIT_CODE_SUGGESTION=$? -echo '::endgroup::' - -echo "EXIT_CODE: ${EXIT_CODE}" -echo "EXIT_CODE_SUGGESTION: ${EXIT_CODE_SUGGESTION}" - -if [ "${EXIT_CODE}" -ne 0 ] || [ "${EXIT_CODE_SUGGESTION}" -ne 0 ]; then - exit $((EXIT_CODE + EXIT_CODE_SUGGESTION)) -fi \ No newline at end of file diff --git a/.github/workflows/offline-installation.yml b/.github/workflows/offline-installation.yml deleted file mode 100644 index f0abc40a59..0000000000 --- a/.github/workflows/offline-installation.yml +++ /dev/null @@ -1,63 +0,0 @@ -name: Offline installation test -on: - pull_request: - paths: - - 'unattended_installer/install_functions/wazuh-offline-download.sh' - workflow_dispatch: - -jobs: - Build-wazuh-install-script: - runs-on: ubuntu-latest - steps: - - name: Cancel previous runs - uses: fkirc/skip-duplicate-actions@master - with: - cancel_others: 'true' - github_token: ${{ secrets.GITHUB_TOKEN }} - skip_after_successful_duplicate: 'false' - - - uses: actions/checkout@v2 - - - name: Build wazuh-install script and use staging packages - working-directory: ./unattended_installer - run: | - bash builder.sh -i -d staging - - - uses: actions/upload-artifact@v3 - with: - name: script - path: | - unattended_installer/wazuh-install.sh - if-no-files-found: error - - Test-offline-installation-debian: - runs-on: ubuntu-latest - needs: Build-wazuh-install-script - steps: - - uses: actions/checkout@v2 - - - uses: actions/download-artifact@v3 - with: - name: script - - - name: Move unattended script - run: cp $GITHUB_WORKSPACE/wazuh-install.sh $GITHUB_WORKSPACE/.github/actions/offline-installation/wazuh-install.sh - - - name: Run script - run: sudo bash $GITHUB_WORKSPACE/.github/actions/offline-installation/offline-installation.sh - - Test-offline-installation-rpm: - runs-on: ubuntu-latest - needs: Build-wazuh-install-script - steps: - - uses: actions/checkout@v2 - - - uses: actions/download-artifact@v3 - with: - name: script - - - name: Move unattended script - run: cp $GITHUB_WORKSPACE/wazuh-install.sh $GITHUB_WORKSPACE/.github/actions/offline-installation/wazuh-install.sh - - - name: Launch docker and run script - run: sudo docker run -v $GITHUB_WORKSPACE/.github/actions/offline-installation/:/tests centos:centos7 bash /tests/offline-installation.sh diff --git a/.github/workflows/password-tool.yml b/.github/workflows/password-tool.yml deleted file mode 100644 index d486ae761d..0000000000 --- a/.github/workflows/password-tool.yml +++ /dev/null @@ -1,57 +0,0 @@ -# Because from 4.9.0 this script is migrated to a new repository, the tests of this script will not be executed. -# name: Password tool script tests -# on: -# pull_request: -# paths: -# - 'unattended_installer/passwords_tool/**' - -jobs: - Build-password-tool-and-wazuh-install-scripts: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v2 - - name: Build password-tool and wazuh-install scripts - working-directory: ./unattended_installer - run: | - bash builder.sh -p - bash builder.sh -i -d staging - shell: bash - - uses: actions/upload-artifact@v3 - with: - name: scripts - path: | - unattended_installer/wazuh-install.sh - unattended_installer/wazuh-passwords-tool.sh - if-no-files-found: error - - test-password-tool-success: - runs-on: ubuntu-latest - needs: Build-password-tool-and-wazuh-install-scripts - steps: - - uses: actions/checkout@v2 - - uses: actions/download-artifact@v3 - with: - name: scripts - - name: Install wazuh - run: | - sudo bash wazuh-install.sh -a -v - - name: Uncompress wazuh install files - run: sudo tar -xvf wazuh-install-files.tar - - name: Run script - run: sudo bash .github/actions/passwords-tool/tests-stack-success.sh - - test-password-tool-failure: - runs-on: ubuntu-latest - needs: Build-password-tool-and-wazuh-install-scripts - steps: - - uses: actions/checkout@v2 - - uses: actions/download-artifact@v3 - with: - name: scripts - - name: Install wazuh - run: | - sudo bash wazuh-install.sh -a -v - - name: Uncompress wazuh install files - run: sudo tar -xvf wazuh-install-files.tar - - name: Run script - run: sudo bash .github/actions/passwords-tool/tests-stack-failure.sh diff --git a/.github/workflows/shellcheck.yml b/.github/workflows/shellcheck.yml deleted file mode 100755 index db2c52a277..0000000000 --- a/.github/workflows/shellcheck.yml +++ /dev/null @@ -1,112 +0,0 @@ -name: Shellcheck code analysis -on: [pull_request] - -jobs: - Get-changes: - runs-on: ubuntu-latest - steps: - - name: Checkout - uses: actions/checkout@v2.1.0 - - name: Get changes - uses: jitterbit/get-changed-files@v1 - id: changed_files - with: - format: space-delimited - - name: Set tools - uses: './.github/actions/get-tools/' - with: - tool: "${{ steps.changed_files.outputs.all }}" - - name: Build matrix - id: set-matrix - run: | - echo "::set-output name=tools_matrix::{\"include\":[${{ env.VAR }}]}" - - name: Check matrix - id: check-matrix - run: | - if [ -z '${{ env.VAR }}' ];then - echo "::set-output name=empty_matrix::true" - else - echo "::set-output name=empty_matrix::false" - fi - outputs: - tools_matrix: ${{ steps.set-matrix.outputs.tools_matrix }} - empty_matrix: ${{ steps.check-matrix.outputs.empty_matrix }} - - Builder-scripts: - name: Builder scripts artifacts - runs-on: ubuntu-latest - needs: Get-changes - if: ${{ needs.Get-changes.outputs.empty_matrix != 'true' }} - strategy: - matrix: ${{ fromJson(needs.Get-changes.outputs.tools_matrix) }} - steps: - - name: Checkout - uses: actions/checkout@v2.1.0 - - name: Generate artifacts - uses: './.github/actions/generate-artifacts/' - with: - artifact: "${{ matrix.key }}" - - name: Upload artifact - uses: actions/upload-artifact@v3 - with: - name: artifacts_generated - path: | - unattended_installer/*.sh - !unattended_installer/builder.sh - - name: Upload artifact - if: contains(matrix.key, 'builder.sh') - uses: actions/upload-artifact@v3 - with: - name: artifacts_generated - path: | - unattended_installer/builder.sh - - Shellcheck-for-libraries: - name: Shellcheck / runner for libraries - runs-on: ubuntu-latest - needs: Get-changes - if: ${{ needs.Get-changes.outputs.empty_matrix != 'true' }} - strategy: - matrix: ${{ fromJson(needs.Get-changes.outputs.tools_matrix) }} - steps: - - uses: actions/checkout@v1 - - name: Shellcheck for libraries of artifacts - uses: './.github/actions/shellcheck/' - with: - github_token: ${{ secrets.github_token }} - reporter: github-pr-review - path: "${{ matrix.path }}" - pattern: "*.sh" - fail_on_error: "false" - check_all_files_with_shebangs: "true" - - Shellcheck-for-artifacts: - name: Shellcheck / runner for artifacts - runs-on: ubuntu-latest - needs: Builder-scripts - steps: - - uses: actions/checkout@v1 - - name: Download all artifacts - uses: actions/download-artifact@v3 - - name: Shellcheck for artifacts generated - uses: './.github/actions/shellcheck/' - with: - github_token: ${{ secrets.github_token }} - reporter: github-pr-check - path: "./artifacts_generated" - pattern: "*.sh" - fail_on_error: "false" - check_all_files_with_shebangs: "true" - - name: Get shellcheck output - id: get-comment-body - run: | - body="$(cat output.md)" - body="${body//'%'/'%25'}" - body="${body//$'\n'/'%0A'}" - body="${body//$'\r'/'%0D'}" - echo "::set-output name=body::$body" - - name: Comments into issue - uses: peter-evans/create-or-update-comment@v2 - with: - issue-number: ${{ github.event.number }} - body: ${{ steps.get-comment-body.outputs.body }} diff --git a/.gitignore b/.gitignore index 4d911922da..8e2dcba328 100644 --- a/.gitignore +++ b/.gitignore @@ -23,14 +23,4 @@ solaris/packer/packer-solaris10-virtualbox/ solaris/packer/packer_cache/ solaris/packer/sol-10-u11-ga-x86-dvd.iso solaris/packer/sol-11_3-text-x86.iso -unattended_installer/certs* -unattended_installer/configurations* -unattended_installer/config.yml -unattended_installer/.vscode -unattended_installer/wazuh-install-files* -unattended_installer/wazuh-install.sh -unattended_installer/wazuh-certs-tool.sh -unattended_installer/wazuh-passwords-tool.sh -unattended_installer/wazuh-passwords.txt -tests/unattended/unit/*.log output diff --git a/bump_version.py b/bump_version.py index 72e18d269e..0851ef2133 100755 --- a/bump_version.py +++ b/bump_version.py @@ -30,19 +30,15 @@ date=datetime.datetime.strptime(args.date, FORMAT_STRING) version=Version(args.version) -## Find files to bump .spec, changelog, pkginfo, .pkgproj, test-*.sh, -## installVariables.sh, unattended_installer/builder.sh, CHANGELOG.md +## Find files to bump .spec, changelog, pkginfo, .pkgproj, CHANGELOG.md spec_files=glob.glob('**/*.spec', recursive=True) changelog_files=glob.glob('**/changelog', recursive=True) copyright_files=glob.glob('**/copyright', recursive=True) pkginfo_files=glob.glob('**/pkginfo', recursive=True) pkgproj_files=glob.glob('**/*.pkgproj', recursive=True) test_files=glob.glob('**/test-*.sh', recursive=True) -install_variables_files=glob.glob('**/installVariables.sh', recursive=True) -unattended_builder_files=glob.glob('**/unattended_installer/builder.sh', recursive=True) changelog_md_files=glob.glob('**/CHANGELOG.md', recursive=True) VERSION_files=glob.glob('**/VERSION', recursive=True) -builder_files=glob.glob('**/unattended_installer/builder.sh', recursive=True) #Format variables SPEC_FORMAT_STRING="%a %b %d %Y" @@ -82,14 +78,6 @@ r'wazuh_version=\"(\d+\.\d+\.\d+)\"': f'wazuh_version=\"{version}\"'} -install_variables_files_dict = { - r'wazuh_major=\"(\d+\.\d+)\"': - f'wazuh_major=\"{version.major}.{version.minor}\"', - r'wazuh_version=\"(\d+\.\d+\.\d+)\"':f'wazuh_version=\"{version}\"'} - -unattended_builder_files_dict = { - r'source_branch="(\d+\.\d+\.\d+)"':f'source_branch="{version}"'} - changelog_md_files_dict = { (r'All notable changes to this project ' r'will be documented in this file.'): @@ -98,9 +86,6 @@ + (f"## [{version}]\n\n- https://github.com/wazuh/" f"wazuh-packages/releases/tag/v{version}\n")} -builder_files_dict = { - r'source_branch=\"(\d+\.\d+\.\d+)\"': f'source_branch=\"{version}\"'} - VERSION_files_dict = { r'(\d+\.\d+\.\d+)': f'{version}'} @@ -150,8 +135,5 @@ def bump_file_list(file_list, regex_replacement): bump_file_list(pkginfo_files,pkginfo_files_dict) bump_file_list(pkgproj_files,pkgproj_files_dict) bump_file_list(test_files,test_files_dict) -bump_file_list(install_variables_files,install_variables_files_dict) -bump_file_list(unattended_builder_files,unattended_builder_files_dict) bump_file_list(changelog_md_files,changelog_md_files_dict) bump_file_list(VERSION_files,VERSION_files_dict) -bump_file_list(builder_files,builder_files_dict) diff --git a/tests/unattended/install/pytest.ini b/tests/unattended/install/pytest.ini deleted file mode 100644 index 3827ff1d65..0000000000 --- a/tests/unattended/install/pytest.ini +++ /dev/null @@ -1,10 +0,0 @@ -[pytest] -filterwarnings = - ignore:Unverified HTTPS request is being made.* -markers = - wazuh: tests to be executed on Wazuh hosts (does not include wazuh-clusterd test). - wazuh_cluster: test for wazuh-clusterd it is meant to be executed on the master node if a wazuh cluster is configured. - wazuh_worker: test for wazuh cluster worker nodes. It is meant to be executed on the worker nodes. - indexer: tests to be executed on Wazuh Indexer hosts. - indexer_cluster: tests to be executed on Wazuh Indexer hosts on distributed installations. - dashboard: tests to be executed on Wazuh dashboard hosts. \ No newline at end of file diff --git a/tests/unattended/install/test_unattended.py b/tests/unattended/install/test_unattended.py deleted file mode 100644 index 521b401e47..0000000000 --- a/tests/unattended/install/test_unattended.py +++ /dev/null @@ -1,280 +0,0 @@ -from datetime import datetime -import pytest -import json -import sys -import tarfile -from subprocess import Popen, PIPE, check_output -import yaml -import requests -import socket -from base64 import b64encode -import warnings -import subprocess -from subprocess import check_call - -warnings.filterwarnings('ignore', message='Unverified HTTPS request') - -# ----------------------------- Aux functions ----------------------------- - -def read_services(): - services = None - p = Popen(['/var/ossec/bin/wazuh-control', 'status'], stdin=PIPE, stdout=PIPE, stderr=PIPE) - if sys.version_info[0] < 3: - services = p.stdout.read() - else: - services = p.stdout - p.kill() - -def get_password(username): - pass_dict={'username': 'tmp_user', 'password': 'tmp_pass'} - tmp_yaml="" - - with tarfile.open("../../../unattended_installer/wazuh-install-files.tar") as configurations: - configurations.extract("wazuh-install-files/wazuh-passwords.txt") - - with open("wazuh-install-files/wazuh-passwords.txt", 'r') as pass_file: - while pass_dict["username"] != username: - for i in range(4): - tmp_yaml+=pass_file.readline() - tmp_dict=yaml.safe_load(tmp_yaml) - if 'indexer_username' in tmp_dict: - pass_dict["username"]=tmp_dict["indexer_username"] - pass_dict["password"]=tmp_dict["indexer_password"] - if 'api_username' in tmp_dict: - pass_dict["username"]=tmp_dict["api_username"] - pass_dict["password"]=tmp_dict["api_password"] - return pass_dict["password"] - -def get_wazuh_version(): - wazuh_version = None - wazuh_version = subprocess.getoutput('/var/ossec/bin/wazuh-control info | grep VERSION | cut -d "=" -f2 | sed s/\\"//g') - return wazuh_version - -def get_indexer_ip(): - - with open("/etc/wazuh-indexer/opensearch.yml", 'r') as stream: - dictionary = yaml.safe_load(stream) - return (dictionary.get('network.host')) - -def get_dashboard_ip(): - - with open("/etc/wazuh-dashboard/opensearch_dashboards.yml", 'r') as stream: - dictionary = yaml.safe_load(stream) - return (dictionary.get('server.host')) - -def get_api_ip(): - - with open("/var/ossec/api/configuration/api.yaml", 'r') as stream: - dictionary = yaml.safe_load(stream) - try: - ip = dictionary.get('host') - except: - ip = '127.0.0.1' - return ip - -def api_call_indexer(host,query,address,api_protocol,api_user,api_pass,api_port): - - if (query == ""): # Calling ES API without query - if (api_user != "" and api_pass != ""): # If credentials provided - resp = requests.get(api_protocol + '://' + address + ':' + api_port, - auth=(api_user, - api_pass), - verify=False) - else: - resp = requests.get(api_protocol + '://' + address + ':' + api_port, verify=False) - - else: # Executing query search - if (api_pass != "" and api_pass != ""): - resp = requests.post(api_protocol + '://' + address + ':' + api_port + "/wazuh-alerts-4.x-*/_search", - json=query, - auth=(api_user, - api_pass), - verify=False) - else: - resp = requests.get(api_protocol + "://" + address + ":" + api_port) - response = resp.json() - return response - -def get_indexer_cluster_status(): - ip = get_indexer_ip() - resp = requests.get('https://'+ip+':9200/_cluster/health', - auth=("admin", - get_password("admin")), - verify=False) - return (resp.json()['status']) - -def get_dashboard_status(): - ip = get_dashboard_ip() - resp = requests.get('https://'+ip, - auth=("kibanaserver", - get_password("kibanaserver")), - verify=False) - return (resp.status_code) - -def get_wazuh_api_status(): - - protocol = 'https' - host = get_api_ip() - port = 55000 - user = 'wazuh' - password = get_password('wazuh') - login_endpoint = 'security/user/authenticate' - - login_url = f"{protocol}://{host}:{port}/{login_endpoint}" - basic_auth = f"{user}:{password}".encode() - login_headers = {'Content-Type': 'application/json', - 'Authorization': f'Basic {b64encode(basic_auth).decode()}'} - response = requests.post(login_url, headers=login_headers, verify=False) - token = json.loads(response.content.decode())['data']['token'] - requests_headers = {'Content-Type': 'application/json', - 'Authorization': f'Bearer {token}'} - response = requests.get(f"{protocol}://{host}:{port}/?pretty=true", headers=requests_headers, verify=False) - return response.json()['data']['title'] - -# ----------------------------- Tests ----------------------------- - -@pytest.mark.wazuh -def test_check_wazuh_manager_authd(): - assert check_call("ps -xa | grep wazuh-authd | grep -v grep", shell=True) != "" - -@pytest.mark.wazuh -def test_check_wazuh_manager_db(): - assert check_call("ps -xa | grep wazuh-db | grep -v grep", shell=True) != "" - -@pytest.mark.wazuh -def test_check_wazuh_manager_execd(): - assert check_call("ps -xa | grep wazuh-execd | grep -v grep", shell=True) != "" - -@pytest.mark.wazuh -def test_check_wazuh_manager_analysisd(): - assert check_call("ps -xa | grep wazuh-analysisd | grep -v grep", shell=True) != "" - -@pytest.mark.wazuh -def test_check_wazuh_manager_syscheckd(): - assert check_call("ps -xa | grep wazuh-syscheckd | grep -v grep", shell=True) != "" - -@pytest.mark.wazuh -def test_check_wazuh_manager_remoted(): - assert check_call("ps -xa | grep wazuh-remoted | grep -v grep", shell=True) != "" - -@pytest.mark.wazuh -def test_check_wazuh_manager_logcollec(): - assert check_call("ps -xa | grep wazuh-logcollec | grep -v grep", shell=True) != "" - -@pytest.mark.wazuh -def test_check_wazuh_manager_monitord(): - assert check_call("ps -xa | grep wazuh-monitord | grep -v grep", shell=True) != "" - -@pytest.mark.wazuh -def test_check_wazuh_manager_modulesd(): - assert check_call("ps -xa | grep wazuh-modulesd | grep -v grep", shell=True) != "" - -@pytest.mark.wazuh -def test_check_wazuh_manager_apid(): - assert check_call("ps -xa | grep wazuh_apid | grep -v grep", shell=True) != "" - -@pytest.mark.wazuh_cluster -def test_check_wazuh_manager_clusterd(): - assert check_call("ps -xa | grep clusterd.py | grep -v grep", shell=True) != "" - -@pytest.mark.wazuh -def test_check_filebeat_process(): - assert check_call("ps -xa | grep \"/usr/share/filebeat/bin/filebeat\" | grep -v grep", shell=True) != "" - -@pytest.mark.indexer -def test_check_indexer_process(): - assert check_call("ps -xa | grep wazuh-indexer | grep -v grep | cut -d \" \" -f15", shell=True) != "" - -@pytest.mark.dashboard -def test_check_dashboard_process(): - assert check_call("ps -xa | grep wazuh-dashboard | grep -v grep", shell=True) != "" - -@pytest.mark.indexer -def test_check_indexer_cluster_status_not_red(): - assert get_indexer_cluster_status() != "red" - -@pytest.mark.indexer_cluster -def test_check_indexer_cluster_status_not_yellow(): - assert get_indexer_cluster_status() != "yellow" - -@pytest.mark.dashboard -def test_check_dashboard_status(): - assert get_dashboard_status() == 200 - -@pytest.mark.wazuh -def test_check_wazuh_api_status(): - assert get_wazuh_api_status() == "Wazuh API REST" - -@pytest.mark.wazuh -def test_check_log_errors(): - found_error = False - exceptions = [ - 'WARNING: Cluster error detected', - 'agent-upgrade: ERROR: (8123): There has been an error executing the request in the tasks manager.', - "ERROR: Could not send message through the cluster after '10' attempts" - - ] - - with open('/var/ossec/logs/ossec.log', 'r') as f: - for line in f.readlines(): - if 'ERROR' in line: - if not any(exception in line for exception in exceptions): - found_error = True - break - assert found_error == False, line - -@pytest.mark.wazuh_cluster -def test_check_cluster_log_errors(): - found_error = False - with open('/var/ossec/logs/cluster.log', 'r') as f: - for line in f.readlines(): - if 'ERROR' in line: - found_error = True - break - assert found_error == False, line - -@pytest.mark.wazuh_worker -def test_check_cluster_log_errors(): - found_error = False - with open('/var/ossec/logs/cluster.log', 'r') as f: - for line in f.readlines(): - if 'ERROR' in line: - if 'Could not connect to master' not in line and 'Worker node is not connected to master' not in line and 'Connection reset by peer' not in line and "Error sending sendsync response to local client: Error 3020 - Timeout sending" not in line: - found_error = True - break - assert found_error == False, line - -@pytest.mark.wazuh_cluster -def test_check_api_log_errors(): - found_error = False - with open('/var/ossec/logs/api.log', 'r') as f: - for line in f.readlines(): - if 'ERROR' in line: - found_error = True - break - assert found_error == False, line - -@pytest.mark.indexer -def test_check_alerts(): - node_name = socket.gethostname() - query = { - "query": { - "bool": { - "must": [ - { - "wildcard": { - "agent.name": { - "value": '*' - } - } - } - ] - } - } - } - - response = api_call_indexer(get_indexer_ip(),query,get_indexer_ip(),'https',"admin",get_password("admin"),'9200') - - print(response) - - assert (response["hits"]["total"]["value"] > 0) diff --git a/tests/unattended/unit/README b/tests/unattended/unit/README deleted file mode 100644 index ee67f90aea..0000000000 --- a/tests/unattended/unit/README +++ /dev/null @@ -1,38 +0,0 @@ -Instructions to run uit tests: - - - All tests are defined in files as such: tests-{script_name}.sh, where {script_name}.sh is the file we are testing. - - To run the tests we use the auxiliary script `unit-tests.sh`, which creates a clean docker environment on which to run the tests. - - Docker must be installed and running in the system and the user must have access. - - The docker image is kept, it isn't destroyed when the script finishes. If something in the Dockerfile is changed, run with `-r` to rebuild - -NAME - unit-tests.sh - Unit test for the Wazuh installer. - -SYNOPSIS - bash unit-tests.sh [OPTIONS] -a | -d | -f - -DESCRIPTION - -a, --test-all - Test all files. - - -d, --debug - Shows the complete installation output. - - -f, --files - List of files to test. I.e. -f common checks - - -h, --help - Shows help. - - -r, --rebuild-image - Forces to rebuild the image. - - -TIPS: - - When many tests are broken after a merge a good way to test them and - fix them in order bypassing the desorder in which they are run is to use - the fact that a bash script exits on an unknown character. Write a `Ç` - after the first test and run it, only the first one will be run. Whenever - a test is ready, you move the `Ç` character a test or some tests down. - That way, you don't have to scroll through 70 tests to find one and see if - it is fixed. diff --git a/tests/unattended/unit/docker-unit-testing-tool/Dockerfile b/tests/unattended/unit/docker-unit-testing-tool/Dockerfile deleted file mode 100644 index f6b64ad3d6..0000000000 --- a/tests/unattended/unit/docker-unit-testing-tool/Dockerfile +++ /dev/null @@ -1,9 +0,0 @@ -FROM alpine:latest -RUN apk add --no-cache bash coreutils diffutils -RUN mkdir -p /tests/unattended/ - -COPY entrypoint.sh /usr/local/bin/test_file -RUN chmod +x /usr/local/bin/test_file - -# Set the entrypoint -ENTRYPOINT ["/usr/local/bin/test_file"] \ No newline at end of file diff --git a/tests/unattended/unit/docker-unit-testing-tool/entrypoint.sh b/tests/unattended/unit/docker-unit-testing-tool/entrypoint.sh deleted file mode 100644 index a504b6ddd4..0000000000 --- a/tests/unattended/unit/docker-unit-testing-tool/entrypoint.sh +++ /dev/null @@ -1,9 +0,0 @@ -#!/bin/bash - -FILE_NAME=${1} -cd /tests/unattended -if [ -f test-${FILE_NAME}.sh ]; then - bash test-${FILE_NAME}.sh -else - echo "Couldn't find test-${FILE_NAME}.sh" -fi \ No newline at end of file diff --git a/tests/unattended/unit/framework/bach.sh b/tests/unattended/unit/framework/bach.sh deleted file mode 100644 index 6462d1e58a..0000000000 --- a/tests/unattended/unit/framework/bach.sh +++ /dev/null @@ -1,642 +0,0 @@ -# -*- mode: sh -*- -# Bach Testing Framework, https://bach.sh -# Copyright (C) 2019 Chai Feng -# -# Bach Testing Framework is dual licensed under: -# - GNU General Public License v3.0 -# - Mozilla Public License 2.0 -set -euo pipefail -shopt -s expand_aliases - -export BACH_COLOR="${BACH_COLOR:-auto}" -export PS4='+(${BASH_SOURCE##*/}:${LINENO}): ${FUNCNAME[0]:+${FUNCNAME[0]}(): }' - -BACH_OS_NAME="$(uname)" -declare -gxr BACH_OS_NAME - -declare -gxa bach_origin_paths=() -while builtin read -r -d: folder; do - bach_origin_paths+=("$folder") -done <<< "${PATH}:" - -function @out() { - if [[ "${1:-}" == "-" || ! -t 0 ]]; then - [[ "${1:-}" == "-" ]] && shift - while IFS=$'\n' read -r line; do - builtin printf "%s\n" "${*}$line" - done - elif [[ "$#" -gt 0 ]]; then - builtin printf "%s\n" "$*" - else - builtin printf "\n" - fi -} 8>/dev/null -export -f @out - -function @err() { - @out "$@" -} >&2 -export -f @err - -function @die() { - @out "$@" - exit 1 -} >&2 -export -f @die - -if [[ -z "${BASH_VERSION:-}" ]] || [[ "${BASH_VERSINFO[0]}" -lt 4 ]]; then - @die "Bach Testing Framework only support Bash v4+!" -fi - -if [[ "${BACH_DEBUG:-}" != true ]]; then - function @debug() { - : - } -else - exec 8>&2 - function @debug() { - builtin printf '[DEBUG] %s\n' "$*" - } >&8 -fi -export -f @debug - -function bach-real-path() { - declare folder name="$1" - declare altname="${name#*|}" - name="${name%|*}" - for folder in "${bach_origin_paths[@]}"; do - if [[ -x "$folder/$name" ]]; then - builtin echo "$folder/$name" - return 0 - elif [[ "$name" != "$altname" && -x "$folder/$altname" ]]; then - builtin echo "$folder/$altname" - return 0 - fi - done - return 1 -} -export -f bach-real-path - -export BACH_DEV_STDIN="" - -function bach_restore_stdin() { - if [[ ! -t 0 ]]; then - declare name - [[ -n "$BACH_DEV_STDIN" ]] || for name in /dev/ptmx /dev/pts/ptmx /dev/ttyv[0-9a-f]; do - if [[ -r "$name" && -c "$name" ]]; then - ls -l "$name" >&2 - BACH_DEV_STDIN="$name" - break - fi - done - exec 0<&- - exec 0<"$BACH_DEV_STDIN" - fi -} - -function bach_initialize(){ - enable -n alias bg bind dirs disown fc fg hash help history jobs kill suspend times ulimit umask unalias wait - - declare util name util_path - - declare -a bash_builtin_cmds=(cd echo enable popd pushd pwd shopt test trap type) - - for name in . command exec false set true unset "${bash_builtin_cmds[@]}"; do - eval "function @${name}() { builtin $name \"\$@\"; } 8>/dev/null; export -f @${name}" - done - - for name in eval; do - eval "function @${name}() { builtin $name \"\$@\"; }; export -f @${name}" - done - - function @source() { - declare script="$1" - shift - builtin source "$script" "$@" - } - - declare -a bach_core_utils=(cat chmod cut diff find env grep ls "shasum|sha1sum" mkdir mktemp rm rmdir sed sort tee touch which xargs) - - for util in "${bach_core_utils[@]}"; do - if [[ "$util" == "shasum|"* && "$BACH_OS_NAME" == FreeBSD ]]; then - util="shasum|sha1" - fi - name="${util%|*}" - util_path="$(bach-real-path "$util")" - eval "[[ -n \"${util_path}\" ]] || @die \"Fatal, CAN NOT find '$name' in \\\$PATH\"; function @${name}() { \"${util_path}\" \"\$@\"; } 8>/dev/null; export -f @${name}" - done - - bach_restore_stdin - @mockall "${bash_builtin_cmds[@]}" source . - - eval "$(builtin export | while read -rs name; do - name="${name%%=*}" - name="${name##* }" - [[ "${name^^}" != BACH_* ]] || continue - builtin echo "unset '$name' || builtin true" - done)" - builtin export LANG=C TERM=vt100 - unset name util_path -} - -function @real() { - declare name="$1" real_cmd - if [[ "$name" == */* ]]; then - @echo "$@" - return - fi - real_cmd="$(bach-real-path "$1" 7>&1)" - if [[ -z "${real_cmd}" ]]; then - real_cmd="${name}_not_found" - fi - declare -a cmd=("${real_cmd}" "${@:2}") - @debug "[REAL-CMD]" "${cmd[@]}" - "${cmd[@]}" -} -export -f @real - -function bach-get-all-functions() { - declare -F -} -export -f bach-get-all-functions - -function bach--skip-the-test() { - declare test="$1" test_filter - while read -d, test_filter; do - [[ -n "$test_filter" ]] || continue - [[ "$test" == $test_filter ]] && return 0 - [[ "$test" == test-$test_filter ]] && return 0 - done <<< "${BACH_TESTS:-}," -} -export -f bach--skip-the-test - -function bach-run-tests--get-all-tests() { - bach-get-all-functions | @sort -R | while read -r _ _ name; do - [[ "$name" == test?* ]] || continue - [[ "$name" == *-assert ]] && continue - bach--skip-the-test "$name" || continue - builtin printf "%s\n" "$name" - done -} - -for donotpanic in donotpanic dontpanic do-not-panic dont-panic do_not_panic dont_panic; do - eval "function @${donotpanic}() { builtin printf '\n%s\n line number: %s\n script stack: %s\n\n' 'DO NOT PANIC!' \"\${BASH_LINENO}\" \"\${BASH_SOURCE[*]}\"; builtin exit 1; } >&2; export -f @${donotpanic};" -done - -function bach--is-function() { - [[ "$(@type -t "$1")" == function ]] -} -export -f bach--is-function - -declare -gr __bach_run_test__ignore_prefix="## BACH:" -function @comment() { - @out "${__bach_run_test__ignore_prefix}" "$@" -} -export -f @comment - -function bach-run-tests() { - set -euo pipefail - - bach_initialize - - for donotpanic in donotpanic dontpanic do-not-panic dont-panic do_not_panic dont_panic; do - eval "function @${donotpanic}() { builtin true; }; export -f @${donotpanic}" - done - - function command() { - if [[ "$1" != -* ]] && bach--is-function "$1"; then - "$@" - else - mockfunc="$(@generate_mock_function_name command "$@")" - if bach--is-function "${mockfunc}"; then - @debug "[BC-func]" "${mockfunc}" "$@" - "${mockfunc}" "$@" - else - command_not_found_handle command "$@" - fi - fi - } - export -f command - - function xargs() { - declare param - declare -a xargs_opts - while param="${1:-}"; [[ -n "${param:-}" ]]; do - shift || true - if [[ "$param" == "--" ]]; then - xargs_opts+=("${BASH:-bash}" "-c" "$(builtin printf "'%s' " "$@") \$@" "-s") - break - else - xargs_opts+=("$param") - fi - done - @debug "@mock-xargs" "${xargs_opts[@]}" - if [[ "$#" -gt 0 ]]; then - @xargs "${xargs_opts[@]}" - else - [[ -t 0 ]] || @cat &>/dev/null - @dryrun xargs "${xargs_opts[@]}" - fi - } - export -f xargs - - if [[ "${BACH_ASSERT_IGNORE_COMMENT}" == true ]]; then - BACH_ASSERT_DIFF_OPTS+=(-I "^${__bach_run_test__ignore_prefix}") - fi - - declare color_ok color_err color_end - if [[ "$BACH_COLOR" == "always" ]] || [[ "$BACH_COLOR" != "no" && -t 1 && -t 2 ]]; then - color_ok="\e[1;32m" - color_err="\e[1;31m" - color_end="\e[0;m" - else - color_ok="" - color_err="" - color_end="" - fi - declare name friendly_name testresult test_name_assert_fail - declare -i total=0 error=0 - declare -a all_tests - mapfile -t all_tests < <(bach-run-tests--get-all-tests) - @echo "1..${#all_tests[@]}" - for name in "${all_tests[@]}"; do - # @debug "Running test: $name" - friendly_name="${name/#test-/}" - friendly_name="${friendly_name//-/ }" - friendly_name="${friendly_name// / -}" - : $(( ++total )) - testresult="$(@mktemp)" - @set +e - assert-execution "$name" &>"$testresult"; test_retval="$?" - @set -e - if [[ "$name" == test-ASSERT-FAIL-* ]]; then - test_retval="$(( test_retval == 0?1:0 ))" - test_name_assert_fail="${color_err}ASSERT FAIL${color_end}" - friendly_name="${friendly_name/#ASSERT FAIL/}" - else - test_name_assert_fail="" - fi - if [[ "$test_retval" -eq 0 ]]; then - builtin printf "${color_ok}ok %d - ${test_name_assert_fail}${color_ok}%s${color_end}\n" "$total" "$friendly_name" - else - : $(( ++error )) - builtin printf "${color_err}not ok %d - ${test_name_assert_fail}${color_err}%s${color_end}\n" "$total" "$friendly_name" - { - builtin printf "\n" - @cat "$testresult" >&2 - builtin printf "\n" - } >&2 - fi - @rm "$testresult" &>/dev/null - done - - declare color_result="$color_ok" - if (( error > 0 )); then - color_result="$color_err" - fi - builtin printf -- "# -----\n#${color_result} All tests: %s, failed: %d, skipped: %d${color_end}\n" \ - "${#all_tests[@]}" "$error" "$(( ${#all_tests[@]} - total ))">&2 - [[ "$error" == 0 ]] && [[ "${#all_tests[@]}" -eq "$total" ]] -} - -function bach-on-exit() { - if [[ -o xtrace ]]; then - exec 8>&2 - BASH_XTRACEFD=8 - fi - if [[ "$?" -eq 0 ]]; then - [[ "${BACH_DISABLED:-false}" == true ]] || bach-run-tests - else - builtin printf "Bail out! %s\n" "Couldn't initlize tests." - fi -} - -trap bach-on-exit EXIT - -function @generate_mock_function_name() { - declare name="$1" - @echo "mock_exec_${name}_$(@dryrun "${@}" | @shasum | @cut -b1-7)" -} -export -f @generate_mock_function_name - -function @mock() { - declare -a param name cmd func body desttype - name="$1" - if [[ "$name" == @(builtin|declare|eval|set|unset|true|false|read) ]]; then - @die "Cannot mock the builtin command: $name" - fi - if [[ command == "$name" && "$2" != -* ]]; then - shift - name="$1" - fi - desttype="$(@type -t "$name" || true)" - for param; do - if [[ "$param" == '===' ]]; then - shift - break - fi - cmd+=("$param") - done - shift "${#cmd[@]}" - if [[ "$name" == /* ]]; then - @die "Cannot mock an absolute path: $name" - elif [[ "$name" == */* ]] && [[ -e "$name" ]]; then - @die "Cannot mock an existed path: $name" - fi - @debug "@mock $name" - if [[ "$#" -gt 0 ]]; then - @debug "@mock $name $*" - declare -a params=("$@") - func="$(declare -p params); \"\${params[@]}\"" - #func="$*" - elif [[ ! -t 0 ]]; then - @debug "@mock $name @cat" - func="$(@cat)" - fi - if [[ -z "${func:-}" ]]; then - @debug "@mock default $name" - func="if [[ -t 0 ]]; then @dryrun \"${name}\" \"\$@\" >&7; else @cat; fi" - fi - if [[ "$name" == */* ]]; then - [[ -d "${name%/*}" ]] || @mkdir -p "${name%/*}" - @cat > "$name" <