| 1 | #!/usr/bin/env bash |
| 2 | set -euo pipefail |
| 3 | cd "$(dirname "$0")/.." |
| 4 | temporary="$(mktemp -d)" |
| 5 | trap 'rm -rf "$temporary"' EXIT |
| 6 | binary="$temporary/account-device-tests" |
| 7 | case "${1:-}" in |
| 8 | '') ;; |
| 9 | --biometric) |
| 10 | : "${CAGE_SIGNING_IDENTITY:?Biometric tests require a Developer ID identity}" |
| 11 | : "${CAGE_PROVISIONING_PROFILE:?Biometric tests require a provisioning profile}" |
| 12 | bundle="$temporary/Cage.app" |
| 13 | mkdir -p "$bundle/Contents/MacOS" |
| 14 | cp "$CAGE_PROVISIONING_PROFILE" "$bundle/Contents/embedded.provisionprofile" |
| 15 | cat > "$bundle/Contents/Info.plist" <<'PLIST' |
| 16 | <?xml version="1.0" encoding="UTF-8"?><plist version="1.0"><dict><key>CFBundleIdentifier</key><string>io.github.lee-xeo.claude-cage</string><key>CFBundleExecutable</key><string>Cage</string><key>CFBundlePackageType</key><string>APPL</string></dict></plist> |
| 17 | PLIST |
| 18 | binary="$bundle/Contents/MacOS/Cage" |
| 19 | ;; |
| 20 | *) echo 'Usage: scripts/test-account-device.sh [--biometric]' >&2; exit 2 ;; |
| 21 | esac |
| 22 | swiftc -O -parse-as-library -framework Security -framework LocalAuthentication \ |
| 23 | desktop/AccountDevice.swift desktop/AccountDeviceTests.swift -o "$binary" |
| 24 | if [[ "${1:-}" == --biometric ]]; then |
| 25 | codesign --force --sign "$CAGE_SIGNING_IDENTITY" --timestamp=none "$binary" |
| 26 | signing_team="$(codesign -dv --verbose=4 "$binary" 2>&1 | sed -n 's/^TeamIdentifier=//p')" |
| 27 | bash scripts/prepare-account-signing.sh "$CAGE_PROVISIONING_PROFILE" "$signing_team" "$temporary/account.entitlements" |
| 28 | codesign --force --sign "$CAGE_SIGNING_IDENTITY" --options runtime --timestamp=none \ |
| 29 | --entitlements "$temporary/account.entitlements" "$bundle" |
| 30 | fi |
| 31 | "$binary" "$@" |