# shellcheck shell=bash # Scenarios set what the runner and items read # shellcheck disable=SC2034 DESCRIPTION="Hermes' gateway reaches only a Matrix server you've allowed; edit_json and empty files" TIER=quick scenario() { local out source "$CONNECTOR/configure.d/30-agents.sh" source "$CONNECTOR/configure.d/lib/json.sh" mkdir -p "$HOME/.hermes" "$(dirname "$HERMES_GATEWAY_UNIT")" step "edit_json" mkdir -p "$CONF_DIR/sandbox" : > "$CONF_DIR/sandbox/test.json" check "it edits an empty file" edit_json "$CONF_DIR/sandbox/test.json" '{}' '.a = 1' check_eq "from its default" 1 "$(jq .a "$CONF_DIR/sandbox/test.json")" rm -f "$CONF_DIR/sandbox/test.json" step "What Hermes' settings name" echo 'MATRIX_HOMESERVER=https://matrix.smoke.invalid:8448/' > "$HERMES_ENV" check_eq "the host in MATRIX_HOMESERVER" matrix.smoke.invalid "$(hermes_homeserver)" echo 'MATRIX_HOMESERVER=https://*.smoke.invalid' > "$HERMES_ENV" check_eq "not a wildcard" "" "$(hermes_homeserver)" printf 'MATRIX_HOMESERVER=https://evil\033[2Jhost\n' > "$HERMES_ENV" check_eq "not escape codes" "" "$(hermes_homeserver)" step "configure hermes asks before it's reached" source "$CONNECTOR/configure.d/33-hermes.sh" echo 'MATRIX_HOMESERVER=https://matrix.smoke.invalid' > "$HERMES_ENV" echo 'OPENROUTER_API_KEY=x' >> "$HERMES_ENV" check_not "a server not allowed yet isn't" hermes_homeserver_allowed matrix.smoke.invalid check_eq "it's to do for that server" matrix.smoke.invalid "$(pending_homeserver)" check_not "Hermes is to do" is_configured check "run_configure asks only about the server" run_configure check "the server is allowed" hermes_homeserver_allowed matrix.smoke.invalid check "Hermes is done" is_configured echo 'MATRIX_HOMESERVER=https://other.smoke.invalid' > "$HERMES_ENV" check_not "a server Hermes names later isn't allowed" hermes_homeserver_allowed other.smoke.invalid step "The gateway's drop-in" # No systemd user manager in a container systemctl() { :; } rm -f "$HERMES_SANDBOX_CONF" touch "$HERMES_GATEWAY_UNIT" mkdir -p "$(dirname "$HERMES_GATEWAY_DROPIN")" printf '[Service]\nEnvironment="FEDERATED_SANDBOX_DOMAINS=matrix.smoke.invalid"\nExecStart=\nExecStart=x\n' > "$HERMES_GATEWAY_DROPIN" check_not "an old drop-in isn't ok" gateway_ok out="$(sandbox_gateway 2>&1)" check "the server an old drop-in allowed is carried over" hermes_homeserver_allowed matrix.smoke.invalid check "the new drop-in is ok" gateway_ok check_not "it allows no domains itself" grep -q FEDERATED_SANDBOX_DOMAINS "$HERMES_GATEWAY_DROPIN" check "it says the server Hermes names now needs allowing" grep -q "other.smoke.invalid.*configure hermes" <<< "$out" printf '[Service]\nEnvironment="FEDERATED_SANDBOX_DOMAINS=*"\n' > "$HERMES_GATEWAY_DROPIN" rm -f "$HERMES_SANDBOX_CONF" hermes_carry_over_homeserver check_not "a wildcard isn't carried over" test -s "$HERMES_SANDBOX_CONF" rm -rf "$HERMES_GATEWAY_UNIT" "$HERMES_GATEWAY_UNIT.d" "$HOME/.hermes" }