#!/usr/bin/env bats # # Drive getcert with openssl absent, and with a certificate key that is not ready yet. # doxcat runs getcert in the foreground and ignores its status, so a wait with no bound stops # the boot and prints nothing. load 'helpers/shell_source' setup() { GETCERT="$(repo_path 'xCAT-genesis-scripts/usr/bin/getcert')" [ -r "$GETCERT" ] || skip "$GETCERT is required" COUNTER="${BATS_TEST_TMPDIR}/req-count" export GETCERT COUNTER } write_stub() { local dir="$1" name="$2" body="$3" printf '#!/bin/sh\n%s\n' "$body" >"$dir/$name" chmod 0755 "$dir/$name" } # A PATH directory holding the commands getcert runs. openssl is absent unless it is asked for. stub_dir() { # count defaults to a no-op: an empty value leaves "{ ; exit 1; }", which is a syntax # error, so the stub would fail for the wrong reason and report bash's message. local with_openssl="${1:-0}" count=":" local dir="${BATS_TEST_TMPDIR}/bin" rm -rf "$dir" mkdir -p "$dir" write_stub "$dir" allowcred.awk 'exec sleep 3' write_stub "$dir" hostname 'echo node1' write_stub "$dir" logger 'echo "$@" >&2' write_stub "$dir" sleep 'exec /bin/sleep "$@"' if [ "$with_openssl" = 1 ]; then [ -n "${COUNT_REQUESTS:-}" ] && count="echo req >> '$COUNTER'" write_stub "$dir" openssl "[ \"\$1\" = req ] && { $count ; echo \"\${OPENSSL_REQ_ERROR:-}\" >&2 ; exit 1; } exit 0" fi printf '%s\n' "$dir" } # Run getcert with only the stub directory on PATH. The timeout is the harness guard: a status # of 124 means getcert never stopped. run_getcert() { local bin="$1" limit="$2" csr_timeout="$3" timeout -k 2 "$limit" env PATH="$bin" GETCERT_CSR_TIMEOUT="$csr_timeout" \ /bin/bash "$GETCERT" 192.0.2.1:3001 2>&1