test: verify the arm artifact by ELF header, add _FORTIFY_SOURCE=2 build checks
An aarch64 ELF cannot be exec'd on an x86_64 host, so the arm leg is now proven by its ELF class and e_machine instead of by running it. Adds the hardened-build checks the other oss plugin suites carry.
AuthorPico <picobot@scorpioplayer.com>
Date2026-11-12 15:37:17
Commit1ede447c
Parents552223be
Changed files
tests/run.sh+39−1■■■■■
1 file+39−1
Diff
tests/run.sh+39−1■■■■■
index 2686f18..f239dc5 100755
--- a/tests/run.sh
+++ b/tests/run.sh
@@ -549,12 +549,50 @@ fi
549549 if command -v aarch64-linux-gnu-gcc >/dev/null 2>&1; then
550550 if aarch64-linux-gnu-gcc -O2 -std=c99 -static -I src -o "$FIX/arm-bin" src/plugin_opencode_login.c 2>/dev/null; then
551551 pass "static aarch64 build"
552- check "the arm binary reports the same metadata" '"name":"opencode"' "$("$FIX/arm-bin" --meta)"
552+ # an aarch64 ELF cannot be exec'd on an x86_64 host, so the artifact is
553+ # verified by its header instead of by running it.
554+ if python3 - "$FIX/arm-bin" <<'PY'
555+import sys
556+b = open(sys.argv[1], "rb").read(18)
557+# ELF magic, class 2 (64-bit), little endian, e_machine 183 = AArch64
558+ok = b[:4] == b"\x7fELF" and b[4] == 2 and b[5] == 1
559+ok = ok and int.from_bytes(b[16:18], "little") == 183
560+sys.exit(0 if ok else 1)
561+PY
562+ then pass "the arm artifact is a little-endian aarch64 ELF"
563+ else fail "the arm artifact is not an aarch64 ELF"; fi
553564 else fail "static aarch64 build"; fi
554565 else
555566 echo " skip aarch64-linux-gnu-gcc not installed"
556567 fi
557568
569+# _FORTIFY_SOURCE=2: a hardened build must still run, because dist packaging on
570+# some distros compiles with it defined by default.
571+if gcc -O2 -std=c99 -D_FORTIFY_SOURCE=2 -I src -o "$FIX/fortify-bin" src/plugin_opencode_login.c 2>/dev/null; then
572+ FORTMETA=$("$FIX/fortify-bin" --meta)
573+ check "a _FORTIFY_SOURCE=2 build runs --meta clean" '"name":"opencode"' "$FORTMETA"
574+ FORTSTAT=$(OPENCODE_CREDS_PATH="$FIX/full/auth.json" OPENCODE_PENDING_PATH="$FIX/pending/none.json" \
575+ OPENCODE_LOGIN_BIN="$ROOT/tests/mock_login.sh" \
576+ OPENCODE_TOKEN_BIN="$ROOT/tests/mock_token.sh" \
577+ OPENCODE_ENV_DIR="$FIX/env" \
578+ QUERY_STRING="action=status" "$FIX/fortify-bin" | tr -d '\r' | tail -1)
579+ check "a _FORTIFY_SOURCE=2 build serves status" '"logged_in":true' "$FORTSTAT"
580+ FORTSTART=$(OPENCODE_PENDING_PATH="$FIX/pending/none.json" \
581+ OPENCODE_LOGIN_BIN="$ROOT/tests/mock_login.sh" \
582+ OPENCODE_TOKEN_BIN="$ROOT/tests/mock_token.sh" \
583+ OPENCODE_ENV_DIR="$FIX/env" \
584+ QUERY_STRING="action=start" "$FIX/fortify-bin" | tr -d '\r' | tail -1)
585+ check "a _FORTIFY_SOURCE=2 build serves start" '"flow":"device_code"' "$FORTSTART"
586+ FORTBAD=$(OPENCODE_PENDING_PATH="$FIX/pending/none.json" \
587+ OPENCODE_LOGIN_BIN="$ROOT/tests/mock_login.sh" \
588+ OPENCODE_TOKEN_BIN="$ROOT/tests/mock_token.sh" \
589+ OPENCODE_ENV_DIR="$FIX/env" \
590+ QUERY_STRING="action=zzz" "$FIX/fortify-bin" | tr -d '\r' | head -1)
591+ check "a _FORTIFY_SOURCE=2 build rejects a bad action" "Status: 400" "$FORTBAD"
592+else
593+ fail "_FORTIFY_SOURCE=2 build"
594+fi
595+
558596 # ---------------------------------------------------------------- summary
559597 section "summary"
560598 printf ' %s%d passed, %d failed%s\n' "$C_B" "$PASS" "$FAIL" "$C_0"
561599
tests/run.sh+39−1■■■■■
index 2686f18..f239dc5 100755index 2686f18..f239dc5 100755
--- a/tests/run.sh--- a/tests/run.sh
+++ b/tests/run.sh+++ b/tests/run.sh
@@ -549,12 +549,50 @@ fi@@ -549,12 +549,50 @@ fi
549 if command -v aarch64-linux-gnu-gcc >/dev/null 2>&1; then549 if command -v aarch64-linux-gnu-gcc >/dev/null 2>&1; then
550 if aarch64-linux-gnu-gcc -O2 -std=c99 -static -I src -o "$FIX/arm-bin" src/plugin_opencode_login.c 2>/dev/null; then550 if aarch64-linux-gnu-gcc -O2 -std=c99 -static -I src -o "$FIX/arm-bin" src/plugin_opencode_login.c 2>/dev/null; then
551 pass "static aarch64 build"551 pass "static aarch64 build"
552- check "the arm binary reports the same metadata" '"name":"opencode"' "$("$FIX/arm-bin" --meta)"552+ # an aarch64 ELF cannot be exec'd on an x86_64 host, so the artifact is
553+ # verified by its header instead of by running it.
554+ if python3 - "$FIX/arm-bin" <<'PY'
555+import sys
556+b = open(sys.argv[1], "rb").read(18)
557+# ELF magic, class 2 (64-bit), little endian, e_machine 183 = AArch64
558+ok = b[:4] == b"\x7fELF" and b[4] == 2 and b[5] == 1
559+ok = ok and int.from_bytes(b[16:18], "little") == 183
560+sys.exit(0 if ok else 1)
561+PY
562+ then pass "the arm artifact is a little-endian aarch64 ELF"
563+ else fail "the arm artifact is not an aarch64 ELF"; fi
553 else fail "static aarch64 build"; fi564 else fail "static aarch64 build"; fi
554 else565 else
555 echo " skip aarch64-linux-gnu-gcc not installed"566 echo " skip aarch64-linux-gnu-gcc not installed"
556 fi567 fi
557 568
569+# _FORTIFY_SOURCE=2: a hardened build must still run, because dist packaging on
570+# some distros compiles with it defined by default.
571+if gcc -O2 -std=c99 -D_FORTIFY_SOURCE=2 -I src -o "$FIX/fortify-bin" src/plugin_opencode_login.c 2>/dev/null; then
572+ FORTMETA=$("$FIX/fortify-bin" --meta)
573+ check "a _FORTIFY_SOURCE=2 build runs --meta clean" '"name":"opencode"' "$FORTMETA"
574+ FORTSTAT=$(OPENCODE_CREDS_PATH="$FIX/full/auth.json" OPENCODE_PENDING_PATH="$FIX/pending/none.json" \
575+ OPENCODE_LOGIN_BIN="$ROOT/tests/mock_login.sh" \
576+ OPENCODE_TOKEN_BIN="$ROOT/tests/mock_token.sh" \
577+ OPENCODE_ENV_DIR="$FIX/env" \
578+ QUERY_STRING="action=status" "$FIX/fortify-bin" | tr -d '\r' | tail -1)
579+ check "a _FORTIFY_SOURCE=2 build serves status" '"logged_in":true' "$FORTSTAT"
580+ FORTSTART=$(OPENCODE_PENDING_PATH="$FIX/pending/none.json" \
581+ OPENCODE_LOGIN_BIN="$ROOT/tests/mock_login.sh" \
582+ OPENCODE_TOKEN_BIN="$ROOT/tests/mock_token.sh" \
583+ OPENCODE_ENV_DIR="$FIX/env" \
584+ QUERY_STRING="action=start" "$FIX/fortify-bin" | tr -d '\r' | tail -1)
585+ check "a _FORTIFY_SOURCE=2 build serves start" '"flow":"device_code"' "$FORTSTART"
586+ FORTBAD=$(OPENCODE_PENDING_PATH="$FIX/pending/none.json" \
587+ OPENCODE_LOGIN_BIN="$ROOT/tests/mock_login.sh" \
588+ OPENCODE_TOKEN_BIN="$ROOT/tests/mock_token.sh" \
589+ OPENCODE_ENV_DIR="$FIX/env" \
590+ QUERY_STRING="action=zzz" "$FIX/fortify-bin" | tr -d '\r' | head -1)
591+ check "a _FORTIFY_SOURCE=2 build rejects a bad action" "Status: 400" "$FORTBAD"
592+else
593+ fail "_FORTIFY_SOURCE=2 build"
594+fi
595+
558 # ---------------------------------------------------------------- summary596 # ---------------------------------------------------------------- summary
559 section "summary"597 section "summary"
560 printf ' %s%d passed, %d failed%s\n' "$C_B" "$PASS" "$FAIL" "$C_0"598 printf ' %s%d passed, %d failed%s\n' "$C_B" "$PASS" "$FAIL" "$C_0"
561599