You are here

run-test.sh in Username Enumeration Prevention 8

Same filename and directory in other branches
  1. 7 tests/package-excludes/run-test.sh
#!/usr/bin/env bash
set -euo pipefail
IFS=$'\n\t'

#/ Usage:       ./package-excludes.sh <path>
#/ Description: Ensures that certain files are excluded from the drupal.org package.
#/ Options:
#/   --help: Display this help message
usage() { grep '^#/' "$0" | cut -c4- ; exit 0 ; }
expr "$*" : ".*--help" > /dev/null && usage

readonly LOG_FILE="/tmp/$(basename "$0").log"
info()    { echo "[INFO]    $*" | tee -a "$LOG_FILE" >&2 ; }
warning() { echo "[WARNING] $*" | tee -a "$LOG_FILE" >&2 ; }
error()   { echo "[ERROR]   $*" | tee -a "$LOG_FILE" >&2 ; }
fatal()   { echo "[FATAL]   $*" | tee -a "$LOG_FILE" >&2 ; exit 1 ; }

GIT_DIR=$@
TMP_DIR=/tmp/package-excludes

cleanup() {
  # Remove temporary files
  echo "cleaning up"
  rm -r "${TMP_DIR}"
}

if [[ "${BASH_SOURCE[0]}" = "$0" ]]; then
  trap cleanup EXIT

  mkdir -p ${TMP_DIR}
  cd ${TMP_DIR}

  RESULT="pass"
  git --git-dir="${GIT_DIR}/.git" archive --format=tar --output="encrypt_kms.tar" HEAD
  tar -vxxf encrypt_kms.tar
  grep 'export-ignore' "${GIT_DIR}/.gitattributes" | awk '{print $1}' | while read FILE; do
    MATCHES=$(find . -name "${FILE}")
    if [[ ! -z "${MATCHES}" ]]; then
      error "Excluded file found in package: ${FILE}"
      RESULT="fail"
    fi
  done

  if [ "${RESULT}" != "pass" ]; then
    fatal "Test failed"
  fi
fi

File

tests/package-excludes/run-test.sh
View source
  1. #!/usr/bin/env bash
  2. set -euo pipefail
  3. IFS=$'\n\t'
  4. #/ Usage: ./package-excludes.sh
  5. #/ Description: Ensures that certain files are excluded from the drupal.org package.
  6. #/ Options:
  7. #/ --help: Display this help message
  8. usage() { grep '^#/' "$0" | cut -c4- ; exit 0 ; }
  9. expr "$*" : ".*--help" > /dev/null && usage
  10. readonly LOG_FILE="/tmp/$(basename "$0").log"
  11. info() { echo "[INFO] $*" | tee -a "$LOG_FILE" >&2 ; }
  12. warning() { echo "[WARNING] $*" | tee -a "$LOG_FILE" >&2 ; }
  13. error() { echo "[ERROR] $*" | tee -a "$LOG_FILE" >&2 ; }
  14. fatal() { echo "[FATAL] $*" | tee -a "$LOG_FILE" >&2 ; exit 1 ; }
  15. GIT_DIR=$@
  16. TMP_DIR=/tmp/package-excludes
  17. cleanup() {
  18. # Remove temporary files
  19. echo "cleaning up"
  20. rm -r "${TMP_DIR}"
  21. }
  22. if [[ "${BASH_SOURCE[0]}" = "$0" ]]; then
  23. trap cleanup EXIT
  24. mkdir -p ${TMP_DIR}
  25. cd ${TMP_DIR}
  26. RESULT="pass"
  27. git --git-dir="${GIT_DIR}/.git" archive --format=tar --output="encrypt_kms.tar" HEAD
  28. tar -vxxf encrypt_kms.tar
  29. grep 'export-ignore' "${GIT_DIR}/.gitattributes" | awk '{print $1}' | while read FILE; do
  30. MATCHES=$(find . -name "${FILE}")
  31. if [[ ! -z "${MATCHES}" ]]; then
  32. error "Excluded file found in package: ${FILE}"
  33. RESULT="fail"
  34. fi
  35. done
  36. if [ "${RESULT}" != "pass" ]; then
  37. fatal "Test failed"
  38. fi
  39. fi