Files
simple-object-server/testing/generate_test_config.sh
Your Name 1fed086348
All checks were successful
Build-Test-Publish / build (linux/amd64) (push) Successful in 49s
Build-Test-Publish / build (linux/arm64) (push) Successful in 1m7s
Build-Test-Publish / create-manifest (push) Successful in 16s
test: Add 3 and update 5 files
2025-08-10 15:55:36 +12:00

49 lines
1.3 KiB
Bash
Executable File

#!/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
set -euo pipefail
SCRIPT_DIR=$(dirname "$0")
CONFIG_FILE="${SCRIPT_DIR}/sos_config.json"
# Function to generate a secure random token
generate_token() {
# Generate 32 bytes of random data and encode as base64
# Remove non-alphanumeric characters for simplicity
openssl rand -base64 32 | tr -d '/+=' | cut -c1-32
}
# Generate 3 random tokens
TOKEN1=$(generate_token)
TOKEN2=$(generate_token)
TOKEN3=$(generate_token)
# Create the configuration file
cat > "${CONFIG_FILE}" << EOF
{
"write_tokens": [
"${TOKEN1}",
"${TOKEN2}",
"${TOKEN3}"
],
"rate_limiting": {
"auth_rate_limit": 5,
"auth_window_seconds": 2
},
"port": 7703,
"host": "127.0.0.1"
}
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 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}"