diff --git a/scripts/ci/android/install-sdk.sh b/scripts/ci/android/install-sdk.sh index 5e66479abb..cf251f6076 100755 --- a/scripts/ci/android/install-sdk.sh +++ b/scripts/ci/android/install-sdk.sh @@ -1,9 +1,9 @@ #!/bin/bash -# Installs a pinned emulator, platform-tools and the Google APIs x86_64 system image of API 34 from Google's repository, -# each checked against the SHA-1 its repository manifest lists and the SHA-256 recorded when it was pinned, and creates -# the AVD "ci" for that image. -# Usage: scripts/ci/android/install-sdk.sh +# Installs a pinned emulator, platform-tools and the Google APIs x86_64 system image of API 34 (or 30) from Google's +# repository, each checked against the SHA-1 its repository manifest lists and the SHA-256 recorded when it was pinned, +# and creates the AVD "ci" for that image. +# Usage: scripts/ci/android/install-sdk.sh [api] # Puts ANDROID_SDK_ROOT, ANDROID_HOME and ANDROID_AVD_HOME in GITHUB_ENV and the emulator and adb on GITHUB_PATH. set -euo pipefail @@ -11,7 +11,17 @@ set -euo pipefail mkdir -p "$1" sdk=$(cd "$1" && pwd) repo=https://dl.google.com/android/repository -api=34 +api=${2:-34} + +# API 30 is the last x86_64 image that translates 32-bit ARM code, which the armv7a APK needs +case $api in + 34) image=(x86_64-34_r14.zip e0f6c9a0691aa27bd597d0deb1bcfdc943ac8ca7 783a40134baf4f3012d4464fbe1571b1612a0dbd2e7a44d14bd8328923443833) ;; + 30) image=(x86_64-30_r16.zip 6ae21030eaadc041078444d3798e4b399f3e787d daae27654be74ae83a484daea4db2c0c77b4f4ad661a645bd5f36d96ce03e4d5) ;; + *) + echo "error: no pinned system image for API $api" + exit 1 + ;; +esac install() { local dest=$1 url=$2 sha1=$3 sha256=$4 zip @@ -30,8 +40,7 @@ install "$sdk" "$repo/emulator-linux_x64-16428233.zip" \ cd7362ea55dfb86a418958138dc396e74165dd01 b08fc43d8608d2955f607f1b287beb525041e730086bdca3af152accac3af9c1 install "$sdk" "$repo/platform-tools_r37.0.1-linux.zip" \ 477254aa5f903c15cf51001717bdf347fb6b53e0 d230f13842f60f782a8645f9c813f8f845bf36089ea7289f28c48f17979313f1 -install "$sdk/system-images/android-$api/google_apis" "$repo/sys-img/google_apis/x86_64-34_r14.zip" \ - e0f6c9a0691aa27bd597d0deb1bcfdc943ac8ca7 783a40134baf4f3012d4464fbe1571b1612a0dbd2e7a44d14bd8328923443833 +install "$sdk/system-images/android-$api/google_apis" "$repo/sys-img/google_apis/${image[0]}" "${image[1]}" "${image[2]}" # avdmanager needs the package.xml that only sdkmanager writes avd_home=$sdk/avd diff --git a/scripts/ci/ios-sim/old-database.sh b/scripts/ci/ios-sim/old-database.sh new file mode 100755 index 0000000000..db7cf82f87 --- /dev/null +++ b/scripts/ci/ios-sim/old-database.sh @@ -0,0 +1,41 @@ +#!/bin/bash + +# Replaces the database of the app that smoke-test.sh left running with the encrypted database that the previous +# release's CLI made (scripts/simplex-chat-build.py test old-database), enters its key on the passphrase screen and +# waits for the chat list with its group, so the app's core and OpenSSL open and migrate that database. +# Usage: scripts/ci/ios-sim/old-database.sh +# Needs SIM_UDID and UI_OUT from smoke-test.sh. + +set -euo pipefail + +old=$1 +bundle_id=chat.simplex.app +ui=$(dirname "$0")/ui +key="old-release-key" +group=team + +# the snapshot tests after the smoke test may have stopped the app already +xcrun simctl terminate "$SIM_UDID" "$bundle_id" || true +container=$(xcrun simctl get_app_container "$SIM_UDID" "$bundle_id" group.chat.simplex.app) +data=$(xcrun simctl get_app_container "$SIM_UDID" "$bundle_id" data) +trap '"$ui" shot old-database-failed || true' ERR +echo "::group::database files before the swap" +ls -la "$container" "$data/Documents" || true +echo "::endgroup::" +rm -f "$container"/simplex_v1_chat.db* "$container"/simplex_v1_agent.db* +cp "$old/simplex_chat.db" "$container/simplex_v1_chat.db" +cp "$old/simplex_agent.db" "$container/simplex_v1_agent.db" + +# iOS otherwise asks for the camera over the passphrase screen, hiding its button from the accessibility tree +xcrun simctl privacy "$SIM_UDID" grant camera "$bundle_id" +# the keychain still has the key of the smoke test's database, so the app asks for the right one +xcrun simctl launch "$SIM_UDID" "$bundle_id" +"$ui" wait "Save passphrase and open chat" 180 +"$ui" shot old-database-passphrase +"$ui" tap-value "Enter passphrase…" +"$ui" type "$key" +"$ui" tap "Save passphrase and open chat" + +"$ui" wait "$group" 180 +"$ui" shot old-database-chat-list +echo "the app opened the previous release's database and shows its group $group" diff --git a/scripts/ci/ios-sim/pq-contact.sh b/scripts/ci/ios-sim/pq-contact.sh new file mode 100755 index 0000000000..4b5f7667a3 --- /dev/null +++ b/scripts/ci/ios-sim/pq-contact.sh @@ -0,0 +1,163 @@ +#!/bin/bash + +# Connects the app that smoke-test.sh left at its chat list with a CLI peer, both on the preset servers: the app pastes +# the peer's one-time link, they exchange messages, and the peer's and the app's contact info must show quantum +# resistant encryption, whose sntrup761 KEM hashes with the core's OpenSSL. +# Usage: scripts/ci/ios-sim/pq-contact.sh +# Needs SIM_UDID and UI_OUT from smoke-test.sh; the peer's commands and their output go to UI_OUT/peer.log. + +set -euo pipefail + +cli=$1 +work=$2 +ui=$(dirname "$0")/ui +bundle_id=chat.simplex.app +peer=pq_peer +peer_pq="quantum resistant end-to-end encryption" +app_pq="Quantum resistant" +peer_message="peer-to-app" +app_message="app-to-peer" +connect_secs=300 +# the y above which a row is on the iPhone 17 screen, clear of the home indicator +visible_bottom=780 +mkdir -p "$work" +chmod +x "$cli" + +# smoke-test.sh stopped its stream of the app's log when it ended +xcrun simctl spawn "$SIM_UDID" log stream --level debug --style compact --predicate 'process == "SimpleX"' > "$UI_OUT/pq-app.log" 2>&1 & +log_pid=$! + +finish() { + local status=$? + if [ "$status" -ne 0 ]; then + "$ui" shot pq-failed || true + fi + kill "$log_pid" || true + exit "$status" +} +trap finish EXIT + +# Runs one command in the peer CLI, which stays online for 5 s after it to exchange messages; the output is in $work/out. +chat() { + local status=0 + "$cli" -d "$work/$peer" --user-display-name "$peer" -e "$1" -t 5 < /dev/null > "$work/out" 2>&1 || status=$? + { + echo "> $1" + cat "$work/out" + } >> "$UI_OUT/peer.log" + return "$status" +} + +until_peer_shows() { + local pattern=$1 cmd=$2 deadline=$((SECONDS + connect_secs)) + until chat "$cmd" && grep -qiE "$pattern" "$work/out"; do + if [ "$SECONDS" -ge "$deadline" ]; then + echo "error: \"$pattern\" not shown by the peer's \"$cmd\" after $connect_secs s" + cat "$work/out" + return 1 + fi + done +} + +# "x y width height" of each element line of ui tree +frames() { + sed -E 's/.* at (-?[0-9]+),(-?[0-9]+) size ([0-9]+)x([0-9]+).*/\1 \2 \3 \4/' +} + +tap_centre() { + local x y w h + read -r x y w h + "$ui" tap-xy $((x + w / 2)) $((y + h / 2)) +} + +# the full simplex: link opens in the app without asking the server for the link's data; the CLI prints only the +# short link with -e, so the link is read from its database +chat /c +link=$(sqlite3 "$work/${peer}_chat.db" "SELECT CAST(conn_req_inv AS TEXT) FROM connections WHERE conn_req_inv IS NOT NULL ORDER BY connection_id DESC LIMIT 1") +case "$link" in + simplex:/invitation#*) ;; + *) + echo "error: the peer made no one-time link" + cat "$work/out" + exit 1 + ;; +esac +# pasted, as the core rejected this link opened with simctl openurl (run 41240723750) +echo "the peer's link: ${#link} characters" +"$ui" clipboard "$link" +# the sheet's QR scanner would ask for the camera in an alert over the paste button; iOS stops an app whose +# permissions change +xcrun simctl privacy "$SIM_UDID" grant camera "$bundle_id" +"$ui" relaunch +"$ui" tap "Connect via link or QR code" +"$ui" tap "Tap to paste link" 20 +deadline=$((SECONDS + 60)) +until "$ui" find "Use current profile" > /dev/null 2>&1; do + "$ui" tap "Allow Paste" 1 > /dev/null 2>&1 || true + if [ "$SECONDS" -ge "$deadline" ]; then + echo "error: the app offered no connection to the peer's link 60 s after it was pasted" + exit 1 + fi + sleep 2 +done +"$ui" shot connect-via-link +"$ui" tap "Use current profile" +"$ui" wait "Connection request sent" 60 +"$ui" tap OK + +# the app's profile is the peer's only contact: smoke-test.sh typed its name, which the keyboard may have autocorrected +contact_line='^[^ ]+( \(.*\))?$' +until_peer_shows "$contact_line" /contacts +contact=$(grep -m 1 -E "$contact_line" "$work/out" | cut -d ' ' -f 1) +until_peer_shows "$peer_pq" "/i @$contact" +chat "@$contact $peer_message" + +"$ui" wait "$peer" "$connect_secs" +"$ui" find "$peer" | head -n 1 | frames | tap_centre +# the chat's messages have no text in the accessibility tree: the screenshots show them +"$ui" wait "Your contact" 30 +"$ui" shot pq-chat + +# the message field has no label: it is right of the attachments button, and the send button appears at its right end +read -r x y w h < <("$ui" tree | grep -E '^Button "Attachements" ' | frames) +row=$((y + h / 2)) +"$ui" tap-xy $((x + w + 100)) "$row" +"$ui" type "$app_message" +send=$("$ui" tree | grep -E '^Button ' | grep -vE '^Button "(Attachements|Flash)" ' | frames | awk -v row="$row" \ + '{ x = $1 + int($3 / 2); y = $2 + int($4 / 2) } y > row - 30 && y < row + 30 && x > 250 { print x, y }' | sort -n | tail -n 1) +if [ -z "$send" ]; then + echo "error: no send button right of the message field" + exit 1 +fi +read -r x y <<< "$send" +"$ui" tap-xy "$x" "$y" + +until_peer_shows "$app_message" "/tail @$contact 5" +chat "/i @$contact" +cp "$work/out" "$UI_OUT/peer-contact.txt" +if ! grep -qF "$peer_pq" "$work/out"; then + echo "error: the peer's contact $contact is not quantum resistant after the messages" + exit 1 +fi +"$ui" shot pq-messages + +# the contact's info shows the connection's encryption in its "E2E encryption" row, below the first screen; the tree +# lists the row before it scrolls into view, so it is scrolled until the screenshot shows it +"$ui" tree | grep -E "^Button \"$peer\" " | frames | tap_centre +row_top() { + "$ui" find "$app_pq" 2> /dev/null | grep ' at ' | frames | head -n 1 | cut -d ' ' -f 2 +} +for _ in 1 2 3 4 5; do + top=$(row_top || true) + if [ -n "$top" ] && [ "$top" -lt "$visible_bottom" ]; then + break + fi + "$ui" swipe 201 700 201 300 +done +top=$(row_top || true) +if [ -z "$top" ] || [ "$top" -ge "$visible_bottom" ]; then + echo "error: the app's contact info does not show \"$app_pq\" encryption" + exit 1 +fi +"$ui" shot pq-contact-info +echo "the app and the peer exchanged messages, and both show quantum resistant encryption" diff --git a/scripts/ci/ios-sim/ui b/scripts/ci/ios-sim/ui index a705155388..21137bbecf 100755 --- a/scripts/ci/ios-sim/ui +++ b/scripts/ci/ios-sim/ui @@ -11,7 +11,8 @@ # ui type type into the focused field (US keyboard characters only) # ui clipboard put the text on the clipboard, to paste it with the text field's Paste menu # ui key [count] press a keyboard key: return submits the field (the Search key), delete erases a character -# ui wait [secs] wait up to secs (30) until a label or value contains the text (case-sensitive) +# ui wait [secs] wait up to secs (30) until a label or value contains the text (case-sensitive), allowing +# the camera alert that may cover the app meanwhile # ui find print the elements whose label or value contains the text (any case) # ui shot save UI_OUT/NN-.png, a smaller NN--view.jpg and NN-.json, and print the tree # ui tree print the tree, one element per line: type, label, value, top-left corner and size in points, @@ -36,6 +37,8 @@ bundle_id=chat.simplex.app app_group=group.chat.simplex.app # the toolbar's new chat button: shown with and without conversations, unlike the search field toolbar_button=Compose +# iOS can ask for the camera over the app even after simctl privacy granted it, and the tree then shows only the alert +camera_alert="would like to access the Camera" # Elements below the screen, such as the keyboard's keys, are counted rather than listed; the screen is the first # element's frame, or the given height. @@ -49,8 +52,7 @@ compact_tree() { # describe-ui failed once while a system alert was appearing, and read the tree a few seconds later (run 38895987656) describe() { - local attempt - for attempt in 1 2 3 4; do + for _ in 1 2 3 4; do if axe describe-ui --udid "$SIM_UDID" "$@"; then return fi @@ -72,8 +74,11 @@ point() { wait_for() { local text=$1 secs=${2:-30} number "$secs" - local deadline=$((SECONDS + secs)) t + local deadline=$((SECONDS + secs)) t="" until t=$(tree 2> /dev/null) && grep -qF -- "$text" <<< "$t"; do + if grep -qF -- "$camera_alert" <<< "$t"; then + axe tap --label Allow --wait-timeout 1 --post-delay 2 --udid "$SIM_UDID" || true + fi if [ "$SECONDS" -ge "$deadline" ]; then echo "error: \"$text\" not shown after $secs s" return 1