test: Add 8 and update 14 files
Some checks failed
Build-Test-Publish / build (linux/amd64) (push) Failing after 22s
Build-Test-Publish / build (linux/arm64) (push) Failing after 32s
Build-Test-Publish / create-manifest (push) Has been skipped

This commit is contained in:
Your Name
2025-08-10 21:18:40 +12:00
parent 1fed086348
commit 8ab6028597
22 changed files with 1392 additions and 81 deletions

View File

@@ -1,12 +1,14 @@
#!/bin/bash
# Generate secure random tokens and create test configuration
# This script generates a new sos_config.json with random tokens for each test run
# This script generates a new sos_config.json with random bcrypt-hashed tokens for each test run
# The plaintext tokens are exported as environment variables for use in tests
set -euo pipefail
SCRIPT_DIR=$(dirname "$0")
SCRIPT_DIR=$(cd "$(dirname "$0")" && pwd)
CONFIG_FILE="${SCRIPT_DIR}/sos_config.json"
PARENT_DIR=$(cd "${SCRIPT_DIR}/.." && pwd)
# Function to generate a secure random token
generate_token() {
@@ -20,13 +22,32 @@ TOKEN1=$(generate_token)
TOKEN2=$(generate_token)
TOKEN3=$(generate_token)
# Create the configuration file
# Export plaintext tokens as environment variables for scripts that need them
export TEST_TOKEN1="${TOKEN1}"
export TEST_TOKEN2="${TOKEN2}"
export TEST_TOKEN3="${TOKEN3}"
echo "Generating bcrypt-hashed tokens (this may take a moment)..."
# Check if hash_token utility exists
if [ ! -f "${PARENT_DIR}/output/hash_token" ]; then
echo "Error: hash_token utility not found at ${PARENT_DIR}/output/hash_token"
echo "Please build it first with: ./build.sh"
exit 1
fi
# Generate bcrypt hashes with cost factor 10 (faster for testing)
HASH1=$("${PARENT_DIR}/output/hash_token" -c 10 -q "${TOKEN1}")
HASH2=$("${PARENT_DIR}/output/hash_token" -c 10 -q "${TOKEN2}")
HASH3=$("${PARENT_DIR}/output/hash_token" -c 10 -q "${TOKEN3}")
# Create configuration with hashed tokens
cat > "${CONFIG_FILE}" << EOF
{
"write_tokens": [
"${TOKEN1}",
"${TOKEN2}",
"${TOKEN3}"
"${HASH1}",
"${HASH2}",
"${HASH3}"
],
"rate_limiting": {
"auth_rate_limit": 5,
@@ -37,13 +58,9 @@ cat > "${CONFIG_FILE}" << EOF
}
EOF
# Export tokens as environment variables for scripts that need them
export TEST_TOKEN1="${TOKEN1}"
export TEST_TOKEN2="${TOKEN2}"
export TEST_TOKEN3="${TOKEN3}"
echo "Generated test configuration with bcrypt-hashed tokens:"
echo " Token 1 (plaintext): ${TOKEN1:0:8}... (hash: ${HASH1:0:20}...)"
echo " Token 2 (plaintext): ${TOKEN2:0:8}... (hash: ${HASH2:0:20}...)"
echo " Token 3 (plaintext): ${TOKEN3:0:8}... (hash: ${HASH3:0:20}...)"
echo "Generated test configuration with random tokens:"
echo " Token 1: ${TOKEN1:0:8}..." # Show only first 8 chars for security
echo " Token 2: ${TOKEN2:0:8}..."
echo " Token 3: ${TOKEN3:0:8}..."
echo "Configuration written to: ${CONFIG_FILE}"