#!/usr/bin/env bash set -euo pipefail cd "$(dirname "$0")/.." test_name="password-hash-test-$$" site_directory="${UCE_TEST_SITE_DIRECTORY:-site}" source_dir="$site_directory/$test_name" bin_directory="${BIN_DIRECTORY:-}" if [[ -z "$bin_directory" && -r /etc/uce/settings.cfg ]]; then bin_directory=$(awk -F= '/^[[:space:]]*BIN_DIRECTORY[[:space:]]*=/ {gsub(/^[[:space:]]+|[[:space:]]+$/, "", $2); print $2; exit}' /etc/uce/settings.cfg) fi bin_directory="${bin_directory:-/tmp/uce/work}" cache_dir="" cleanup() { rm -rf "$source_dir" if [[ -n "$cache_dir" ]]; then rm -rf "$cache_dir" fi } trap cleanup EXIT mkdir -p "$source_dir" cache_dir="$bin_directory$(realpath "$source_dir")" printf '%s\n' \ 'CLI(Request& context) {' \ ' String encoded = password_hash("correct horse battery staple");' \ ' print(encoded, "\n", password_verify("correct horse battery staple", encoded) ? "valid" : "invalid", "\n", password_verify("wrong password", encoded) ? "wrong-valid" : "wrong-rejected", "\n", password_needs_rehash(encoded) ? "rehash" : "current", "\n", password_verify("password", "$uce$scrypt$999999999$8$1$00$00") ? "malformed-valid" : "malformed-rejected");' \ '}' >"$source_dir/test.uce" output=$(scripts/uce-cli "/$test_name/test.uce") if [[ "$output" != *'$uce$scrypt$65536$8$1$'* || "$output" != *$'\nvalid\nwrong-rejected\ncurrent\nmalformed-rejected'* ]]; then echo "native password hashing failed: $output" >&2 exit 1 fi echo "password hashing passed"