diff --git a/.gitignore b/.gitignore index c61f208..d1f00d3 100644 --- a/.gitignore +++ b/.gitignore @@ -42,4 +42,7 @@ test-playwright dist-electron-packages ios .ruby-version -+.env \ No newline at end of file ++.env + +# Generated test files +.generated/ \ No newline at end of file diff --git a/test-deeplinks.sh b/test-deeplinks.sh.bak similarity index 90% rename from test-deeplinks.sh rename to test-deeplinks.sh.bak index 237af45..9db3c26 100755 --- a/test-deeplinks.sh +++ b/test-deeplinks.sh.bak @@ -37,9 +37,9 @@ echo "\nTesting Contact Import Routes:" # 1. Direct Query Parameter Import (URL-encoded JSON) QUERY_CONTACTS='[{ - "did":"did:ethr:0xf969A5DeE7a5806d1C37f4Ec49A555Ab97911089" + "did":"did:ethr:" },{ - "did":"did:ethr:0xFEd3b416946b23F3F472799053144B4E34155B5b", + "did":"did:ethr:", "name":"Jordan", "nextPubKeyHashB64":"IBfRZfwdzeKOzqCx8b+WlLpMJHOAT9ZknIDJo7F3rZE=", "publicKeyBase64":"A1eIndfaxgMpVwyD5dYe74DgjuIo5SwPZFCcLdOemjf" @@ -56,7 +56,7 @@ test_link "timesafari://contact-import/$BULK_JWT" "Multiple contacts via JWT" test_link "timesafari://contacts?contactJwt=$BULK_JWT" "Multiple contacts redirect" # Contact Management Routes -test_link "timesafari://contact-edit/did:ethr:0xf969A5DeE7a5806d1C37f4Ec49A555Ab97911089" \ +test_link "timesafari://contact-edit/did:ethr:" \ "Edit first contact" # Error Cases @@ -72,9 +72,6 @@ echo "\nTesting Claim Routes:" test_link "timesafari://claim/01JMAAFZRNSRTQ0EBSD70A8E1H" test_link "timesafari://claim-cert/01JMAAFZRNSRTQ0EBSD70A8E1H" -echo "\nTesting Additional Claim Routes:" -test_link "timesafari://claim-add-raw/123?claimJwtId=jwt123" - # Test project routes echo "\nTesting Project Routes:" test_link "timesafari://project/https%3A%2F%2Fendorser.ch%2Fentity%2F01JKW0QZX1XVCVZV85VXAMB31R" @@ -110,12 +107,12 @@ test_link "timesafari://did/invalid-did" # Payload: { # "iat": 1740740453, # "contact": { -# "did": "did:ethr:0xFEd3b416946b23F3F472799053144B4E34155B5b", +# "did": "did:ethr:", # "name": "Jordan", # "nextPubKeyHashB64": "IBfRZfwdzeKOzqCx8b+WlLpMJHOAT9ZknIDJo7F3rZE=", # "publicKeyBase64": "A1eIndfaxgMpVwyD5dYe74DgjuIo5SwPZFCcLdOemjf" # }, -# "iss": "did:ethr:0xD53114830D4a5D90416B43Fc99a25b0dF8bb1BAd" +# "iss": "did:ethr:" # } SINGLE_INVITE_JWT="eyJ0eXAiOiJKV1QiLCJhbGciOiJFUzI1NksifQ.eyJpYXQiOjE3NDA3NDA0NTMsImNvbnRhY3QiOnsiZGlkIjoiZGlkOmV0aHI6MHhGRWQzYjQxNjk0NmIyM0YzRjQ3Mjc5OTA1MzE0NEI0RTM0MTU1QjViIiwibmFtZSI6IkpvcmRhbiIsIm5leHRQdWJLZXlIYXNoQjY0IjoiSUJmUlpmd2R6ZUtPenFDeDhiK1dsTHBNSkhPQVQ5WmtuSURKbzdGM3JaRT0iLCJwdWJsaWNLZXlCYXNlNjQiOiJBMWVJbmRmYXhnTXBWd3lENWRZZTc0RGdqdUlvNVN3UFpGQ2NMZEtlbWpmIn0sImlzcyI6ImRpZDpldGhyOjB4RDUzMTE0ODMwRDRhNUQ5MDQxNkI0M0ZjOTlhMjViMGRGOGJiMUJBZCJ9.yKEFounxUGU9-grAMFHA12dif9BKYkftg8F3wAIcFYh0H_k1tevjEYyD1fvAyIxYxK5xR0E8moqMhi78ipJXcg" diff --git a/test-scripts/run-deeplink-tests.sh b/test-scripts/run-deeplink-tests.sh new file mode 100755 index 0000000..c73d223 --- /dev/null +++ b/test-scripts/run-deeplink-tests.sh @@ -0,0 +1,144 @@ +#!/bin/bash + +# Parse command line arguments +GENERATE_ONLY=false +ALL_TESTS=false +while getopts "ga" opt; do + case $opt in + g) GENERATE_ONLY=true ;; + a) ALL_TESTS=true ;; + \?) echo "Invalid option: -$OPTARG" >&2; exit 1 ;; + esac +done + +# Directory for storing generated DIDs +mkdir -p .generated + +# Function to validate environment variables +validate_env() { + local missing=false + for var in CONTACT1_DID CONTACT1_KEY CONTACT2_DID CONTACT2_KEY ISSUER_DID ISSUER_KEY; do + if [ -z "${!var}" ]; then + echo "Error: $var is not set" >&2 + missing=true + fi + done + if [ "$missing" = true ]; then + rm -f .generated/test-env.sh # Remove invalid env file + echo "Please regenerate DIDs by running:" >&2 + echo "./test-scripts/run-deeplink-tests.sh -g" >&2 + return 1 + fi + return 0 +} + +# Check if we already have generated DIDs +if [ -f .generated/test-env.sh ] && [ "$GENERATE_ONLY" = false ]; then + echo "Using existing DIDs from .generated/test-env.sh" + source .generated/test-env.sh + validate_env || exit 1 +else + # Function to extract DID info from did_generator.sh output + extract_did_info() { + local output + # Read all input into output variable + output=$(cat) + + # Debug the input + echo "Parsing output:" >&2 + echo "$output" >&2 + + # Extract values using more robust patterns + local did=$(echo "$output" | grep "^DID: " | cut -d' ' -f2-) + local private_key=$(echo "$output" | grep "^Private Key: " | cut -d' ' -f3-) + + # Debug the extracted values + echo "Found DID: $did" >&2 + echo "Found Key: $private_key" >&2 + + # Output JSON only if both values were found + if [ -n "$did" ] && [ -n "$private_key" ]; then + printf '%s\n' "{\"did\":\"$did\",\"privateKey\":\"$private_key\"}" + else + echo "Error: Could not extract DID info from output" >&2 + return 1 + fi + } + + echo "Generating first contact DID..." + CONTACT1_INFO=$(./test-scripts/did_generator.sh | tee /dev/stderr | extract_did_info) + if [ $? -ne 0 ]; then + echo "Failed to generate first contact DID" + exit 1 + fi + CONTACT1_DID=$(echo "$CONTACT1_INFO" | jq -r .did) + CONTACT1_KEY=$(echo "$CONTACT1_INFO" | jq -r .privateKey) + echo "Extracted DID: $CONTACT1_DID" + echo "Extracted Key: $CONTACT1_KEY" + + echo "Generating second contact DID (Jordan)..." + CONTACT2_INFO=$(./test-scripts/did_generator.sh 2>&1 | tee /dev/stderr | extract_did_info) + CONTACT2_DID=$(echo "$CONTACT2_INFO" | jq -r .did) + CONTACT2_KEY=$(echo "$CONTACT2_INFO" | jq -r .privateKey) + + echo "Generating issuer DID..." + ISSUER_INFO=$(./test-scripts/did_generator.sh 2>&1 | tee /dev/stderr | extract_did_info) + ISSUER_DID=$(echo "$ISSUER_INFO" | jq -r .did) + ISSUER_KEY=$(echo "$ISSUER_INFO" | jq -r .privateKey) + + # Create a temporary env file with the generated DIDs + echo "Creating test-env.sh with generated DIDs..." + cat > .generated/test-env.sh << EOF +#!/bin/bash +# Generated $(date) +export CONTACT1_DID="$CONTACT1_DID" +export CONTACT1_KEY="$CONTACT1_KEY" +export CONTACT2_DID="$CONTACT2_DID" +export CONTACT2_KEY="$CONTACT2_KEY" +export ISSUER_DID="$ISSUER_DID" +export ISSUER_KEY="$ISSUER_KEY" +EOF + + # Debug output + echo "Contents of generated test-env.sh:" + cat .generated/test-env.sh + + # Make sure file is executable + chmod +x .generated/test-env.sh + + # Source and validate the newly created env file + echo "Sourcing generated test-env.sh..." + source .generated/test-env.sh + validate_env || exit 1 +fi + +if [ "$GENERATE_ONLY" = true ]; then + echo "Generated DIDs and created environment file at .generated/test-env.sh" + echo "To use these DIDs, run:" + echo "source .generated/test-env.sh" + exit 0 +fi + +# Create contacts JSON for deep links +CONTACTS_JSON=$(jq -n \ + --arg did1 "$CONTACT1_DID" \ + --arg did2 "$CONTACT2_DID" \ + '[ + {"did": $did1}, + { + "did": $did2, + "name": "Jordan", + "nextPubKeyHashB64": "IBfRZfwdzeKOzqCx8b+WlLpMJHOAT9ZknIDJo7F3rZE=", + "publicKeyBase64": "A1eIndfaxgMpVwyD5dYe74DgjuIo5SwPZFCcLdOemjf" + } + ]') + +export CONTACTS_JSON +export TEST_MODE=${TEST_MODE:-print} # Use TEST_MODE from environment or default to print + +# Run deep link tests in order +if [ "$ALL_TESTS" = true ]; then + ./test-scripts/test-deeplinks.sh -t 5 -a +else + ./test-scripts/test-deeplinks.sh -t 5 +fi \ No newline at end of file diff --git a/test-scripts/test-deeplinks.sh b/test-scripts/test-deeplinks.sh new file mode 100755 index 0000000..6bccc78 --- /dev/null +++ b/test-scripts/test-deeplinks.sh @@ -0,0 +1,130 @@ +#!/bin/bash + +# Verify required environment variables are set +required_vars=( + "CONTACT1_DID" + "CONTACT1_KEY" + "CONTACT2_DID" + "CONTACT2_KEY" + "ISSUER_DID" + "ISSUER_KEY" + "CONTACTS_JSON" +) + +for var in "${required_vars[@]}"; do + if [ -z "${!var}" ]; then + echo "Error: $var is not set" + echo "Please run: source .generated/test-env.sh" + exit 1 + fi +done + +# Color definitions +BLUE='\033[0;34m' +GREEN='\033[0;32m' +YELLOW='\033[1;33m' +PURPLE='\033[0;35m' +CYAN='\033[0;36m' +NC='\033[0m' # No Color +BOLD='\033[1m' + +# Parse command line arguments +TIMEOUT=5 +ALL_TESTS=false +TEST_MODE=${TEST_MODE:-execute} # Default to execute mode + +while getopts "t:a" opt; do + case $opt in + t) TIMEOUT=$OPTARG ;; + a) ALL_TESTS=true ;; + \?) echo "Invalid option: -$OPTARG" >&2; exit 1 ;; + esac +done + +# Check for adb and connected devices +if [ "$TEST_MODE" = "execute" ]; then + if ! command -v adb >/dev/null 2>&1; then + echo "Warning: adb not found, switching to print mode" + TEST_MODE=print + elif [ -z "$(adb devices | grep -v List | grep device)" ]; then + echo "Warning: no devices/emulators found, switching to print mode" + TEST_MODE=print + fi +fi + +# Function to encode URL parameters +urlencode() { + local string="${1}" + local strlen=${#string} + local encoded="" + local pos c o + + for (( pos=0 ; pos