Merge pull request #1513 from cypherstack/fix/linux-app-icons
What changed, and why it matters
This commit overhauls how Stack Wallet builds its Linux AppImage packages. The main security-relevant change is that the AppImage launcher scripts no longer force the bundled library directory onto the front of the system library search path. Previously, the AppRun script set LD_LIBRARY_PATH to the AppImage's own lib folder, which could have caused the wallet to load attacker-controlled libraries if a user ran it from a directory containing malicious libraries. The new scripts also pin and verify the AppImage runtime by its SHA-256 hash, validate the bundle is a real x86-64 binary, and add tests for these packaging checks. The rest of the changes are about fixing Linux desktop icons, adding metadata files, and making the build reproducible.
Review the new AppImage scripts for correctness, especially the runtime pin and the SHA-256 hash. Ensure CI continues to run the new regression tests on every Linux build. Users who rely on AppImageLauncher should note the documented requirement for version 3 beta or later. No immediate user action is required, but downstream packagers should verify the new build instructions.
Security signals we found
AppRun wrappers no longer prepend the bundled lib directory to LD_LIBRARY_PATH, reducing library search-order risk
New build_appimage.sh pins and SHA-256-verifies the AppImage Type 2 runtime before use
Bundle executable architecture is verified as x86-64 ELF via readelf
AppDir assembly rejects symbolic links for critical entries and validates PNG icon dimensions
GitHub Actions workflow gains explicit contents: read permission
Regression tests cover runtime hash mismatch, architecture mismatch, symlink output paths, and non-execution of untrusted AppImage during verification
Evidence from the diff
The commit replaces inline GitHub Actions AppImage construction with a set of reviewed shell scripts (build_appimage.sh, make_appdir.sh, assemble_appimage.sh, verify_appimage.sh, lib.sh). Security signals include: removal of LD_LIBRARY_PATH prefixing in AppRun wrappers, which eliminates a relative/library-search-order concern; introduction of a pinned, SHA-256-verified Type 2 AppImage runtime downloaded over HTTPS with enforced protocols; architecture verification of the bundle executable via readelf; validation that AppDir contents are regular files and not symlinks; and a regression test suite covering symlink/path-traversal attempts, runtime hash mismatch, architecture mismatch, and verification that the verifier does not execute untrusted input. The commit also fixes X11 window icon handling and updates Flatpak desktop/metainfo metadata. No CVE or vendor security advisory is present in the supplied materials.
Changed components
Linux AppImage packaging scriptsGitHub Actions build workflow for Linux AppImagesAppRun launchers for stack_wallet, stack_duo, and campfireFlatpak desktop and metainfo metadata filesFlutter Linux application template (my_application.cc) for window icon handlingLinux packaging regression testsInspect captured patch +1603 / −76
### .github/workflows/build.yaml
@@ -17,6 +17,9 @@ on:
required: true
default: '1'
+permissions:
+ contents: read
+
# Configure app uses -d for verified dnix prebuilts (Frost, Tor, Epic and MWC).
# Every app still builds dnssec_resolver with Rust 1.90.0; Stack Wallet also
# builds Xelis with Rust 1.99.1, and Stack Wallet/Campfire build Spark with C++.
@@ -685,22 +688,15 @@ jobs:
- name: Install AppImage tools
run: |
sudo apt-get update -q
- sudo apt-get install -y squashfs-tools
+ sudo apt-get install -y \
+ appstream binutils curl desktop-file-utils squashfs-tools
- name: Build AppImage
+ env:
+ VERSION: ${{ steps.ver.outputs.version }}
run: |
- VERSION="${{ steps.ver.outputs.version }}"
tar -xzf "stack_wallet-linux-x86_64-${VERSION}.tar.gz"
- mkdir -p AppDir
- cp -r bundle/* AppDir/
- cp appimage/stack_wallet/AppRun AppDir/AppRun
- chmod +x AppDir/AppRun
- cp appimage/stack_wallet/stack_wallet.desktop AppDir/
- cp asset_sources/icon/stack_wallet/icon.png AppDir/stack_wallet.png
- curl -fsSL -o appimagetool \
- https://github.com/AppImage/AppImageKit/releases/download/continuous/appimagetool-x86_64.AppImage
- chmod +x appimagetool
- ARCH=x86_64 ./appimagetool --appimage-extract-and-run AppDir \
+ appimage/build_appimage.sh stack_wallet bundle \
"stack_wallet-appimage-x86_64-${VERSION}.AppImage"
- uses: actions/upload-artifact@v7
@@ -1139,22 +1135,15 @@ jobs:
- name: Install AppImage tools
run: |
sudo apt-get update -q
- sudo apt-get install -y squashfs-tools
+ sudo apt-get install -y \
+ appstream binutils curl desktop-file-utils squashfs-tools
- name: Build AppImage
+ env:
+ VERSION: ${{ steps.ver.outputs.version }}
run: |
- VERSION="${{ steps.ver.outputs.version }}"
tar -xzf "campfire-linux-x86_64-${VERSION}.tar.gz"
- mkdir -p AppDir
- cp -r bundle/* AppDir/
- cp appimage/campfire/AppRun AppDir/AppRun
- chmod +x AppDir/AppRun
- cp appimage/campfire/campfire.desktop AppDir/
- cp asset_sources/icon/campfire/icon.png AppDir/campfire.png
- curl -fsSL -o appimagetool \
- https://github.com/AppImage/AppImageKit/releases/download/continuous/appimagetool-x86_64.AppImage
- chmod +x appimagetool
- ARCH=x86_64 ./appimagetool --appimage-extract-and-run AppDir \
+ appimage/build_appimage.sh campfire bundle \
"campfire-appimage-x86_64-${VERSION}.AppImage"
- uses: actions/upload-artifact@v7
@@ -1593,22 +1582,15 @@ jobs:
- name: Install AppImage tools
run: |
sudo apt-get update -q
- sudo apt-get install -y squashfs-tools
+ sudo apt-get install -y \
+ appstream binutils curl desktop-file-utils squashfs-tools
- name: Build AppImage
+ env:
+ VERSION: ${{ steps.ver.outputs.version }}
run: |
- VERSION="${{ steps.ver.outputs.version }}"
tar -xzf "stack_duo-linux-x86_64-${VERSION}.tar.gz"
- mkdir -p AppDir
- cp -r bundle/* AppDir/
- cp appimage/stack_duo/AppRun AppDir/AppRun
- chmod +x AppDir/AppRun
- cp appimage/stack_duo/stack_duo.desktop AppDir/
- cp asset_sources/icon/stack_duo/icon.png AppDir/stack_duo.png
- curl -fsSL -o appimagetool \
- https://github.com/AppImage/AppImageKit/releases/download/continuous/appimagetool-x86_64.AppImage
- chmod +x appimagetool
- ARCH=x86_64 ./appimagetool --appimage-extract-and-run AppDir \
+ appimage/build_appimage.sh stack_duo bundle \
"stack_duo-appimage-x86_64-${VERSION}.AppImage"
- uses: actions/upload-artifact@v7
### .github/workflows/test.yaml
@@ -11,19 +11,21 @@ jobs:
shell: powershell
run: powershell -NoProfile -ExecutionPolicy Bypass -File scripts/tests/prebuild_windows_test.ps1
- linux-release-bundle:
+ linux-release-packaging:
runs-on: ubuntu-24.04
permissions:
contents: read
steps:
- uses: actions/checkout@v6
- - name: Install ELF test tools
+ - name: Install Linux packaging test tools
run: |
sudo apt-get update -q
- sudo apt-get install -y --no-install-recommends binutils build-essential patchelf python3
+ sudo apt-get install -y --no-install-recommends \
+ appstream binutils build-essential desktop-file-utils patchelf \
+ python3 squashfs-tools
- - name: Test Linux release bundle preparation
+ - name: Test Linux release packaging
run: python3 -m unittest discover -s scripts/linux/tests -p 'test_*.py' -v
test:
### appimage/assemble_appimage.sh
@@ -0,0 +1,138 @@
+#!/usr/bin/env bash
+# Assemble a validated AppDir and Type 2 runtime into a gzip AppImage.
+# Usage: appimage/assemble_appimage.sh <AppDir> <runtime> <output.AppImage> <version>
+set -euo pipefail
+
+script_dir=$(CDPATH='' cd -- "$(dirname -- "$0")" && pwd)
+# shellcheck source=appimage/lib.sh
+source "$script_dir/lib.sh"
+
+if [ $# -ne 4 ]; then
+ echo "usage: $0 <AppDir> <runtime> <output.AppImage> <version>" >&2
+ exit 1
+fi
+
+appdir=$1
+runtime=$2
+output=$3
+version=$4
+source_date_epoch=${SOURCE_DATE_EPOCH:-0}
+
+if [ ! -d "$appdir" ] || [ -L "$appdir" ]; then
+ echo "AppDir must be a directory, not a symbolic link: $appdir" >&2
+ exit 1
+fi
+if [ ! -f "$runtime" ] || [ -L "$runtime" ]; then
+ echo "runtime must be a regular file, not a symbolic link: $runtime" >&2
+ exit 1
+fi
+case "$version" in
+ ''|*[!A-Za-z0-9._+-]*)
+ echo "version contains unsupported characters: $version" >&2
+ exit 1
+ ;;
+esac
+case "$source_date_epoch" in
+ ''|*[!0-9]*)
+ echo "SOURCE_DATE_EPOCH must be a non-negative integer: $source_date_epoch" >&2
+ exit 1
+ ;;
+esac
+
+require_tools appstreamcli basename chmod dd desktop-file-edit \
+ desktop-file-validate dirname mkdir mksquashfs mktemp mv readlink realpath \
+ rm wc
+
+shopt -s nullglob
+root_desktops=("$appdir"/*.desktop)
+installed_desktops=("$appdir"/usr/share/applications/*.desktop)
+metadata_files=("$appdir"/usr/share/metainfo/*.metainfo.xml)
+shopt -u nullglob
+if [ "${#root_desktops[@]}" -ne 1 ] ||
+ [ "${#installed_desktops[@]}" -ne 1 ] ||
+ [ "${#metadata_files[@]}" -ne 1 ]; then
+ echo "AppDir must contain exactly one root desktop entry, installed desktop entry, and metainfo file" >&2
+ exit 1
+fi
+if [ "${root_desktops[0]##*/}" != "${installed_desktops[0]##*/}" ]; then
+ echo "root and installed desktop entry names must match" >&2
+ exit 1
+fi
+desktop_files=("${root_desktops[0]}" "${installed_desktops[0]}")
+for file in "${desktop_files[@]}" "${metadata_files[@]}"; do
+ if [ ! -f "$file" ] || [ -L "$file" ]; then
+ echo "required packaging metadata not found or is a symbolic link: $file" >&2
+ exit 1
+ fi
+done
+
+if [ ! -f "$appdir/AppRun" ] || [ -L "$appdir/AppRun" ] ||
+ [ ! -x "$appdir/AppRun" ]; then
+ echo "AppDir must contain an executable, non-symbolic AppRun" >&2
+ exit 1
+fi
+
+icon_name=""
+for desktop in "${desktop_files[@]}"; do
+ desktop_icon=$(desktop_entry_value Icon "$desktop")
+ if [ -z "$desktop_icon" ] || [ "$desktop_icon" != "${desktop_icon##*/}" ]; then
+ echo "desktop entry must name a root icon: $desktop" >&2
+ exit 1
+ fi
+ if [ -n "$icon_name" ] && [ "$desktop_icon" != "$icon_name" ]; then
+ echo "root and installed desktop entries must name the same icon" >&2
+ exit 1
+ fi
+ icon_name=$desktop_icon
+done
+root_icon="$appdir/$icon_name.png"
+if [ ! -f "$root_icon" ] || [ -L "$root_icon" ]; then
+ echo "desktop entry icon not found: $root_icon" >&2
+ exit 1
+fi
+if [ ! -L "$appdir/.DirIcon" ] ||
+ [ "$(readlink -- "$appdir/.DirIcon")" != "$icon_name.png" ]; then
+ echo ".DirIcon must be a relative link to the desktop entry icon" >&2
+ exit 1
+fi
+
+canonical_appdir=$(CDPATH='' cd -- "$appdir" && pwd -P)
+output_dir=$(realpath -m -- "$(dirname -- "$output")")
+output="$output_dir/$(basename -- "$output")"
+case "$output" in
+ "$canonical_appdir"|"$canonical_appdir"/*)
+ echo "output must be outside the AppDir: $output" >&2
+ exit 1
+ ;;
+esac
+mkdir -p "$output_dir"
+output_dir=$(CDPATH='' cd -- "$output_dir" && pwd -P)
+output="$output_dir/$(basename -- "$output")"
+
+for desktop in "${desktop_files[@]}"; do
+ desktop-file-edit --set-key=X-AppImage-Version --set-value="$version" "$desktop"
+ # desktop-file-edit rewrites the file with the caller's umask.
+ chmod 0644 "$desktop"
+ desktop-file-validate "$desktop"
+done
+for metadata in "${metadata_files[@]}"; do
+ appstreamcli validate --no-net "$metadata"
+done
+
+workdir=$(mktemp -d "$output_dir/.appimage-assemble.XXXXXX")
+cleanup() {
+ rm -rf -- "$workdir"
+}
+trap cleanup EXIT
+image="$workdir/output.AppImage"
+runtime_size=$(wc -c < "$runtime")
+
+# Write the SquashFS directly at the runtime boundary so the large application
+# payload is not materialized as a second temporary file. mksquashfs truncates
+# the destination, so restore the small runtime prefix afterward.
+SOURCE_DATE_EPOCH="$source_date_epoch" \
+ mksquashfs "$appdir" "$image" -offset "$runtime_size" \
+ -all-root -noappend -no-xattrs -comp gzip >/dev/null
+dd if="$runtime" of="$image" conv=notrunc status=none
+chmod 0755 "$image"
+mv -fT -- "$image" "$output"
### appimage/build_appimage.sh
@@ -0,0 +1,127 @@
+#!/usr/bin/env bash
+# Build an x86_64 AppImage with a pinned, hash-verified Type 2 runtime.
+# Usage: VERSION=<version> appimage/build_appimage.sh <app> <bundle dir> <output.AppImage>
+
+script_dir=$(CDPATH='' cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)
+# shellcheck source=appimage/lib.sh
+source "$script_dir/lib.sh"
+
+verify_sha256() {
+ local file=$1
+ local expected=$2
+ local actual
+ actual=$(sha256sum "$file" | cut -d ' ' -f1)
+ if [ "$actual" != "$expected" ]; then
+ echo "SHA-256 mismatch for $file: expected $expected, got $actual" >&2
+ return 1
+ fi
+}
+
+download_verified() {
+ local url=$1
+ local expected=$2
+ local destination=$3
+ curl --fail --silent --show-error --location --retry 3 --retry-all-errors \
+ --connect-timeout 30 --max-time 300 \
+ --proto '=https' --proto-redir '=https' \
+ --output "$destination" "$url"
+ verify_sha256 "$destination" "$expected"
+}
+
+verify_x86_64_bundle() {
+ local executable=$1
+ local header
+ local machine
+ if [ ! -e "$executable" ]; then
+ echo "bundle executable not found: $executable" >&2
+ return 1
+ fi
+ if ! header=$(LC_ALL=C readelf --wide --file-header -- "$executable" 2>/dev/null); then
+ echo "bundle executable must be an x86-64 ELF: $executable (machine: unknown)" >&2
+ return 1
+ fi
+ machine=$(sed -n 's/^[[:space:]]*Machine:[[:space:]]*//p' <<< "$header")
+ if [ "$machine" != "Advanced Micro Devices X86-64" ]; then
+ echo "bundle executable must be an x86-64 ELF: $executable (machine: ${machine:-unknown})" >&2
+ return 1
+ fi
+}
+
+cleanup() {
+ if [ -n "${APPIMAGE_STAGED_OUTPUT:-}" ]; then
+ rm -f -- "$APPIMAGE_STAGED_OUTPUT"
+ fi
+ if [ -n "${APPIMAGE_WORKDIR:-}" ] && [ -d "$APPIMAGE_WORKDIR" ]; then
+ rm -rf -- "$APPIMAGE_WORKDIR"
+ fi
+}
+
+main() {
+ set -euo pipefail
+
+ if [ $# -ne 3 ]; then
+ echo "usage: VERSION=<version> $0 <app> <bundle dir> <output.AppImage>" >&2
+ return 1
+ fi
+ if [ -z "${VERSION:-}" ]; then
+ echo "VERSION must be set" >&2
+ return 1
+ fi
+ case "$VERSION" in
+ *[!A-Za-z0-9._+-]*)
+ echo "VERSION contains unsupported characters: $VERSION" >&2
+ return 1
+ ;;
+ esac
+
+ local app=$1
+ local bundle=$2
+ local output=$3
+ local root
+ root=$(CDPATH='' cd -- "$script_dir/.." && pwd)
+ # Keep the executable runtime and its trust root together in reviewed source.
+ # Environment variables must not be able to replace either half of this pin.
+ # Use the modern static runtime so current distributions do not need the
+ # obsolete libfuse2 package. AppImageLauncher 2.2 cannot start static
+ # runtimes; integrated launch requires the AppImageLauncher 3 beta or later.
+ # Verification depends on this runtime retaining TARGET_APPIMAGE support for
+ # --appimage-offset and --appimage-extract; preserve that when updating it.
+ local runtime_url="https://github.com/AppImage/type2-runtime/releases/download/20251108/runtime-x86_64"
+ local runtime_sha256="2fca8b443c92510f1483a883f60061ad09b46b978b2631c807cd873a47ec260d"
+
+ require_tools appstreamcli basename chmod cmp curl cut desktop-file-edit \
+ desktop-file-validate dirname mkdir mksquashfs mktemp mv readelf realpath \
+ rm sed sha256sum unsquashfs
+
+ local output_dir
+ output_dir=$(dirname -- "$output")
+ mkdir -p "$output_dir"
+ output_dir=$(CDPATH='' cd -- "$output_dir" && pwd)
+ output="$output_dir/$(basename -- "$output")"
+
+ APPIMAGE_WORKDIR=""
+ APPIMAGE_STAGED_OUTPUT=""
+ trap cleanup EXIT
+ APPIMAGE_WORKDIR=$(mktemp -d "$output_dir/.appimage-work.XXXXXX")
+ APPIMAGE_STAGED_OUTPUT=$(mktemp "$output_dir/.appimage-unverified.XXXXXX")
+
+ local runtime="$APPIMAGE_WORKDIR/runtime-x86_64"
+ local appdir="$APPIMAGE_WORKDIR/AppDir"
+
+ # Verify external tooling before copying the potentially large application
+ # bundle, so supply-chain or network failures fail early.
+ download_verified "$runtime_url" "$runtime_sha256" "$runtime"
+ chmod 0755 "$runtime"
+ verify_x86_64_bundle "$bundle/$app"
+
+ "$root/appimage/make_appdir.sh" "$app" "$bundle" "$appdir"
+ "$root/appimage/assemble_appimage.sh" \
+ "$appdir" "$runtime" "$APPIMAGE_STAGED_OUTPUT" "$VERSION"
+ "$root/appimage/verify_appimage.sh" "$APPIMAGE_STAGED_OUTPUT" "$runtime"
+ mv -fT -- "$APPIMAGE_STAGED_OUTPUT" "$output"
+ APPIMAGE_STAGED_OUTPUT=""
+}
+
+if [[ "${BASH_SOURCE[0]}" == "$0" ]]; then
+ main "$@"
+fi
### appimage/campfire/AppRun
@@ -1,5 +1,4 @@
#!/bin/bash
SELF=$(readlink -f "$0")
HERE=${SELF%/*}
-export LD_LIBRARY_PATH="${HERE}/lib:${LD_LIBRARY_PATH}"
exec "${HERE}/campfire" "$@"
### appimage/campfire/campfire.desktop
@@ -1,7 +0,0 @@
-[Desktop Entry]
-Name=Campfire
-Comment=Your privacy. Your wallet. Your Firo.
-Exec=campfire
-Icon=campfire
-Type=Application
-Categories=Finance;
### appimage/lib.sh
@@ -0,0 +1,26 @@
+#!/usr/bin/env bash
+
+# Print the first value for a key in the main Desktop Entry group.
+desktop_entry_value() {
+ local key=$1
+ local file=$2
+ awk -v key="$key" '
+ /^\[Desktop Entry\]$/ { in_entry = 1; next }
+ /^\[/ { in_entry = 0 }
+ in_entry && index($0, key "=") == 1 {
+ sub("^" key "=", "")
+ print
+ exit
+ }
+ ' "$file"
+}
+
+require_tools() {
+ local tool
+ for tool in "$@"; do
+ if ! command -v "$tool" >/dev/null 2>&1; then
+ echo "required tool not found: $tool" >&2
+ return 1
+ fi
+ done
+}
### appimage/make_appdir.sh
@@ -0,0 +1,122 @@
+#!/usr/bin/env bash
+# Assemble an AppDir from a built Linux bundle.
+# Usage: appimage/make_appdir.sh <stack_wallet|stack_duo|campfire> <bundle dir> <AppDir>
+set -euo pipefail
+
+if [ $# -ne 3 ]; then
+ echo "usage: $0 <stack_wallet|stack_duo|campfire> <bundle dir> <AppDir>" >&2
+ exit 1
+fi
+
+app=$1
+bundle=$2
+appdir=$3
+
+script_dir=$(CDPATH='' cd -- "$(dirname -- "$0")" && pwd)
+# shellcheck source=appimage/lib.sh
+source "$script_dir/lib.sh"
+require_tools awk cp find install ln mkdir od stat tr
+root=$(CDPATH='' cd -- "$script_dir/.." && pwd)
+desktop=""
+for candidate in "$root"/flatpak/*.desktop; do
+ exec_line=$(desktop_entry_value Exec "$candidate")
+ exec_command=${exec_line%%[[:space:]]*}
+ if [ "$exec_command" = "$app" ]; then
+ if [ -n "$desktop" ]; then
+ echo "multiple desktop entries found for app: $app" >&2
+ exit 1
+ fi
+ desktop=$candidate
+ fi
+done
+if [ -z "$desktop" ]; then
+ echo "unknown app: $app" >&2
+ exit 1
+fi
+id=${desktop##*/}
+id=${id%.desktop}
+metainfo="$root/flatpak/$id.metainfo.xml"
+icon="$root/asset_sources/icon/$app/icon.png"
+
+if [ ! -d "$bundle" ]; then
+ echo "bundle directory not found: $bundle" >&2
+ exit 1
+fi
+if [ ! -e "$bundle/$app" ]; then
+ echo "bundle executable not found: $bundle/$app" >&2
+ exit 1
+fi
+if [ ! -f "$bundle/$app" ] || [ -L "$bundle/$app" ] ||
+ [ ! -x "$bundle/$app" ]; then
+ echo "bundle executable must be an executable regular file, not a symbolic link: $bundle/$app" >&2
+ exit 1
+fi
+for reserved in usr AppRun .DirIcon "$id.desktop" "$id.png"; do
+ if [ -e "$bundle/$reserved" ] || [ -L "$bundle/$reserved" ]; then
+ echo "bundle contains reserved packaging path: $bundle/$reserved" >&2
+ exit 1
+ fi
+done
+extra_desktop=$(find "$bundle" -mindepth 1 -maxdepth 1 -name '*.desktop' \
+ -print -quit)
+if [ -n "$extra_desktop" ]; then
+ echo "bundle contains reserved packaging path: $extra_desktop" >&2
+ exit 1
+fi
+if [ -L "$appdir" ]; then
+ echo "AppDir must not be a symbolic link: $appdir" >&2
+ exit 1
+fi
+if [ -e "$appdir" ]; then
+ if [ ! -d "$appdir" ]; then
+ echo "AppDir is not a directory: $appdir" >&2
+ exit 1
+ fi
+ if [ -n "$(find "$appdir" -mindepth 1 -maxdepth 1 -print -quit)" ]; then
+ echo "AppDir is not empty: $appdir" >&2
+ exit 1
+ fi
+fi
+
+# The hicolor directory must agree with the actual source icon. Validate the
+# PNG signature before reading its big-endian IHDR width and height.
+if [ ! -f "$icon" ] || [ ! -r "$icon" ]; then
+ echo "icon is not a readable regular file: $icon" >&2
+ exit 1
+fi
+signature=$(od -An -N8 -tx1 "$icon" 2>/dev/null | tr -d ' \n')
+width_hex=$(od -An -j16 -N4 -tx1 "$icon" 2>/dev/null | tr -d ' \n')
+height_hex=$(od -An -j20 -N4 -tx1 "$icon" 2>/dev/null | tr -d ' \n')
+if [ "$signature" != "89504e470d0a1a0a" ] ||
+ [ "${#width_hex}" -ne 8 ] || [ "${#height_hex}" -ne 8 ]; then
+ echo "$icon is invalid, expected a 512x512 PNG" >&2
+ exit 1
+fi
+width=$((16#$width_hex))
+height=$((16#$height_hex))
+if [ "$width" -ne 512 ] || [ "$height" -ne 512 ]; then
+ echo "$icon is ${width}x${height}, expected a 512x512 PNG" >&2
+ exit 1
+fi
+
+mkdir -p "$appdir"
+if [ "$(stat -c %d -- "$bundle")" = "$(stat -c %d -- "$appdir")" ]; then
+ cp -al "$bundle"/. "$appdir"/
+else
+ cp -a --reflink=auto "$bundle"/. "$appdir"/
+fi
+install -m755 "$root/appimage/$app/AppRun" "$appdir/AppRun"
+install -m644 "$desktop" "$appdir/$id.desktop"
+
+# The AppImage runtime uses the root icon, while file managers and integrators
+# such as Gear Lever and AppImageLauncher read .DirIcon.
+install -m644 "$icon" "$appdir/$id.png"
+ln -sfn "$id.png" "$appdir/.DirIcon"
+
+# Standard AppDir locations, also read by integrators.
+install -Dm644 "$icon" \
+ "$appdir/usr/share/icons/hicolor/${width}x${width}/apps/$id.png"
+install -Dm644 "$desktop" \
+ "$appdir/usr/share/applications/$id.desktop"
+install -Dm644 "$metainfo" \
+ "$appdir/usr/share/metainfo/$id.metainfo.xml"
### appimage/stack_duo/AppRun
@@ -1,5 +1,4 @@
#!/bin/bash
SELF=$(readlink -f "$0")
HERE=${SELF%/*}
-export LD_LIBRARY_PATH="${HERE}/lib:${LD_LIBRARY_PATH}"
exec "${HERE}/stack_duo" "$@"
### appimage/stack_duo/stack_duo.desktop
@@ -1,7 +0,0 @@
-[Desktop Entry]
-Name=Stack Duo
-Comment=An open-source, multicoin wallet for everyone
-Exec=stack_duo
-Icon=stack_duo
-Type=Application
-Categories=Finance;
### appimage/stack_wallet/AppRun
@@ -1,5 +1,4 @@
#!/bin/bash
SELF=$(readlink -f "$0")
HERE=${SELF%/*}
-export LD_LIBRARY_PATH="${HERE}/lib:${LD_LIBRARY_PATH}"
exec "${HERE}/stack_wallet" "$@"
### appimage/stack_wallet/stack_wallet.desktop
@@ -1,7 +0,0 @@
-[Desktop Entry]
-Name=Stack Wallet
-Comment=Open-source non-custodial cryptocurrency wallet
-Exec=stack_wallet
-Icon=stack_wallet
-Type=Application
-Categories=Finance;
### appimage/verify_appimage.sh
@@ -0,0 +1,76 @@
+#!/usr/bin/env bash
+# Verify the runtime boundary and the executable entry point of an AppImage.
+# Usage: appimage/verify_appimage.sh <image.AppImage> <runtime>
+set -euo pipefail
+
+script_dir=$(CDPATH='' cd -- "$(dirname -- "$0")" && pwd)
+# shellcheck source=appimage/lib.sh
+source "$script_dir/lib.sh"
+
+if [ $# -ne 2 ]; then
+ echo "usage: $0 <image.AppImage> <runtime>" >&2
+ exit 1
+fi
+
+require_tools cmp dirname mkdir mktemp realpath rm unsquashfs wc
+
+image=$1
+runtime=$2
+if [ ! -f "$image" ] || [ ! -x "$image" ]; then
+ echo "AppImage must be an executable regular file: $image" >&2
+ exit 1
+fi
+if [ ! -f "$runtime" ] || [ -L "$runtime" ]; then
+ echo "runtime must be a regular file, not a symbolic link: $runtime" >&2
+ exit 1
+fi
+image=$(realpath -e -- "$image")
+runtime=$(realpath -e -- "$runtime")
+expected_offset=$(wc -c < "$runtime")
+
+if ! cmp --silent --bytes="$expected_offset" "$runtime" "$image"; then
+ echo "AppImage runtime prefix does not match the verified runtime" >&2
+ exit 1
+fi
+
+workdir=$(mktemp -d "${TMPDIR:-/tmp}/appimage-verify.XXXXXX")
+cleanup() {
+ rm -rf -- "$workdir"
+}
+trap cleanup EXIT
+(
+ cd "$workdir"
+ unsquashfs -s -o "$expected_offset" "$image" >/dev/null
+ unsquashfs -q -no-progress -o "$expected_offset" \
+ -d squashfs-root "$image" AppRun
+)
+if [ -L "$workdir/squashfs-root/AppRun" ] ||
+ [ ! -f "$workdir/squashfs-root/AppRun" ] ||
+ [ ! -x "$workdir/squashfs-root/AppRun" ]; then
+ echo "AppImage does not contain an executable, non-symbolic AppRun" >&2
+ exit 1
+fi
+
+# Exercise the hash-verified runtime itself without executing bytes from the
+# image. TARGET_APPIMAGE makes the trusted runtime inspect the candidate.
+if [ ! -x "$runtime" ]; then
+ echo "runtime must be executable: $runtime" >&2
+ exit 1
+fi
+actual_offset=$(TARGET_APPIMAGE="$image" "$runtime" --appimage-offset)
+if [ "$actual_offset" != "$expected_offset" ]; then
+ echo "AppImage runtime offset is $actual_offset, expected $expected_offset" >&2
+ exit 1
+fi
+runtime_extract="$workdir/runtime-extract"
+mkdir "$runtime_extract"
+(
+ cd "$runtime_extract"
+ TARGET_APPIMAGE="$image" "$runtime" --appimage-extract AppRun >/dev/null
+)
+if [ -L "$runtime_extract/squashfs-root/AppRun" ] ||
+ [ ! -f "$runtime_extract/squashfs-root/AppRun" ] ||
+ [ ! -x "$runtime_extract/squashfs-root/AppRun" ]; then
+ echo "AppImage runtime did not extract an executable, non-symbolic AppRun" >&2
+ exit 1
+fi
### docs/building/linux.md
@@ -110,7 +110,40 @@ then checks every ELF in the bundle and fails if any still requests an
executable stack. Other libraries are not patched automatically. CI runs this
before producing the Linux tarball, so downstream packagers get the prepared
bundle. Its regression tests are described in
-[Testing the build setup](testing.md#linux-release-bundle-tests).
+[Testing the build setup](testing.md#linux-release-packaging-tests).
+
+## Build an AppImage
+
+Install the AppImage assembly and metadata validation tools, then package the
+prepared release bundle:
+
+```sh
+sudo apt-get install appstream binutils curl desktop-file-utils squashfs-tools
+export VERSION=1.2.3
+appimage/build_appimage.sh stack_wallet \
+ build/linux/x64/release/bundle stack_wallet.AppImage
+```
+
+The builder deliberately uses a pinned, checksum-verified static Type 2 runtime
+so the resulting gzip-compressed AppImage runs on current Linux distributions
+without the obsolete `libfuse2` package. The tradeoff is that AppImageLauncher
+2.2 cannot launch static-runtime AppImages. Desktop integration requires the
+AppImageLauncher 3 beta (currently 3.0.0-beta-3) or a later compatible release.
+On systems where FUSE mounting is unavailable, run the AppImage directly with
+`APPIMAGE_EXTRACT_AND_RUN=1`. Replace `stack_wallet` with `stack_duo` or
+`campfire` for the other applications.
+
+### Linux icon behavior
+
+On X11, the application sets one 256 px window icon: the icon the installed
+icon theme has for the application ID, or the Flutter asset when the theme has
+none. It never passes a larger image, because GTK drops a 512 px icon, and
+every icon listed after it, from the X11 window property. On Wayland, GTK 3
+applications cannot set their own window icon; the desktop shell resolves it
+through the matching installed `.desktop` entry instead. Consequently, an
+unpacked tarball or an AppImage launched without desktop integration may show a
+generic Wayland icon. Installing or integrating the desktop entry supplies the
+application icon.
## Troubleshooting
### docs/building/testing.md
@@ -19,11 +19,19 @@ secp256k1 build helper. A small Windows CI job runs the PowerShell prebuild
regression tests. Actual native Windows-to-WSL builds are tested in dnix's CI;
these app tests don't run WSL.
-## Linux release bundle tests
+## Linux release packaging tests
-These are standalone regression tests for the
-[release bundle helper](linux.md#prepare-a-release-bundle). They also need a C
-compiler:
+These standalone regression tests cover the
+[release bundle helper](linux.md#prepare-a-release-bundle) and AppImage
+assembly, including metadata, checksum failures and gzip compression. Install
+their native tools first:
+
+```sh
+sudo apt-get install appstream binutils build-essential desktop-file-utils \
+ patchelf python3 squashfs-tools
+```
+
+Then run:
```sh
python3 -m unittest discover -s scripts/linux/tests -p 'test_*.py' -v
### flatpak/com.cypherstack.campfire.desktop
@@ -3,5 +3,6 @@ Name=Campfire
Comment=Your privacy. Your wallet. Your Firo.
Exec=campfire
Icon=com.cypherstack.campfire
+StartupWMClass=com.cypherstack.campfire
Type=Application
-Categories=Finance;
+Categories=Office;Finance;
### flatpak/com.cypherstack.campfire.metainfo.xml
@@ -10,7 +10,8 @@
Campfire is an open-source, non-custodial Firo wallet.
</p>
</description>
- <url type="homepage">https://campfireprivacy.com</url>
+ <url type="homepage">https://github.com/firoorg/campfire</url>
<url type="bugtracker">https://github.com/cypherstack/stack_wallet/issues</url>
+ <launchable type="desktop-id">com.cypherstack.campfire.desktop</launchable>
<content_rating type="oars-1.1"/>
</component>
### flatpak/com.cypherstack.stackduo.desktop
@@ -3,5 +3,6 @@ Name=Stack Duo
Comment=An open-source, multicoin wallet for everyone
Exec=stack_duo
Icon=com.cypherstack.stackduo
+StartupWMClass=com.cypherstack.stackduo
Type=Application
-Categories=Finance;
+Categories=Office;Finance;
### flatpak/com.cypherstack.stackduo.metainfo.xml
@@ -12,5 +12,6 @@
</description>
<url type="homepage">https://stackwallet.com</url>
<url type="bugtracker">https://github.com/cypherstack/stack_wallet/issues</url>
+ <launchable type="desktop-id">com.cypherstack.stackduo.desktop</launchable>
<content_rating type="oars-1.1"/>
</component>
### flatpak/com.cypherstack.stackwallet.desktop
@@ -3,5 +3,6 @@ Name=Stack Wallet
Comment=Open-source non-custodial cryptocurrency wallet
Exec=stack_wallet
Icon=com.cypherstack.stackwallet
+StartupWMClass=com.cypherstack.stackwallet
Type=Application
-Categories=Finance;
+Categories=Office;Finance;
### flatpak/com.cypherstack.stackwallet.metainfo.xml
@@ -13,5 +13,6 @@
</description>
<url type="homepage">https://stackwallet.com</url>
<url type="bugtracker">https://github.com/cypherstack/stack_wallet/issues</url>
+ <launchable type="desktop-id">com.cypherstack.stackwallet.desktop</launchable>
<content_rating type="oars-1.1"/>
</component>
### scripts/app_config/templates/linux/my_application.cc
@@ -1,6 +1,9 @@
#include "my_application.h"
#include <flutter_linux/flutter_linux.h>
+#ifdef GDK_WINDOWING_X11
+#include <gdk/gdkx.h>
+#endif
#include "flutter/generated_plugin_registrant.h"
@@ -17,6 +20,45 @@ static void first_frame_cb(MyApplication* self, FlView *view)
gtk_widget_show(gtk_widget_get_toplevel(GTK_WIDGET(view)));
}
+// X11 window icon. GDK publishes icons in list order and stops at the first one
+// that does not fit in the 262144-word window property, so a 512 px icon is
+// dropped along with every icon after it, and gtk_window_set_icon_name() can
+// leave the window with no icon at all when the theme has a 512 px icon. Set
+// one 256 px image instead: the themed icon when the theme has one for
+// APPLICATION_ID, otherwise the icon in the Flutter assets. Wayland ignores
+// window icons and uses the .desktop file matching APPLICATION_ID.
+static void set_window_icon(GtkWindow* window, FlDartProject* project) {
+#ifdef GDK_WINDOWING_X11
+ const gint icon_size = 256;
+ GdkDisplay* display = gtk_widget_get_display(GTK_WIDGET(window));
+ if (!GDK_IS_X11_DISPLAY(display)) {
+ return;
+ }
+
+ GtkIconTheme* theme =
+ gtk_icon_theme_get_for_screen(gtk_window_get_screen(window));
+ g_autoptr(GdkPixbuf) icon = gtk_icon_theme_load_icon(
+ theme, APPLICATION_ID, icon_size, GTK_ICON_LOOKUP_FORCE_SIZE, nullptr);
+ if (icon == nullptr) {
+ g_autofree gchar* path =
+ g_build_filename(fl_dart_project_get_assets_path(project), "assets",
+ "icon", "icon.png", nullptr);
+ g_autoptr(GError) error = nullptr;
+ icon = gdk_pixbuf_new_from_file_at_scale(path, icon_size, icon_size, TRUE,
+ &error);
+ if (icon == nullptr) {
+ g_warning("No window icon: %s",
+ error != nullptr ? error->message : "unknown image error");
+ return;
+ }
+ }
+ gtk_window_set_icon(window, icon);
+#else
+ (void)window;
+ (void)project;
+#endif
+}
+
// Implements GApplication::activate.
static void my_application_activate(GApplication* application) {
MyApplication* self = MY_APPLICATION(application);
@@ -37,12 +79,13 @@ static void my_application_activate(GApplication* application) {
gtk_window_set_title(window, "PlaceHolderName");
}
- gtk_window_set_default_size(window, 1220, 500);
- gtk_widget_show(GTK_WIDGET(window));
-
g_autoptr(FlDartProject) project = fl_dart_project_new();
fl_dart_project_set_dart_entrypoint_arguments(project, self->dart_entrypoint_arguments);
+ set_window_icon(window, project);
+ gtk_window_set_default_size(window, 1220, 500);
+ gtk_widget_show(GTK_WIDGET(window));
+
FlView* view = fl_view_new(project);
GdkRGBA background_color;
// Background defaults to black, override it here if necessary, e.g. #00000000 for transparent.
### scripts/linux/tests/test_appimage.py
@@ -0,0 +1,988 @@
+"""Offline regression tests for AppImage layout and pinned release tooling."""
+
+import configparser
+import hashlib
+import os
+from pathlib import Path
+import re
+import shutil
+import subprocess
+import tempfile
+import time
+import unittest
+
+
+ROOT = Path(__file__).resolve().parents[3]
+MAKE_APPDIR = ROOT / "appimage" / "make_appdir.sh"
+BUILD_APPIMAGE = ROOT / "appimage" / "build_appimage.sh"
+ASSEMBLE_APPIMAGE = ROOT / "appimage" / "assemble_appimage.sh"
+VERIFY_APPIMAGE = ROOT / "appimage" / "verify_appimage.sh"
+FLATPAK = ROOT / "flatpak"
+BUILD_WORKFLOW = ROOT / ".github/workflows/build.yaml"
+
+
+def read_desktop(path):
+ parser = configparser.ConfigParser(interpolation=None)
+ parser.optionxform = str
+ with path.open() as desktop_file:
+ parser.read_file(desktop_file)
+ return parser["Desktop Entry"]
+
+
+CONFIGURE_SCRIPTS = {
+ "campfire": ROOT / "scripts/app_config/configure_campfire.sh",
+ "stack_duo": ROOT / "scripts/app_config/configure_stack_duo.sh",
+ "stack_wallet": ROOT / "scripts/app_config/configure_stack_wallet.sh",
+}
+
+
+def configured_app_id(path):
+ match = re.search(r'^\s*export NEW_APP_ID="([^"]+)"', path.read_text(), re.M)
+ if match is None:
+ raise AssertionError(f"NEW_APP_ID not found in {path}")
+ return match.group(1)
+
+
+APP_IDS = {app: configured_app_id(path) for app, path in CONFIGURE_SCRIPTS.items()}
+
+
+# Tools each script checks for with require_tools, beyond coreutils. The
+# builder's curl is replaced by a fake in these tests.
+ASSEMBLE_TOOLS = (
+ "appstreamcli",
+ "desktop-file-edit",
+ "desktop-file-validate",
+ "mksquashfs",
+ "realpath",
+)
+VERIFY_TOOLS = ("cmp", "realpath", "unsquashfs")
+BUILD_TOOLS = (*ASSEMBLE_TOOLS, *VERIFY_TOOLS, "readelf", "sha256sum")
+
+
+def requires_tools(*tools):
+ missing = [tool for tool in tools if shutil.which(tool) is None]
+ return unittest.skipIf(bool(missing), f"required tools not found: {', '.join(missing)}")
+
+
+class AppImageScriptsTest(unittest.TestCase):
+ def setUp(self):
+ self.temp = tempfile.TemporaryDirectory(prefix="appimage-test-")
+ self.addCleanup(self.temp.cleanup)
+ self.temp_path = Path(self.temp.name)
+ self.bundle = self.temp_path / "bundle"
+ self.bundle.mkdir()
+ (self.bundle / "bundle-marker").write_text("copied\n")
+ for app in APP_IDS:
+ executable = self.bundle / app
+ executable.write_text("#!/bin/sh\nprintf '%s\\n' \"$LD_LIBRARY_PATH\"\n")
+ executable.chmod(0o755)
+
+ def run_make_appdir(self, app="stack_wallet", appdir=None, script=MAKE_APPDIR):
+ if appdir is None:
+ appdir = self.temp_path / "AppDir"
+ return subprocess.run(
+ [str(script), app, str(self.bundle), str(appdir)],
+ capture_output=True,
+ text=True,
+ )
+
+ def make_test_packaging_root(self, name, icon_bytes):
+ root = self.temp_path / f"packaging-root-{name.replace(' ', '-')}"
+ shutil.copytree(ROOT / "appimage", root / "appimage")
+ shutil.copytree(ROOT / "flatpak", root / "flatpak")
+ icon = root / "asset_sources/icon/stack_wallet/icon.png"
+ icon.parent.mkdir(parents=True)
+ icon.write_bytes(icon_bytes)
+ return root
+
+ def make_fake_curl(self, runtime):
+ fake_bin = self.temp_path / "fake-bin"
+ fake_bin.mkdir(exist_ok=True)
+ runtime_fixture = self.temp_path / "runtime-fixture"
+ runtime_fixture.write_bytes(runtime)
+ curl_log = self.temp_path / "curl-arguments"
+ curl = fake_bin / "curl"
+ curl.write_text(
+ "#!/bin/sh\n"
+ "set -eu\n"
+ "printf '%s\\n' \"$@\" > \"$APPIMAGE_TEST_CURL_LOG\"\n"
+ "output=\n"
+ "retry_all_errors=false\n"
+ "while [ \"$#\" -gt 0 ]; do\n"
+ " case \"$1\" in\n"
+ " --output) output=$2; shift 2 ;;\n"
+ " --retry-all-errors) retry_all_errors=true; shift ;;\n"
+ " *) shift ;;\n"
+ " esac\n"
+ "done\n"
+ "[ \"$retry_all_errors\" = true ]\n"
+ "cp \"$APPIMAGE_TEST_RUNTIME\" \"$output\"\n"
+ )
+ curl.chmod(0o755)
+ return fake_bin, runtime_fixture, curl_log
+
+ def make_elf_executable(self, path, machine=62):
+ header = bytearray(64)
+ header[:4] = b"\x7fELF"
+ header[4:7] = bytes((2, 1, 1))
+ header[16:18] = (2).to_bytes(2, "little")
+ header[18:20] = machine.to_bytes(2, "little")
+ header[20:24] = (1).to_bytes(4, "little")
+ header[52:54] = (64).to_bytes(2, "little")
+ path.write_bytes(header)
+ path.chmod(0o755)
+
+ def run_build_appimage(self, runtime, output=None):
+ fake_bin, runtime_fixture, curl_log = self.make_fake_curl(runtime)
+ if output is None:
+ output = self.temp_path / "test.AppImage"
+ result = subprocess.run(
+ [str(BUILD_APPIMAGE), "stack_wallet", str(self.bundle), str(output)],
+ capture_output=True,
+ text=True,
+ env={
+ **os.environ,
+ "PATH": f"{fake_bin}:{os.environ['PATH']}",
+ "VERSION": "1.2.3-test",
+ "APPIMAGE_RUNTIME_URL": "https://attacker.invalid/runtime",
+ "APPIMAGE_RUNTIME_SHA256": hashlib.sha256(runtime).hexdigest(),
+ "APPIMAGE_TEST_RUNTIME": str(runtime_fixture),
+ "APPIMAGE_TEST_CURL_LOG": str(curl_log),
+ },
+ )
+ return result, output, curl_log
+
+ def test_apprun_does_not_override_the_process_library_path(self):
+ for app in APP_IDS:
+ with self.subTest(app=app):
+ appdir = self.temp_path / f"{app}-AppDir"
+ subprocess.run(
+ [str(MAKE_APPDIR), app, str(self.bundle), str(appdir)],
+ check=True,
+ capture_output=True,
+ text=True,
+ )
+
+ unset = subprocess.run(
+ [str(appdir / "AppRun")],
+ check=True,
+ capture_output=True,
+ text=True,
+ env={},
+ )
+ self.assertEqual(unset.stdout.strip(), "")
+
+ existing = subprocess.run(
+ [str(appdir / "AppRun")],
+ check=True,
+ capture_output=True,
+ text=True,
+ env={"LD_LIBRARY_PATH": "/trusted/lib"},
+ )
+ self.assertEqual(existing.stdout.strip(), "/trusted/lib")
+
+ def test_appdir_layout_for_all_apps(self):
+ for app, app_id in APP_IDS.items():
+ with self.subTest(app=app):
+ appdir = self.temp_path / f"{app} AppDir"
+ subprocess.run(
+ [str(MAKE_APPDIR), app, str(self.bundle), str(appdir)],
+ check=True,
+ capture_output=True,
+ text=True,
+ )
+ self.assertTrue((appdir / "AppRun").stat().st_mode & 0o111)
+ self.assertTrue((appdir / "bundle-marker").is_file())
+ self.assertEqual(
+ (appdir / "bundle-marker").stat().st_ino,
+ (self.bundle / "bundle-marker").stat().st_ino,
+ )
+ self.assertTrue((appdir / f"{app_id}.desktop").is_file())
+ self.assertTrue((appdir / f"{app_id}.png").is_file())
+ self.assertEqual((appdir / ".DirIcon").readlink(), Path(f"{app_id}.png"))
+ self.assertTrue(
+ (appdir / "usr/share/applications" / f"{app_id}.desktop").is_file()
+ )
+ self.assertTrue(
+ (
+ appdir
+ / "usr/share/icons/hicolor/512x512/apps"
+ / f"{app_id}.png"
+ ).is_file()
+ )
+ canonical_desktop = FLATPAK / f"{app_id}.desktop"
+ self.assertEqual(
+ (appdir / f"{app_id}.desktop").read_bytes(),
+ canonical_desktop.read_bytes(),
+ )
+ self.assertEqual(
+ (
+ appdir / "usr/share/applications" / f"{app_id}.desktop"
+ ).read_bytes(),
+ canonical_desktop.read_bytes(),
+ )
+ self.assertEqual(
+ (
+ appdir / "usr/share/metainfo" / f"{app_id}.metainfo.xml"
+ ).read_bytes(),
+ (FLATPAK / f"{app_id}.metainfo.xml").read_bytes(),
+ )
+
+ def test_desktop_metadata_matches_the_application_id(self):
+ for app, app_id in APP_IDS.items():
+ with self.subTest(app=app):
+ desktop = read_desktop(FLATPAK / f"{app_id}.desktop")
+ self.assertEqual(desktop["Exec"], app)
+ self.assertEqual(desktop["Icon"], app_id)
+ self.assertEqual(desktop["StartupWMClass"], app_id)
+ self.assertEqual(desktop["Categories"], "Office;Finance;")
+
+ def test_x11_window_icon_is_one_image_that_fits_the_window_property(self):
+ application = (
+ ROOT / "scripts/app_config/templates/linux/my_application.cc"
+ ).read_text()
+ # GDK drops a 512 px icon and every icon listed after it, and these two
+ # calls hand it whatever sizes the theme has, in no particular order.
+ self.assertNotIn("gtk_window_set_icon_name(window", application)
+ self.assertNotIn("gtk_window_set_icon_list(window", application)
+ self.assertIn("const gint icon_size = 256;", application)
+ self.assertIn("GTK_ICON_LOOKUP_FORCE_SIZE", application)
+ self.assertIn('"icon.png"', application)
+ self.assertIn("gtk_window_set_icon(window, icon)", application)
+
+ def test_metadata_does_not_advertise_the_abandoned_campfire_domain(self):
+ metadata = (FLATPAK / "com.cypherstack.campfire.metainfo.xml").read_text()
+ self.assertNotIn("campfireprivacy.com", metadata)
+ self.assertIn(
+ '<url type="homepage">https://github.com/firoorg/campfire</url>',
+ metadata,
+ )
+
+ def test_unknown_app_is_rejected(self):
+ result = subprocess.run(
+ [str(MAKE_APPDIR), "unknown", str(self.bundle), str(self.temp_path / "out")],
+ capture_output=True,
+ text=True,
+ )
+ self.assertNotEqual(result.returncode, 0)
+ self.assertIn("unknown app", result.stderr)
+
+ def test_app_lookup_uses_the_desktop_entry_command(self):
+ icon = (ROOT / "asset_sources/icon/stack_wallet/icon.png").read_bytes()
+ packaging_root = self.make_test_packaging_root("exec-field-code", icon)
+ desktop = packaging_root / "flatpak/com.cypherstack.stackwallet.desktop"
+ desktop.write_text(
+ desktop.read_text().replace("Exec=stack_wallet\n", "Exec=stack_wallet %U\n")
+ + "\n[Desktop Action Settings]\n"
+ + "Name=Settings\n"
+ + "Exec=unrelated-command\n"
+ )
+
+ result = self.run_make_appdir(
+ script=packaging_root / "appimage/make_appdir.sh",
+ appdir=self.temp_path / "field-code-AppDir",
+ )
+
+ self.assertEqual(result.returncode, 0, result.stdout + result.stderr)
+
+ def test_bundle_must_contain_the_expected_executable(self):
+ (self.bundle / "stack_wallet").unlink()
+ result = self.run_make_appdir()
+ self.assertNotEqual(result.returncode, 0)
+ self.assertIn("executable not found", result.stderr)
+
+ def test_bundle_executable_must_not_be_a_symbolic_link(self):
+ executable = self.bundle / "stack_wallet"
+ executable.unlink()
+ executable.symlink_to("/bin/true")
+
+ result = self.run_make_appdir()
+
+ self.assertNotEqual(result.returncode, 0)
+ self.assertIn("regular file, not a symbolic link", result.stderr)
+
+ def test_existing_appdir_must_be_empty(self):
+ appdir = self.temp_path / "AppDir"
+ appdir.mkdir()
+ sentinel = appdir / "old.desktop"
+ sentinel.write_text("stale\n")
+
+ result = self.run_make_appdir(appdir=appdir)
+
+ self.assertNotEqual(result.returncode, 0)
+ self.assertIn("not empty", result.stderr)
+ self.assertEqual(sentinel.read_text(), "stale\n")
+
+ def test_bundle_cannot_redirect_packaging_paths_outside_the_appdir(self):
+ outside = self.temp_path / "outside"
+ outside.mkdir()
+ (self.bundle / "usr").symlink_to(outside, target_is_directory=True)
+
+ result = self.run_make_appdir()
+
+ self.assertNotEqual(result.returncode, 0)
+ self.assertIn("reserved packaging path", result.stderr)
+ self.assertEqual(list(outside.iterdir()), [])
+
+ def test_bundle_cannot_supply_an_extra_desktop_entry(self):
+ (self.bundle / "injected.desktop").write_text(
+ "[Desktop Entry]\n"
+ "Type=Application\n"
+ "Name=Injected\n"
+ "Exec=stack_wallet\n"
+ )
+
+ result = self.run_make_appdir()
+
+ self.assertNotEqual(result.returncode, 0)
+ self.assertIn("reserved packaging path", result.stderr)
+
+ def test_cdpath_cannot_redirect_repository_discovery(self):
+ decoy = self.temp_path / "decoy"
+ (decoy / "appimage").mkdir(parents=True)
+ result = subprocess.run(
+ [
+ "appimage/make_appdir.sh",
+ "stack_wallet",
+ str(self.bundle),
+ str(self.temp_path / "cdpath-AppDir"),
+ ],
+ cwd=ROOT,
+ env={**os.environ, "CDPATH": str(decoy)},
+ capture_output=True,
+ text=True,
+ )
+ self.assertEqual(result.returncode, 0, result.stdout + result.stderr)
+
+ def test_icon_must_be_a_512_pixel_square_png(self):
+ cases = {
+ "bad signature": b"not a png" + bytes(32),
+ "wrong size": (
+ b"\x89PNG\r\n\x1a\n"
+ + bytes(8)
+ + (32).to_bytes(4, "big")
+ + (32).to_bytes(4, "big")
+ ),
+ "not square": (
+ b"\x89PNG\r\n\x1a\n"
+ + bytes(8)
+ + (512).to_bytes(4, "big")
+ + (256).to_bytes(4, "big")
+ ),
+ }
+ for name, icon_bytes in cases.items():
+ with self.subTest(name=name):
+ root = self.make_test_packaging_root(name, icon_bytes)
+ result = self.run_make_appdir(
+ script=root / "appimage/make_appdir.sh",
+ appdir=self.temp_path / f"{name}-AppDir",
+ )
+ self.assertNotEqual(result.returncode, 0)
+ self.assertIn("expected a 512x512 PNG", result.stderr)
+
+ def test_missing_icon_reports_a_diagnostic(self):
+ root = self.make_test_packaging_root("missing-icon", b"unused")
+ (root / "asset_sources/icon/stack_wallet/icon.png").unlink()
+
+ result = self.run_make_appdir(
+ script=root / "appimage/make_appdir.sh",
+ appdir=self.temp_path / "missing-icon-AppDir",
+ )
+
+ self.assertNotEqual(result.returncode, 0)
+ self.assertIn("icon is not a readable regular file", result.stderr)
+
+ @requires_tools(*ASSEMBLE_TOOLS, *VERIFY_TOOLS)
+ def test_assembly_honors_source_date_epoch_with_versioned_metadata(self):
+ runtime_log = self.temp_path / "runtime-log"
+ runtime = (
+ "#!/bin/sh\n"
+ "set -eu\n"
+ "[ \"${TARGET_APPIMAGE:-}\" = \"$APPIMAGE_TEST_EXPECTED_TARGET\" ]\n"
+ "printf '%s | %s\\n' \"$TARGET_APPIMAGE\" \"$*\" "
+ ">> \"$APPIMAGE_TEST_RUNTIME_LOG\"\n"
+ "case $1 in\n"
+ " --appimage-offset) wc -c < \"$0\" ;;\n"
+ " --appimage-extract)\n"
+ " [ \"$2\" = AppRun ]\n"
+ " mkdir -p squashfs-root\n"
+ " printf '#!/bin/sh\\n' > squashfs-root/AppRun\n"
+ " chmod 0755 squashfs-root/AppRun\n"
+ " ;;\n"
+ " *) exit 2 ;;\n"
+ "esac\n"
+ ).encode()
+ appdir = self.temp_path / "assembly-AppDir"
+ make_result = self.run_make_appdir(appdir=appdir)
+ self.assertEqual(
+ make_result.returncode, 0, make_result.stdout + make_result.stderr
+ )
+ runtime_path = self.temp_path / "runtime-x86_64"
+ runtime_path.write_bytes(runtime)
+ runtime_path.chmod(0o755)
+ mksquashfs_log = self.temp_path / "mksquashfs-log"
+ mksquashfs_epoch_log = self.temp_path / "mksquashfs-epoch-log"
+ fake_bin = self.temp_path / "assembly-fake-bin"
+ fake_bin.mkdir()
+ mksquashfs = fake_bin / "mksquashfs"
+ mksquashfs.write_text(
+ "#!/bin/sh\n"
+ "printf '%s\\n' \"${SOURCE_DATE_EPOCH:-}\" "
+ "> \"$APPIMAGE_TEST_MKSQUASHFS_EPOCH_LOG\"\n"
+ "printf '%s\\n' \"$@\" > \"$APPIMAGE_TEST_MKSQUASHFS_LOG\"\n"
+ f"exec {shutil.which('mksquashfs')} \"$@\"\n"
+ )
+ mksquashfs.chmod(0o755)
+ for desktop in (
+ appdir / "com.cypherstack.stackwallet.desktop",
+ appdir / "usr/share/applications/com.cypherstack.stackwallet.desktop",
+ ):
+ desktop.write_text(
+ desktop.read_text().replace(
+ "Type=Application\n", "Type=Application\nActions=Settings;\n"
+ )
+ + (
+ "\n[Desktop Action Settings]\n"
+ "Name=Settings\n"
+ "Exec=stack_wallet --settings\n"
+ )
+ )
+ output = self.temp_path / "test.AppImage"
+ result = subprocess.run(
+ [
+ str(ASSEMBLE_APPIMAGE),
+ str(appdir),
+ str(runtime_path),
+ str(output),
+ "1.2.3-test",
+ ],
+ capture_output=True,
+ text=True,
+ env={
+ **os.environ,
+ "PATH": f"{fake_bin}:{os.environ['PATH']}",
+ "SOURCE_DATE_EPOCH": "1234567890",
+ "APPIMAGE_TEST_MKSQUASHFS_EPOCH_LOG": str(mksquashfs_epoch_log),
+ "APPIMAGE_TEST_MKSQUASHFS_LOG": str(mksquashfs_log),
+ },
+ )
+ self.assertEqual(result.returncode, 0, result.stdout + result.stderr)
+ self.assertTrue(output.stat().st_mode & 0o111)
+ mksquashfs_arguments = mksquashfs_log.read_text().splitlines()
+ self.assertIn("-offset", mksquashfs_arguments)
+ self.assertEqual(
+ mksquashfs_arguments[mksquashfs_arguments.index("-offset") + 1],
+ str(len(runtime)),
+ )
+ self.assertNotIn("-mkfs-time", mksquashfs_arguments)
+ self.assertNotIn("-all-time", mksquashfs_arguments)
+ self.assertEqual(mksquashfs_epoch_log.read_text().strip(), "1234567890")
+ self.assertNotIn("filesystem.squashfs", " ".join(mksquashfs_arguments))
+ time.sleep(1.1)
+ second_output = self.temp_path / "second.AppImage"
+ second_result = subprocess.run(
+ [
+ str(ASSEMBLE_APPIMAGE),
+ str(appdir),
+ str(runtime_path),
+ str(second_output),
+ "1.2.3-test",
+ ],
+ capture_output=True,
+ text=True,
+ env={
+ **os.environ,
+ "PATH": f"{fake_bin}:{os.environ['PATH']}",
+ "SOURCE_DATE_EPOCH": "1234567890",
+ "APPIMAGE_TEST_MKSQUASHFS_EPOCH_LOG": str(mksquashfs_epoch_log),
+ "APPIMAGE_TEST_MKSQUASHFS_LOG": str(mksquashfs_log),
+ },
+ )
+ self.assertEqual(
+ second_result.returncode,
+ 0,
+ second_result.stdout + second_result.stderr,
+ )
+ self.assertEqual(output.read_bytes(), second_output.read_bytes())
+
+ verify = subprocess.run(
+ [str(VERIFY_APPIMAGE), str(output), str(runtime_path)],
+ capture_output=True,
+ text=True,
+ env={
+ **os.environ,
+ "APPIMAGE_TEST_EXPECTED_TARGET": str(output.resolve()),
+ "APPIMAGE_TEST_RUNTIME_LOG": str(runtime_log),
+ },
+ )
+ self.assertEqual(verify.returncode, 0, verify.stdout + verify.stderr)
+ self.assertEqual(
+ runtime_log.read_text().splitlines(),
+ [
+ f"{output.resolve()} | --appimage-offset",
+ f"{output.resolve()} | --appimage-extract AppRun",
+ ],
+ )
+
+ filesystem = subprocess.run(
+ ["unsquashfs", "-s", "-o", str(len(runtime)), str(output)],
+ check=True,
+ capture_output=True,
+ text=True,
+ )
+ self.assertIn("Compression gzip", filesystem.stdout)
+
+ extracted = self.temp_path / "extracted-AppDir"
+ subprocess.run(
+ [
+ "unsquashfs",
+ "-q",
+ "-no-progress",
+ "-o",
+ str(len(runtime)),
+ "-d",
+ str(extracted),
+ str(output),
+ ],
+ check=True,
+ capture_output=True,
+ text=True,
+ )
+ desktop = read_desktop(extracted / "com.cypherstack.stackwallet.desktop")
+ self.assertEqual(desktop["X-AppImage-Version"], "1.2.3-test")
+
+ @requires_tools(*ASSEMBLE_TOOLS)
+ def test_assembly_does_not_depend_on_the_umask(self):
+ runtime = self.temp_path / "runtime-x86_64"
+ runtime.write_bytes(bytes(4096))
+ images = []
+ for umask in (0o022, 0o077):
+ appdir = self.temp_path / f"umask-{umask:03o}-AppDir"
+ output = self.temp_path / f"umask-{umask:03o}.AppImage"
+ for command in (
+ [str(MAKE_APPDIR), "stack_wallet", str(self.bundle), str(appdir)],
+ [
+ str(ASSEMBLE_APPIMAGE),
+ str(appdir),
+ str(runtime),
+ str(output),
+ "1.2.3-test",
+ ],
+ ):
+ result = subprocess.run(
+ command, capture_output=True, text=True, umask=umask
+ )
+ self.assertEqual(
+ result.returncode, 0, result.stdout + result.stderr
+ )
+ images.append(output.read_bytes())
+
+ self.assertEqual(images[0], images[1])
+
+ @requires_tools(*BUILD_TOOLS)
+ def test_runtime_pin_cannot_be_replaced_by_the_build_environment(self):
+ (self.bundle / "stack_wallet").unlink()
+ result, output, curl_log = self.run_build_appimage(b"corrupt runtime")
+ self.assertNotEqual(result.returncode, 0)
+ self.assertIn("SHA-256 mismatch", result.stderr)
+ self.assertNotIn("executable not found", result.stderr)
+ self.assertFalse(output.exists())
+
+ curl_arguments = curl_log.read_text().splitlines()
+ self.assertIn("--retry-all-errors", curl_arguments)
+ self.assertIn("--proto", curl_arguments)
+ self.assertIn("=https", curl_arguments)
+ self.assertIn(
+ "https://github.com/AppImage/type2-runtime/releases/download/20251108/runtime-x86_64",
+ curl_arguments,
+ )
+ self.assertFalse(any("/continuous/" in arg for arg in curl_arguments))
+
+ @requires_tools("readelf")
+ def test_architecture_check_accepts_x86_64_and_rejects_arm64(self):
+ cases = ((62, 0), (183, 1))
+ for machine, expected_failure in cases:
+ with self.subTest(machine=machine):
+ executable = self.temp_path / f"machine-{machine}-app"
+ self.make_elf_executable(executable, machine=machine)
+
+ result = subprocess.run(
+ [
+ "bash",
+ "-c",
+ 'source "$1"; verify_x86_64_bundle "$2"',
+ "bash",
+ str(BUILD_APPIMAGE),
+ str(executable),
+ ],
+ capture_output=True,
+ text=True,
+ )
+
+ self.assertEqual(bool(result.returncode), bool(expected_failure))
+ if expected_failure:
+ self.assertIn("must be an x86-64 ELF", result.stderr)
+
+ @requires_tools(*BUILD_TOOLS)
+ def test_builder_rejects_a_non_x86_64_bundle(self):
+ icon = (ROOT / "asset_sources/icon/stack_wallet/icon.png").read_bytes()
+ packaging_root = self.make_test_packaging_root("arm64-bundle", icon)
+ runtime = bytes(4096)
+ build_script = packaging_root / "appimage/build_appimage.sh"
+ build_script.write_text(
+ build_script.read_text().replace(
+ "2fca8b443c92510f1483a883f60061ad09b46b978b2631c807cd873a47ec260d",
+ hashlib.sha256(runtime).hexdigest(),
+ )
+ )
+ self.make_elf_executable(self.bundle / "stack_wallet", machine=183)
+ fake_bin, runtime_fixture, curl_log = self.make_fake_curl(runtime)
+ output = self.temp_path / "arm64.AppImage"
+
+ result = subprocess.run(
+ [str(build_script), "stack_wallet", str(self.bundle), str(output)],
+ capture_output=True,
+ text=True,
+ env={
+ **os.environ,
+ "PATH": f"{fake_bin}:{os.environ['PATH']}",
+ "VERSION": "1.2.3-test",
+ "APPIMAGE_TEST_RUNTIME": str(runtime_fixture),
+ "APPIMAGE_TEST_CURL_LOG": str(curl_log),
+ },
+ )
+
+ self.assertNotEqual(result.returncode, 0)
+ self.assertIn("must be an x86-64 ELF", result.stderr)
+ self.assertFalse(output.exists())
+
+ def test_packaging_scripts_use_the_shared_tool_check(self):
+ for script in (MAKE_APPDIR, ASSEMBLE_APPIMAGE, BUILD_APPIMAGE, VERIFY_APPIMAGE):
+ with self.subTest(script=script.name):
+ source = script.read_text()
+ self.assertIn('source "$script_dir/lib.sh"', source)
+ self.assertIn("require_tools ", source)
+
+ @requires_tools(*BUILD_TOOLS)
+ def test_failed_verification_preserves_the_published_image_and_cleans_work(self):
+ icon = (ROOT / "asset_sources/icon/stack_wallet/icon.png").read_bytes()
+ packaging_root = self.make_test_packaging_root("failed-verification", icon)
+ runtime = bytes(4096)
+ build_script = packaging_root / "appimage/build_appimage.sh"
+ build_script.write_text(
+ build_script.read_text().replace(
+ "2fca8b443c92510f1483a883f60061ad09b46b978b2631c807cd873a47ec260d",
+ hashlib.sha256(runtime).hexdigest(),
+ )
+ )
+ verifier = packaging_root / "appimage/verify_appimage.sh"
+ verifier.write_text(
+ "#!/bin/sh\n"
+ "set -eu\n"
+ "work_marker=$(find \"$(dirname \"$1\")\" "
+ "-path '*/AppDir/bundle-marker' -print -quit)\n"
+ "[ -n \"$work_marker\" ]\n"
+ "work_prefix=$(dirname \"$1\")/.appimage-work.\n"
+ "case $work_marker in\n"
+ " \"$work_prefix\"*/AppDir/bundle-marker) ;;\n"
+ " *) exit 24 ;;\n"
+ "esac\n"
+ "[ \"$work_marker\" -ef \"$APPIMAGE_TEST_BUNDLE_MARKER\" ]\n"
+ "exit 23\n"
+ )
+ verifier.chmod(0o755)
+ fake_bin, runtime_fixture, curl_log = self.make_fake_curl(runtime)
+ output = self.temp_path / "published.AppImage"
+ output.write_bytes(b"known-good\n")
+ temp_root = self.temp_path / "tmp"
+ temp_root.mkdir()
+ self.make_elf_executable(self.bundle / "stack_wallet")
+
+ result = subprocess.run(
+ [str(build_script), "stack_wallet", str(self.bundle), str(output)],
+ capture_output=True,
+ text=True,
+ env={
+ **os.environ,
+ "PATH": f"{fake_bin}:{os.environ['PATH']}",
+ "TMPDIR": str(temp_root),
+ "VERSION": "1.2.3-test",
+ "APPIMAGE_TEST_RUNTIME": str(runtime_fixture),
+ "APPIMAGE_TEST_CURL_LOG": str(curl_log),
+ "APPIMAGE_TEST_BUNDLE_MARKER": str(self.bundle / "bundle-marker"),
+ },
+ )
+
+ self.assertEqual(result.returncode, 23)
+ self.assertEqual(output.read_bytes(), b"known-good\n")
+ self.assertEqual(list(output.parent.glob(".appimage-work.*")), [])
+ self.assertEqual(list(output.parent.glob(".appimage-unverified.*")), [])
+ self.assertEqual(list(temp_root.iterdir()), [])
+
+ @requires_tools(*BUILD_TOOLS)
+ def test_work_directory_is_cleaned_if_staged_output_creation_fails(self):
+ icon = (ROOT / "asset_sources/icon/stack_wallet/icon.png").read_bytes()
+ packaging_root = self.make_test_packaging_root("failed-mktemp", icon)
+ build_script = packaging_root / "appimage/build_appimage.sh"
+ fake_bin, runtime_fixture, curl_log = self.make_fake_curl(bytes(4096))
+ mktemp_log = self.temp_path / "mktemp-count"
+ mktemp = fake_bin / "mktemp"
+ real_mktemp = shutil.which("mktemp")
+ mktemp.write_text(
+ "#!/bin/sh\n"
+ "set -eu\n"
+ "count=0\n"
+ "[ ! -f \"$APPIMAGE_TEST_MKTEMP_LOG\" ] || "
+ "count=$(cat \"$APPIMAGE_TEST_MKTEMP_LOG\")\n"
+ "count=$((count + 1))\n"
+ "printf '%s\\n' \"$count\" > \"$APPIMAGE_TEST_MKTEMP_LOG\"\n"
+ "[ \"$count\" -ne 2 ] || exit 55\n"
+ f"exec {real_mktemp} \"$@\"\n"
+ )
+ mktemp.chmod(0o755)
+ output_dir = self.temp_path / "output"
+ output_dir.mkdir()
+ temp_root = self.temp_path / "tmp"
+ temp_root.mkdir()
+ output = output_dir / "published.AppImage"
+
+ result = subprocess.run(
+ [str(build_script), "stack_wallet", str(self.bundle), str(output)],
+ capture_output=True,
+ text=True,
+ env={
+ **os.environ,
+ "PATH": f"{fake_bin}:{os.environ['PATH']}",
+ "TMPDIR": str(temp_root),
+ "VERSION": "1.2.3-test",
+ "APPIMAGE_TEST_RUNTIME": str(runtime_fixture),
+ "APPIMAGE_TEST_CURL_LOG": str(curl_log),
+ "APPIMAGE_TEST_MKTEMP_LOG": str(mktemp_log),
+ },
+ )
+
+ self.assertEqual(result.returncode, 55, result.stdout + result.stderr)
+ self.assertEqual(list(output_dir.glob(".appimage-work.*")), [])
+ self.assertEqual(list(output_dir.glob(".appimage-unverified.*")), [])
+ self.assertEqual(list(temp_root.iterdir()), [])
+
+ def test_linux_build_docs_state_appimage_requirements(self):
+ docs = (ROOT / "docs/building/linux.md").read_text()
+ appimage_docs = docs.split("## Build an AppImage", 1)[1]
+
+ self.assertRegex(appimage_docs, r"apt-get install[^\n]*\bbinutils\b")
+ self.assertRegex(appimage_docs, r"apt-get install[^\n]*\bcurl\b")
+ self.assertIn("AppImageLauncher 3 beta", appimage_docs)
+ self.assertRegex(appimage_docs, r"AppImageLauncher\s+2\.2")
+ self.assertIn("one 256 px window icon", appimage_docs)
+ self.assertIn("Flutter asset", appimage_docs)
+
+ def test_appimage_version_is_passed_to_workflow_steps_through_env(self):
+ workflow = BUILD_WORKFLOW.read_text()
+
+ self.assertNotIn(
+ 'export VERSION="${{ steps.ver.outputs.version }}"', workflow
+ )
+ self.assertEqual(
+ workflow.count("VERSION: ${{ steps.ver.outputs.version }}"), 3
+ )
+
+ @requires_tools(*ASSEMBLE_TOOLS)
+ def test_assembly_rejects_output_inside_the_appdir(self):
+ appdir = self.temp_path / "nested-output-AppDir"
+ make_result = self.run_make_appdir(appdir=appdir)
+ self.assertEqual(
+ make_result.returncode, 0, make_result.stdout + make_result.stderr
+ )
+ runtime = self.temp_path / "runtime-x86_64"
+ runtime.write_bytes(bytes(4096))
+ output = appdir / "nested" / "nested.AppImage"
+
+ result = subprocess.run(
+ [
+ str(ASSEMBLE_APPIMAGE),
+ str(appdir),
+ str(runtime),
+ str(output),
+ "1.2.3-test",
+ ],
+ capture_output=True,
+ text=True,
+ )
+
+ self.assertNotEqual(result.returncode, 0)
+ self.assertIn("must be outside the AppDir", result.stderr)
+ self.assertFalse(output.exists())
+ self.assertFalse(output.parent.exists())
+ self.assertEqual(list(appdir.glob(".appimage-assemble.*")), [])
+
+ @requires_tools(*ASSEMBLE_TOOLS)
+ def test_assembly_replaces_a_directory_symlink_without_writing_through_it(self):
+ appdir = self.temp_path / "symlink-output-AppDir"
+ make_result = self.run_make_appdir(appdir=appdir)
+ self.assertEqual(
+ make_result.returncode, 0, make_result.stdout + make_result.stderr
+ )
+ runtime = self.temp_path / "runtime-x86_64"
+ runtime.write_bytes(bytes(4096))
+ redirected_directory = appdir / "redirected-output"
+ redirected_directory.mkdir()
+ output = self.temp_path / "external.AppImage"
+ output.symlink_to(redirected_directory, target_is_directory=True)
+
+ result = subprocess.run(
+ [
+ str(ASSEMBLE_APPIMAGE),
+ str(appdir),
+ str(runtime),
+ str(output),
+ "1.2.3-test",
+ ],
+ capture_output=True,
+ text=True,
+ )
+
+ self.assertEqual(result.returncode, 0, result.stdout + result.stderr)
+ self.assertTrue(output.is_file())
+ self.assertFalse(output.is_symlink())
+ self.assertEqual(list(redirected_directory.iterdir()), [])
+
+ @requires_tools(*ASSEMBLE_TOOLS)
+ def test_assembly_rejects_incomplete_runtime_layout(self):
+ cases = {
+ "missing AppRun": ("AppRun", "AppDir must contain an executable"),
+ "missing icon": (
+ "com.cypherstack.stackwallet.png",
+ "desktop entry icon not found",
+ ),
+ "missing DirIcon": (".DirIcon", ".DirIcon must be a relative"),
+ }
+ for name, (missing, message) in cases.items():
+ with self.subTest(name=name):
+ appdir = self.temp_path / f"{name}-AppDir"
+ make_result = self.run_make_appdir(appdir=appdir)
+ self.assertEqual(
+ make_result.returncode,
+ 0,
+ make_result.stdout + make_result.stderr,
+ )
+ (appdir / missing).unlink()
+ runtime = self.temp_path / f"{name}-runtime"
+ runtime.write_bytes(bytes(4096))
+ result = subprocess.run(
+ [
+ str(ASSEMBLE_APPIMAGE),
+ str(appdir),
+ str(runtime),
+ str(self.temp_path / f"{name}.AppImage"),
+ "1.2.3-test",
+ ],
+ capture_output=True,
+ text=True,
+ )
+ self.assertNotEqual(result.returncode, 0)
+ self.assertIn(message, result.stderr)
+
+ @requires_tools(*ASSEMBLE_TOOLS)
+ def test_assembly_rejects_an_absolute_diricon_link(self):
+ appdir = self.temp_path / "absolute-diricon-AppDir"
+ make_result = self.run_make_appdir(appdir=appdir)
+ self.assertEqual(
+ make_result.returncode, 0, make_result.stdout + make_result.stderr
+ )
+ diricon = appdir / ".DirIcon"
+ diricon.unlink()
+ diricon.symlink_to((appdir / "com.cypherstack.stackwallet.png").resolve())
+ runtime = self.temp_path / "absolute-diricon-runtime"
+ runtime.write_bytes(bytes(4096))
+
+ result = subprocess.run(
+ [
+ str(ASSEMBLE_APPIMAGE),
+ str(appdir),
+ str(runtime),
+ str(self.temp_path / "absolute-diricon.AppImage"),
+ "1.2.3-test",
+ ],
+ capture_output=True,
+ text=True,
+ )
+
+ self.assertNotEqual(result.returncode, 0)
+ self.assertIn("relative link to the desktop entry icon", result.stderr)
+
+ @requires_tools(*VERIFY_TOOLS)
+ def test_image_verifier_does_not_execute_untrusted_input(self):
+ image = self.temp_path / "fake.AppImage"
+ marker = self.temp_path / "executed"
+ image.write_text(
+ "#!/bin/sh\n"
+ f"touch {marker}\n"
+ )
+ image.chmod(0o755)
+ runtime = self.temp_path / "fake-runtime"
+ runtime.write_bytes(image.read_bytes())
+
+ result = subprocess.run(
+ [str(VERIFY_APPIMAGE), str(image), str(runtime)],
+ capture_output=True,
+ text=True,
+ )
+
+ self.assertNotEqual(result.returncode, 0)
+ self.assertFalse(marker.exists())
+
+ @requires_tools(*VERIFY_TOOLS, "mksquashfs")
+ def test_image_verifier_rejects_a_symbolic_apprun(self):
+ runtime = self.temp_path / "runtime"
+ runtime.write_bytes(bytes(4096))
+ payload = self.temp_path / "payload"
+ payload.mkdir()
+ (payload / "AppRun").symlink_to("/bin/sh")
+ squashfs = self.temp_path / "payload.squashfs"
+ subprocess.run(
+ [
+ "mksquashfs",
+ str(payload),
+ str(squashfs),
+ "-all-root",
+ "-noappend",
+ "-no-xattrs",
+ "-comp",
+ "gzip",
+ ],
+ check=True,
+ capture_output=True,
+ text=True,
+ )
+ image = self.temp_path / "symbolic-AppRun.AppImage"
+ image.write_bytes(runtime.read_bytes() + squashfs.read_bytes())
+ image.chmod(0o755)
+
+ result = subprocess.run(
+ [str(VERIFY_APPIMAGE), str(image), str(runtime)],
+ capture_output=True,
+ text=True,
+ )
+
+ self.assertNotEqual(result.returncode, 0)
+ self.assertIn("non-symbolic AppRun", result.stderr)
+
+ def test_build_script_can_be_sourced_repeatedly_without_side_effects(self):
+ result = subprocess.run(
+ [
+ "bash",
+ "-c",
+ 'source "$1"; source "$1"; printf sourced',
+ "bash",
+ str(BUILD_APPIMAGE),
+ ],
+ capture_output=True,
+ text=True,
+ )
+ self.assertEqual(result.returncode, 0, result.stdout + result.stderr)
+ self.assertEqual(result.stdout, "sourced")
+
+
+if __name__ == "__main__":
+ unittest.main()Why this scored 25/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.