Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion rigforge.sh
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,16 @@ parse_config() {
if [ "$WORKER_CONFIG_FILE" == "null" ] || [ -z "$WORKER_CONFIG_FILE" ]; then
error "WORKER_CONFIG_FILE is not defined in $CONFIG_JSON."
fi
P2POOL_NODE_HOSTNAME=$(jq -r .P2POOL_NODE_HOSTNAME "$CONFIG_JSON")
P2POOL_NODE_HOSTNAME=$(jq -r '.P2POOL_NODE_HOSTNAME // empty' "$CONFIG_JSON")
# The host goes straight into the XMRig pool URL, so validate it before building: it must be set
# and look like a hostname/FQDN or an IPv4/IPv6 literal. This also rejects the unfilled template
# placeholder (<...>) and any shell/URL metacharacters.
if [ -z "$P2POOL_NODE_HOSTNAME" ]; then
error "P2POOL_NODE_HOSTNAME is required in $CONFIG_JSON (your pool/stack host or IP)."
fi
if ! [[ "$P2POOL_NODE_HOSTNAME" =~ ^[A-Za-z0-9._:-]+$ ]]; then
error "P2POOL_NODE_HOSTNAME is not a valid host/IP: '$P2POOL_NODE_HOSTNAME'. Use a hostname, FQDN, or IP address."
fi
ACCESS_TOKEN=$(jq -r '.ACCESS_TOKEN // empty' "$CONFIG_JSON")
if [ -z "$ACCESS_TOKEN" ]; then
ACCESS_TOKEN=$(hostname)
Expand Down
14 changes: 14 additions & 0 deletions tests/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,20 @@ assert_eq "FQDN passed through" "$(parse_and_print "$c" "$ROOT" P2
c="$(mkconf ip "{ \"P2POOL_NODE_HOSTNAME\": \"10.0.0.5\", $CFG_TPL }")"
assert_eq "IPv4 host passed through" "$(parse_and_print "$c" "$ROOT" P2POOL_NODE_ADDRESS)" "10.0.0.5"

echo "== unit: hostname validation (#8) =="
for h in box box.lan 10.0.0.5 fe80::1 rig-01; do
c="$(mkconf hnok "{ \"P2POOL_NODE_HOSTNAME\": \"$h\", $CFG_TPL }")"
parse_rc "$c" "$ROOT"; assert_rc "host '$h' accepted" "$?" "0"
done
c="$(mkconf hnempty "{ \"P2POOL_NODE_HOSTNAME\": \"\", $CFG_TPL }")"
parse_rc "$c" "$ROOT"; assert_rc "empty host rejected" "$?" "1"
c="$(mkconf hnmiss "{ $CFG_TPL }")"
parse_rc "$c" "$ROOT"; assert_rc "missing host rejected" "$?" "1"
for h in 'bad host' 'evil;rm' 'a/b' '<P2POOL_NODE_HOSTNAME>'; do
c="$(mkconf hnbad "{ \"P2POOL_NODE_HOSTNAME\": \"$h\", $CFG_TPL }")"
parse_rc "$c" "$ROOT"; assert_rc "host '$h' rejected" "$?" "1"
done

echo "== unit: parse_config — workspace + token + template resolution =="
c="$(mkconf dyn "{ \"HOME_DIR\": \"DYNAMIC_HOME\", \"P2POOL_NODE_HOSTNAME\": \"h\", $CFG_TPL }")"
assert_eq "DYNAMIC_HOME -> script data dir" "$(parse_and_print "$c" "$ROOT" WORKER_ROOT)" "$ROOT/data/worker"
Expand Down
Loading