Browse Source

feat: Improve test scripts for deep link testing

- Add DID generation and management for testing
- Create .generated directory for test artifacts
- Add environment variable support for test configuration
- Improve deep link test script with better URL handling
- Add print/execute modes for testing with/without device

The changes improve the testing workflow by:
1. Generating and managing test DIDs automatically
2. Storing test artifacts in .generated directory (gitignored)
3. Adding proper URL encoding for deep links
4. Supporting both print mode for debugging and execute mode for device testing
5. Adding better error handling and validation
pull/127/head
Matthew Raymer 1 week ago
parent
commit
02747fb771
  1. 3
      .gitignore
  2. 13
      test-deeplinks.sh.bak
  3. 144
      test-scripts/run-deeplink-tests.sh
  4. 130
      test-scripts/test-deeplinks.sh

3
.gitignore

@ -43,3 +43,6 @@ dist-electron-packages
ios
.ruby-version
+.env
# Generated test files
.generated/

13
test-deeplinks.sh → 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"

144
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

130
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<strlen ; pos++ )); do
c=${string:$pos:1}
case "$c" in
[-_.~a-zA-Z0-9] ) o="${c}" ;;
* ) printf -v o '%%%02x' "'$c"
esac
encoded+="${o}"
done
echo "${encoded}"
}
# Function to print section header
print_header() {
echo -e "\n${BOLD}${1}${NC}"
echo -e "${BOLD}$(printf '=%.0s' {1..50})${NC}\n"
}
# Function to handle deep links
handle_deeplink() {
local url="$1"
local color="$2"
local encoded_url=$(urlencode "$url")
if [ "$TEST_MODE" = "print" ]; then
echo -e "${color}Deep Link URL:${NC}"
echo -e "${color}$url${NC}"
echo -e "${color}Encoded URL:${NC}"
echo -e "${color}$encoded_url${NC}"
echo "---"
else
echo -e "${color}Opening: $url${NC}"
adb shell am start -a android.intent.action.VIEW -d "$encoded_url"
sleep "$TIMEOUT"
fi
}
# Generate a test JWT for claims
TEST_JWT=$(./test-scripts/did_generator.sh | grep "Created JWT:" | cut -d' ' -f3)
echo -e "${BOLD}Running deep link tests (mode: $TEST_MODE)...${NC}"
# 1. Basic routes
print_header "Basic Routes"
handle_deeplink "timesafari://claim-cert/$TEST_JWT" $BLUE
handle_deeplink "timesafari://claim-add-raw/$TEST_JWT?claim=$(urlencode '{"type":"test"}')&claimJwtId=$TEST_JWT" $BLUE
# 2. Contact import routes
print_header "Contact Import Routes"
handle_deeplink "timesafari://contacts/import?contacts=$(urlencode "$CONTACTS_JSON")" $GREEN
handle_deeplink "timesafari://contacts" $GREEN
# 3. Contact management routes
print_header "Contact Management Routes"
handle_deeplink "timesafari://contact-edit?did=$CONTACT1_DID" $YELLOW
handle_deeplink "timesafari://contact-edit?did=$CONTACT2_DID" $YELLOW
if [ "$ALL_TESTS" = true ]; then
# 4. Claims and verification routes
print_header "Claims and Verification Routes"
handle_deeplink "timesafari://verify?issuer=$ISSUER_DID" $PURPLE
handle_deeplink "timesafari://claims?contact=$CONTACT1_DID" $PURPLE
# 5. Project routes
print_header "Project Routes"
handle_deeplink "timesafari://projects" $CYAN
handle_deeplink "timesafari://project-edit?id=test-project" $CYAN
fi
echo -e "\n${BOLD}Deep link tests completed${NC}"
Loading…
Cancel
Save