Something went wrong. Try again.
An auto tiler for macOS
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261#!/bin/bashset -euo pipefailcd "$(dirname "$0")/../.."unset BASH_ENVumask 077root=$PWDPARCEL_DEV_BINARY=$(Scripts/parcel-dev.sh --path)export PARCEL_DEV_BINARYwork=$(mktemp -d "${TMPDIR:-/tmp}/parcel-updates-tests.XXXXXX")keychain="$work/mock.keychain-db"trap 'rm -rf "$work"' EXITmkdir "$work/bin"for tool in security xcrun; do printf '#!/bin/bash\nprintf "Forbidden keychain or notarization call\\n" >&2\nexit 88\n' > "$work/bin/$tool" chmod +x "$work/bin/$tool"doneexport PATH="$work/bin:$PATH"count=0check() { if ! "$@"; then printf 'Update script test failed: %s\n' "$*" >&2; exit 1; fi; count=$((count + 1)); }fails() { if "$@" > "$work/failure.log" 2>&1; then printf 'Expected failure: %s\n' "$*" >&2; /bin/cat "$work/failure.log" >&2; return 1; fi; }xml_value() { /usr/bin/xmllint --xpath "$2" "$1"; }plist_value() { /usr/libexec/PlistBuddy -c "Print ':$2'" "$1"; }crypto=(Scripts/parcel-dev.sh update-crypto)export TEST_CRYPTO_HELPER="$root/Scripts/parcel-dev.sh"signer="$work/bin/sign_update"cat > "$signer" <<'SIGNER'#!/bin/bashset -euo pipefail[[ $# == 4 && $1 == --ed-key-file && $3 == -p ]]if [[ $2 == - ]]; then exec "$TEST_CRYPTO_HELPER" update-crypto sign "$4"else exec "$TEST_CRYPTO_HELPER" update-crypto sign "$4" < "$2"fiSIGNERchmod +x "$signer"check test -x "$signer"public=$("${crypto[@]}" temporary-key "$work/seed")check test "$(stat -f %Lp "$work/seed")" = 600check fails "${crypto[@]}" temporary-key "$work/seed"check fails "${crypto[@]}" invalidprintf 'Archive fixture\n' > "$work/update.dmg"signature=$("$signer" --ed-key-file "$work/seed" -p "$work/update.dmg")check "${crypto[@]}" verify "$work/update.dmg" "$signature" "$public"stdin_signature=$("${crypto[@]}" sign "$work/update.dmg" < "$work/seed")check test "$(printf '%s' "$stdin_signature" | base64 -D | wc -c | tr -d ' ')" = 64check test "$(printf '%s' "$stdin_signature" | base64 -D | base64 -b 0)" = "$stdin_signature"check "${crypto[@]}" verify "$work/update.dmg" "$stdin_signature" "$public"check fails "${crypto[@]}" sign < "$work/seed"check fails "${crypto[@]}" sign "$work/update.dmg" extra < "$work/seed"check fails "${crypto[@]}" sign "$work/missing" < "$work/seed"check Scripts/parcel-dev.sh release-data-not-contained "$work/failure.log" "$work/seed"Scripts/parcel-dev.sh update-seed-fixtures "$work"for input in "$work/"*.seed-input; do check fails "${crypto[@]}" sign "$work/update.dmg" < "$input" check grep -Fq 'canonical base64 Ed25519 seed' "$work/failure.log" check Scripts/parcel-dev.sh release-data-not-contained "$work/failure.log" "$work/seed" "$input"donecheck fails "${crypto[@]}" verify "$work/update.dmg" bad "$public"check fails "${crypto[@]}" verify "$work/update.dmg" "$signature" badprintf 'Changed\n' >> "$work/update.dmg"check fails "${crypto[@]}" verify "$work/update.dmg" "$signature" "$public"check fails "${crypto[@]}" verify "$work/missing" "$signature" "$public"source Scripts/script-root-test.shcheck script_root_test UpdateFeedIntegrationTestscheck Scripts/parcel-dev.sh generate-update-key --dry-run --keychain "$keychain" > "$work/key-plan.log"check test ! -e "$keychain"check fails Scripts/parcel-dev.sh generate-update-key --keychain "$keychain"check fails Scripts/parcel-dev.sh generate-update-key --account '' --dry-runcheck script_root_test UpdateKeyTestsstored_public=$("${crypto[@]}" temporary-key "$work/stored-seed")printf '%s' "$stored_public" > "$work/stored-public"key_signature=$("${crypto[@]}" sign "$work/update.dmg" < "$work/stored-seed")check "${crypto[@]}" verify "$work/update.dmg" "$key_signature" "$(<"$work/stored-public")"mkdir -p "$work/project/Scripts" "$work/project/Packaging" "$work/bin"cp Scripts/product.env Scripts/version.sh Scripts/packaging-paths.sh Scripts/release.sh Scripts/parcel-dev.sh "$work/project/Scripts/"cp Packaging/parcel.rb "$work/project/Packaging/"export TEST_CHAIN_LOG="$work/chain.log" TEST_RELEASE_FAIL=export PARCEL_SPARKLE_BIN="$work/bin"cat > "$work/project/Scripts/bundle.sh" <<'MOCK'#!/bin/bashset -euo pipefailprintf 'bundle %s identity=%s\n' "$*" "$PARCEL_SIGN_IDENTITY" >> "$TEST_CHAIN_LOG"[[ ${TEST_RELEASE_FAIL:-} != bundle ]] || exit 70[[ $1 == release && $PARCEL_SIGN_IDENTITY == '-' ]] || exit 71mkdir -p build/Parcel.app/Contentsprintf '<?xml version="1.0"?><plist version="1.0"><dict/></plist>\n' > build/Parcel.app/Contents/Info.plistScripts/parcel-dev.sh update-metadata configure build/Parcel.app/Contents/Info.plist releaseMOCKcat > "$work/project/Scripts/check-bundle.sh" <<'MOCK'#!/bin/bashset -euo pipefailprintf 'check %s\n' "$*" >> "$TEST_CHAIN_LOG"[[ ${TEST_RELEASE_FAIL:-} != check ]] || exit 70Scripts/parcel-dev.sh update-metadata check build/Parcel.app/Contents/Info.plistMOCKcat > "$work/project/Scripts/dmg.sh" <<'MOCK'#!/bin/bashset -euo pipefailprintf 'dmg %s\n' "$*" >> "$TEST_CHAIN_LOG"[[ ${TEST_RELEASE_FAIL:-} != dmg ]] || exit 70printf 'Signed disk image fixture\n' > "$2"MOCKchmod +x "$work/project/Scripts/"*.shcd "$work/project"unset PARCEL_SIGN_IDENTITY PARCEL_NOTARY_PROFILE PARCEL_APPCAST_URL PARCEL_UPDATE_PUBLIC_KEY PARCEL_DOWNLOAD_URL PARCEL_DOWNLOAD_URL_PREFIX PARCEL_RELEASE_DIR PARCEL_PREVIOUS_APPexport PARCEL_VERSION=1.2.3 PARCEL_BUILD_NUMBER=123mkdir "$work/failing-bin"cat > "$work/failing-bin/parcel-dev" <<'MOCK'#!/bin/bashset -euo pipefailif [[ $1 == update-crypto && $2 == temporary-key ]]; then printf 'Mock temporary-key generation failed\n' >&2 exit 70fiexec "$REAL_DEV_BINARY" "$@"MOCKchmod +x "$work/failing-bin/parcel-dev"check fails env REAL_DEV_BINARY="$PARCEL_DEV_BINARY" PARCEL_DEV_BINARY="$work/failing-bin/parcel-dev" Scripts/release.sh --dry-runcheck grep -Fq 'Mock temporary-key generation failed' "$work/failure.log"check test ! -e "$TEST_CHAIN_LOG"check test ! -d build/dry-run/1.2.3check test -z "$(find build -name seed -o -name '.release.*')"check fails Scripts/release.sh --badcheck fails Scripts/release.shcheck fails env PARCEL_SIGN_IDENTITY=Fixture PARCEL_APPCAST_URL=https://example.invalid/appcast.xml PARCEL_UPDATE_PUBLIC_KEY="$public" PARCEL_DOWNLOAD_URL=https://example.invalid/artifact PARCEL_DOWNLOAD_URL_PREFIX=https://example.invalid/files Scripts/release.shcheck grep -Fq 'Set only one download URL or download URL prefix' "$work/failure.log"check test ! -e "$TEST_CHAIN_LOG"check fails env PARCEL_VERSION=../bad Scripts/release.sh --dry-runcheck fails env TEST_RELEASE_FAIL=bundle Scripts/release.sh --dry-runcheck test ! -d build/dry-run/1.2.3check fails env TEST_RELEASE_FAIL=check Scripts/release.sh --dry-runcheck fails env TEST_RELEASE_FAIL=dmg Scripts/release.sh --dry-runcheck fails env PARCEL_SPARKLE_BIN=/missing Scripts/release.sh --dry-runcheck test ! -d build/dry-run/1.2.3check env PARCEL_PREVIOUS_APP=/previous-release.app PARCEL_DOWNLOAD_URL=https://example.invalid/ignored Scripts/release.sh --dry-run > "$work/dry-run.log"check test -s build/dry-run/1.2.3/DRY-RUN.txtcheck grep -q 'bundle release identity=-' "$TEST_CHAIN_LOG"check grep -q 'check --no-launch build/Parcel.app' "$TEST_CHAIN_LOG"check fails Scripts/release.sh --dry-runcheck grep -q 'Refusing to replace' "$work/failure.log"check test -z "$(find build -name seed -o -name '.release.*')"check "$root/Scripts/parcel-dev.sh" check-ruby-syntax build/dry-run/1.2.3/parcel.rbout=build/dry-run/1.2.3dmg="$out/Parcel-1.2.3.dmg"check test "$(xml_value "$out/appcast.xml" 'string(/rss/channel/item/*[local-name()="version"])')" = 123check test "$(xml_value "$out/appcast.xml" 'string(/rss/channel/item/*[local-name()="shortVersionString"])')" = 1.2.3check test "$(xml_value "$out/appcast.xml" 'string(/rss/channel/item/*[local-name()="minimumSystemVersion"])')" = 15.0check test "$(xml_value "$out/appcast.xml" 'string(/rss/channel/item/enclosure/@length)')" = "$(stat -f %z "$dmg")"check test "$(xml_value "$out/appcast.xml" 'string(/rss/channel/item/enclosure/@url)')" = https://example.invalid/parcel/Parcel-1.2.3.dmgsha=$(shasum -a 256 "$dmg"); sha=${sha%% *}check grep -Fq "$sha" "$out/parcel.rb"check grep -Fq "version '1.2.3'" "$out/parcel.rb"check fails grep -Fq '@VERSION@' "$out/parcel.rb"check Scripts/parcel-dev.sh release-checksum "$dmg" "$out/SHA256SUMS"xml_value "$out/appcast.xml" 'string(/rss/channel/item/enclosure/@*[local-name()="edSignature"])' > signatureplist_value build/Parcel.app/Contents/Info.plist SUPublicEDKey | tr -d '\n' > publiccheck Scripts/parcel-dev.sh update-crypto verify "$dmg" "$(<signature)" "$(<public)"check fails Scripts/parcel-dev.sh update-metadata badcheck fails Scripts/parcel-dev.sh update-metadata configure missing releasecheck fails Scripts/parcel-dev.sh update-metadata configure build/Parcel.app/Contents/Info.plist invalidcheck fails env PARCEL_APPCAST_URL=http://example.org PARCEL_UPDATE_PUBLIC_KEY="$public" Scripts/parcel-dev.sh update-metadata configure build/Parcel.app/Contents/Info.plist releasecheck fails env PARCEL_APPCAST_URL=https://example.org PARCEL_UPDATE_PUBLIC_KEY=bad Scripts/parcel-dev.sh update-metadata configure build/Parcel.app/Contents/Info.plist releasemkdir metadatametadata=(Scripts/parcel-dev.sh update-metadata release "$dmg" "$(<signature)" metadata Packaging/parcel.rb)check fails env PARCEL_DOWNLOAD_URL_PREFIX='https://example.org/files?token=value' "${metadata[@]}"artifact_url=https://tangled.org/vinnymac.dev/parcel/artifacts/3n2fixturecheck env PARCEL_DOWNLOAD_URL="$artifact_url" "${metadata[@]}"check test "$(xml_value metadata/appcast.xml 'string(/rss/channel/item/enclosure/@url)')" = "$artifact_url"check grep -Fq "url '$artifact_url'" metadata/parcel.rbcheck fails env PARCEL_DOWNLOAD_URL="$artifact_url" PARCEL_DOWNLOAD_URL_PREFIX=https://example.invalid/files "${metadata[@]}"check fails Scripts/parcel-dev.sh update-metadatacheck env PARCEL_DOWNLOAD_URL_PREFIX="https://example.org/owner's/files" "${metadata[@]}"check "$root/Scripts/parcel-dev.sh" check-ruby-syntax metadata/parcel.rbcheck env PARCEL_DOWNLOAD_URL_PREFIX=https://example.org/files PARCEL_VERSION=1.2.3-beta.1+build.42 PARCEL_BUILD_NUMBER=123 "${metadata[@]}"check grep -Fq "version '1.2.3-beta.1+build.42'" metadata/parcel.rbprintf 'touch %q\n' "$work/unexpected-version-startup" > "$work/version-startup.sh"check env BASH_ENV="$work/version-startup.sh" PARCEL_DOWNLOAD_URL_PREFIX=https://example.org/files "${metadata[@]}"check test ! -e "$work/unexpected-version-startup"for version in '' '1.2.3 bad' $'1.2.3\n1.2.3' $'1.2.3\t' letters; do check fails env PARCEL_VERSION="$version" "${metadata[@]}" check grep -Fq 'Invalid version' "$work/failure.log"donefor build in '' 1.2 -1 letters $'123\n' $'123\t' '123 '; do check fails env PARCEL_BUILD_NUMBER="$build" "${metadata[@]}" check grep -Fq 'Invalid build number' "$work/failure.log"donemkdir -p "$work/renamed/Scripts" "$work/renamed/output"cp Scripts/parcel-dev.sh Scripts/version.sh "$work/renamed/Scripts/"cat > "$work/renamed/Scripts/product.env" <<'PRODUCT'# Quoted literals and a distinct prefix exercise the product settings reader.export PRODUCT_NAME='Crate Kit'export PRODUCT_ENV_PREFIX=CRATEexport PRODUCT_CASK=crate-kitPRODUCTcat > "$work/renamed/template.rb" <<'CASK'cask 'crate-kit' do version '@VERSION@' sha256 '@SHA256@' url '@DOWNLOAD_URL@' name 'Crate Kit' app 'Crate Kit.app'endCASKprintf '<?xml version="1.0"?><plist version="1.0"><dict/></plist>\n' > "$work/renamed/Info.plist"printf 'Renamed disk image fixture\n' > "$work/renamed/Crate Kit-2.3.4.dmg"renamed_metadata() { env -u PRODUCT_NAME -u PRODUCT_ENV_PREFIX -u PRODUCT_CASK \ CRATE_VERSION="${CRATE_VERSION-2.3.4}" CRATE_BUILD_NUMBER="${CRATE_BUILD_NUMBER-234}" CRATE_UPDATE_PUBLIC_KEY="$public" \ CRATE_APPCAST_URL=https://example.invalid/crate/appcast.xml CRATE_DOWNLOAD_URL_PREFIX=https://example.invalid/crate/releases \ PARCEL_VERSION=9.9.9 PARCEL_BUILD_NUMBER=999 PARCEL_UPDATE_PUBLIC_KEY=bad PARCEL_APPCAST_URL=http://example.invalid/ignored \ "$work/renamed/Scripts/parcel-dev.sh" update-metadata "$@"}check renamed_metadata configure "$work/renamed/Info.plist" releasecheck renamed_metadata check "$work/renamed/Info.plist"check test "$(plist_value "$work/renamed/Info.plist" 'Crate KitUpdatesEnabled')" = truecheck fails plist_value "$work/renamed/Info.plist" ParcelUpdatesEnabledcheck test "$(plist_value "$work/renamed/Info.plist" SUPublicEDKey)" = "$public"check test "$(plist_value "$work/renamed/Info.plist" SUFeedURL)" = https://example.invalid/crate/appcast.xmlcheck renamed_metadata release "$work/renamed/Crate Kit-2.3.4.dmg" "$signature" "$work/renamed/output" "$work/renamed/template.rb"check "$root/Scripts/parcel-dev.sh" check-ruby-syntax "$work/renamed/output/crate-kit.rb"out="$work/renamed/output"dmg="$work/renamed/Crate Kit-2.3.4.dmg"check test "$(xml_value "$out/appcast.xml" 'string(/rss/channel/title)')" = 'Crate Kit Updates'check test "$(xml_value "$out/appcast.xml" 'string(/rss/channel/item/title)')" = 'Crate Kit 2.3.4'check test "$(xml_value "$out/appcast.xml" 'string(/rss/channel/item/*[local-name()="version"])')" = 234check test "$(xml_value "$out/appcast.xml" 'string(/rss/channel/item/*[local-name()="shortVersionString"])')" = 2.3.4check test "$(xml_value "$out/appcast.xml" 'string(/rss/channel/item/enclosure/@url)')" = 'https://example.invalid/crate/releases/Crate Kit-2.3.4.dmg'check test "$(xml_value "$out/appcast.xml" 'string(/rss/channel/item/enclosure/@length)')" = "$(stat -f %z "$dmg")"check Scripts/parcel-dev.sh release-checksum "$dmg" "$out/SHA256SUMS"sha=$(shasum -a 256 "$dmg"); sha=${sha%% *}check grep -Fq "$sha" "$out/crate-kit.rb"check grep -Fq "version '2.3.4'" "$out/crate-kit.rb"check grep -Fq 'Crate Kit.app' "$out/crate-kit.rb"for token in '@VERSION@' '@SHA256@' '@DOWNLOAD_URL@'; do check fails grep -Fq "$token" "$out/crate-kit.rb"; donecheck test ! -e "$out/parcel.rb"renamed_release=(release "$dmg" "$signature" "$out" "$work/renamed/template.rb")CRATE_VERSION=2.3.4-beta.1+build.42 CRATE_BUILD_NUMBER=00235 check renamed_metadata "${renamed_release[@]}"check test "$(xml_value "$out/appcast.xml" 'string(/rss/channel/item/*[local-name()="shortVersionString"])')" = 2.3.4-beta.1+build.42check test "$(xml_value "$out/appcast.xml" 'string(/rss/channel/item/*[local-name()="version"])')" = 00235for version in '' letters '2.3.4 bad' $'2.3.4\n2.3.4'; do CRATE_VERSION="$version" check fails renamed_metadata "${renamed_release[@]}" check grep -Fq 'Invalid version' "$work/failure.log"donefor build in '' 2.3 -1 $'234\n'; do CRATE_BUILD_NUMBER="$build" check fails renamed_metadata "${renamed_release[@]}" check grep -Fq 'Invalid build number' "$work/failure.log"donecheck renamed_metadata configure "$work/renamed/Info.plist" debugcheck renamed_metadata check "$work/renamed/Info.plist"check test "$(plist_value "$work/renamed/Info.plist" 'Crate KitUpdatesEnabled')" = falsecheck test "$(plist_value "$work/renamed/Info.plist" SUEnableAutomaticChecks)" = falsecheck fails plist_value "$work/renamed/Info.plist" SUPublicEDKeycheck fails plist_value "$work/renamed/Info.plist" SUFeedURL# shellcheck disable=SC2016printf 'export PRODUCT_NAME=$(touch %s)\n' "$work/should-not-exist" > "$work/renamed/Scripts/product.env"check fails renamed_metadata check "$work/renamed/Info.plist"check test ! -e "$work/should-not-exist"check grep -q 'literal exports' "$work/failure.log"printf 'Update script checks passed: %s\n' "$count"