Commit 9b82479d authored by Pierre Smeyers's avatar Pierre Smeyers
Browse files

feat: add hook scripts support

parent 66f805de
Loading
Loading
Loading
Loading
+7 −0
Original line number Diff line number Diff line
@@ -71,3 +71,10 @@ environments) will automatically be propagated to your Test SSL tests.

If you're not using a smart deployment job, you may still explicitly declare the `TESTSSL_URL` variable (but that
will be unfortunately hardcoded to a single server).

### Hook scripts

The Test SSL template supports _optional_ **hook scripts** from your project, located in the root directory to perform additional project-specific logic:

* `pre-testssl.sh` is executed **before** running Test SSL,
* `post-testssl.sh` is executed **after** running Test SSL (whichever the tests status).
+23 −1
Original line number Diff line number Diff line
@@ -244,6 +244,21 @@ stages:
    log_info "... done"
  }

  function maybe_exec_hook() {
    if [[ -f "$1" ]]
    then
      log_info "\\e[33;1m$1\\e[0m hook found: execute"
      if [[ ! -x "$1" ]] && ! chmod +x "$1"
      then
        log_warn "... could not make \\e[33;1m${1}\\e[0m executable: please do it (chmod +x)"
        # fallback technique
        sh "$1"
      else
        "$1"
      fi
    fi
  }

  function eval_env_url() {
    # shellcheck disable=SC2154
    if [[ -n "$environment_url" ]]
@@ -285,7 +300,14 @@ testssl:
    - eval_env_url
  script:
    - mkdir -p -m 777 reports
    - testssl.sh --jsonfile reports/testssl.native.json --csvfile reports/testssl.native.csv ${TRACE+--debug 2} $TESTSSL_ARGS $TESTSSL_URL
    # maybe execute pre hook
    - maybe_exec_hook "./pre-testssl.sh"
    # run tests
    - testssl.sh --jsonfile reports/testssl.native.json --csvfile reports/testssl.native.csv ${TRACE+--debug 2} $TESTSSL_ARGS $TESTSSL_URL || rc=$?
    # maybe execute post hook
    - maybe_exec_hook "./post-testssl.sh"
    # exit with return code
    - exit $rc
  artifacts:
    name: "$CI_JOB_NAME artifacts from $CI_PROJECT_NAME on $CI_COMMIT_REF_SLUG"
    when: always