From 592373f0ea3898ff733fe090e0d20bee5e28e468 Mon Sep 17 00:00:00 2001 From: Vincent Koc Date: Sat, 20 Jun 2026 08:14:17 +0200 Subject: [PATCH] fix(ci): quote Windows testbox phone-home payloads --- .../workflows/windows-blacksmith-testbox.yml | 69 +++++++++++++------ test/scripts/ci-workflow-guards.test.ts | 9 +++ 2 files changed, 56 insertions(+), 22 deletions(-) diff --git a/.github/workflows/windows-blacksmith-testbox.yml b/.github/workflows/windows-blacksmith-testbox.yml index b31d0078a556..63bacc0408f0 100644 --- a/.github/workflows/windows-blacksmith-testbox.yml +++ b/.github/workflows/windows-blacksmith-testbox.yml @@ -57,6 +57,10 @@ jobs: echo "could not read required Blacksmith metadata" >&2 exit 1 fi + if ! jq -e 'type == "number"' <<<"$installation_model_id" >/dev/null; then + echo "invalid Blacksmith installation model id: ${installation_model_id}" >&2 + exit 1 + fi if [ -n "${BLACKSMITH_HOSTNAME:-}" ]; then runner_host="$BLACKSMITH_HOSTNAME" @@ -65,21 +69,32 @@ jobs: fi runner_ssh_port="${BLACKSMITH_SSH_PORT:-22}" + hydrating_body="$RUNNER_TEMP/testbox-hydrating.json" hydrating_response="$RUNNER_TEMP/testbox-hydrating.response" + jq -n \ + --arg testbox_id "$TESTBOX_ID" \ + --argjson installation_model_id "$installation_model_id" \ + --arg status "hydrating" \ + --arg ip_address "$runner_host" \ + --arg ssh_port "$runner_ssh_port" \ + --arg working_directory "$GITHUB_WORKSPACE" \ + --arg adopted_run_id "$GITHUB_RUN_ID" \ + '{ + testbox_id: $testbox_id, + installation_model_id: $installation_model_id, + status: $status, + ip_address: $ip_address, + ssh_port: $ssh_port, + working_directory: $working_directory, + adopted_run_id: $adopted_run_id, + metadata: {} + }' > "$hydrating_body" + hydrating_http_code="$(curl -sS -L --post302 --post303 -o "$hydrating_response" -w '%{http_code}' \ -X POST "${api_url}/api/testbox/phone-home" \ -H "Content-Type: application/json" \ -H "Authorization: Bearer ${auth_token}" \ - -d "{ - \"testbox_id\": \"${TESTBOX_ID}\", - \"installation_model_id\": ${installation_model_id}, - \"status\": \"hydrating\", - \"ip_address\": \"${runner_host}\", - \"ssh_port\": \"${runner_ssh_port}\", - \"working_directory\": \"${GITHUB_WORKSPACE}\", - \"adopted_run_id\": \"${GITHUB_RUN_ID}\", - \"metadata\": {} - }" || true)" + --data-binary @"$hydrating_body" || true)" echo "phone_home_hydrating_http=${hydrating_http_code}" if [[ ! "$hydrating_http_code" =~ ^2 ]]; then @@ -152,20 +167,30 @@ jobs: runner_ssh_port="$(cat "$state/runner_ssh_port")" working_directory="$(cat "$state/working_directory")" adopted_run_id="$(cat "$state/adopted_run_id")" + if ! jq -e 'type == "number"' <<<"$installation_model_id" >/dev/null; then + echo "invalid Blacksmith installation model id: ${installation_model_id}" >&2 + exit 1 + fi ready_body="$RUNNER_TEMP/testbox-ready.json" - cat > "$ready_body" < "$ready_body" http_code="$(curl -sS -L --post302 --post303 -o "$RUNNER_TEMP/testbox-ready.response" -w '%{http_code}' \ -X POST "${api_url}/api/testbox/phone-home" \ diff --git a/test/scripts/ci-workflow-guards.test.ts b/test/scripts/ci-workflow-guards.test.ts index 758cd908610d..c330883b86fb 100644 --- a/test/scripts/ci-workflow-guards.test.ts +++ b/test/scripts/ci-workflow-guards.test.ts @@ -270,6 +270,12 @@ describe("ci workflow guards", () => { expect(workflow).toContain('echo "phone_home_hydrating_http=${hydrating_http_code}"'); expect(workflow).toContain('echo "phone_home_ready_http=${http_code}"'); + expect(workflow).toContain('jq -e \'type == "number"\' <<<"$installation_model_id"'); + expect(workflow).toContain('--arg testbox_id "$TESTBOX_ID"'); + expect(workflow).toContain('--arg testbox_id "$testbox_id"'); + expect(workflow).toContain('--argjson installation_model_id "$installation_model_id"'); + expect(workflow).toContain('--data-binary @"$hydrating_body"'); + expect(workflow).toContain('--data-binary @"$ready_body"'); const hydratingFailureBlock = workflow.slice( workflow.indexOf('if [[ ! "$hydrating_http_code" =~ ^2 ]]; then'), workflow.indexOf('response="$(cat "$hydrating_response")"'), @@ -292,6 +298,9 @@ describe("ci workflow guards", () => { expect(workflow).not.toContain( 'phone_home_ready_http=${http_code}"\n\n echo "============================================"', ); + expect(workflow).not.toContain('\\"testbox_id\\": \\"${TESTBOX_ID}\\"'); + expect(workflow).not.toContain('cat > "$ready_body" < {