49 lines
1.3 KiB
Bash
Executable File
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}" |