test_anastasis_reducer_backup_enter_user_attributes.sh (3973B)
1 #!/bin/bash 2 # This file is in the public domain. 3 4 set -eu 5 6 # Exit, with status code "skip" (no 'real' failure) 7 function exit_skip() { 8 echo " SKIP: $1" 9 exit 77 10 } 11 12 # Exit, with error message (hard failure) 13 function exit_fail() { 14 echo " ERROR: $1" 15 exit 1 16 } 17 18 # Cleanup to run whenever we exit 19 function cleanup() 20 { 21 for n in $(jobs -p) 22 do 23 kill $n 2> /dev/null || true 24 done 25 wait 26 } 27 28 CONF_1="test_anastasis_reducer_1.conf" 29 CONF_2="test_anastasis_reducer_2.conf" 30 CONF_3="test_anastasis_reducer_3.conf" 31 CONF_4="test_anastasis_reducer_4.conf" 32 TFILE=$(mktemp test_reducer_stateXXXXXX) 33 34 # Install cleanup handler (except for kill -9) 35 trap cleanup EXIT 36 37 # Check we can actually run 38 echo -n "Testing for jq" 39 jq -h > /dev/null || exit_skip "jq required" 40 echo " FOUND" 41 42 echo -n "Testing for anastasis-reducer ..." 43 anastasis-reducer -h > /dev/null || exit_skip "anastasis-reducer required" 44 echo " FOUND" 45 46 echo -n "Testing for anastasis-httpd" 47 anastasis-httpd -h >/dev/null </dev/null || exit_skip " MISSING" 48 echo " FOUND" 49 50 51 # Name of the Postgres database we will use for the script. 52 # Will be dropped, do NOT use anything that might be used 53 # elsewhere 54 TARGET_DB_1=`anastasis-config -c $CONF_1 -s stasis-postgres -o CONFIG | sed -e "s/^postgres:\/\/\///"` 55 TARGET_DB_2=`anastasis-config -c $CONF_2 -s stasis-postgres -o CONFIG | sed -e "s/^postgres:\/\/\///"` 56 TARGET_DB_3=`anastasis-config -c $CONF_3 -s stasis-postgres -o CONFIG | sed -e "s/^postgres:\/\/\///"` 57 TARGET_DB_4=`anastasis-config -c $CONF_4 -s stasis-postgres -o CONFIG | sed -e "s/^postgres:\/\/\///"` 58 59 echo -n "Initialize anastasis database ..." 60 dropdb $TARGET_DB_1 >/dev/null 2>/dev/null || true 61 createdb $TARGET_DB_1 || exit_skip "Could not create database $TARGET_DB_1" 62 anastasis-dbinit -c $CONF_1 2> anastasis-dbinit_1.log 63 dropdb $TARGET_DB_2 >/dev/null 2>/dev/null || true 64 createdb $TARGET_DB_2 || exit_skip "Could not create database $TARGET_DB_2" 65 anastasis-dbinit -c $CONF_2 2> anastasis-dbinit_2.log 66 dropdb $TARGET_DB_3 >/dev/null 2>/dev/null || true 67 createdb $TARGET_DB_3 || exit_skip "Could not create database $TARGET_DB_3" 68 anastasis-dbinit -c $CONF_3 2> anastasis-dbinit_3.log 69 dropdb $TARGET_DB_4 >/dev/null 2>/dev/null || true 70 createdb $TARGET_DB_4 || exit_skip "Could not create database $TARGET_DB_4" 71 anastasis-dbinit -c $CONF_4 2> anastasis-dbinit_4.log 72 73 echo " OK" 74 75 echo -n "Launching anastasis service ..." 76 anastasis-httpd -c $CONF_1 2> anastasis-httpd_1.log & 77 anastasis-httpd -c $CONF_2 2> anastasis-httpd_2.log & 78 anastasis-httpd -c $CONF_3 2> anastasis-httpd_3.log & 79 anastasis-httpd -c $CONF_4 2> anastasis-httpd_4.log & 80 81 # Wait for anastasis service to be available 82 for n in $(seq 1 50) 83 do 84 echo -n "." 85 sleep 0.1 86 OK=0 87 # anastasis_01 88 wget http://localhost:8086/ -o /dev/null -O /dev/null >/dev/null || continue 89 # anastasis_02 90 wget http://localhost:8087/ -o /dev/null -O /dev/null >/dev/null || continue 91 # anastasis_03 92 wget http://localhost:8088/ -o /dev/null -O /dev/null >/dev/null || continue 93 # anastasis_04 94 wget http://localhost:8089/ -o /dev/null -O /dev/null >/dev/null || continue 95 OK=1 96 break 97 done 98 99 if [ 1 != $OK ] 100 then 101 exit_skip "Failed to launch anastasis services" 102 fi 103 echo " OK" 104 105 # Test user attributes collection in a backup state 106 echo -n "Test user attributes collection in a backup state ..." 107 108 anastasis-reducer -L WARNING -a \ 109 '{"identity_attributes": { 110 "full_name": "Max Musterman", 111 "sq_number": "4", 112 "birthdate": "2000-01-01"}}' \ 113 enter_user_attributes resources/02-backup.json "$TFILE" 114 115 STATE=$(jq -r -e .backup_state < "$TFILE") 116 if test "$STATE" != "AUTHENTICATIONS_EDITING" 117 then 118 exit_fail "Expected new state to be 'AUTHENTICATIONS_EDITING', got '$STATE'" 119 fi 120 121 SELECTED_COUNTRY=$(jq -r -e .selected_country < "$TFILE") 122 if test "$SELECTED_COUNTRY" != "xx" 123 then 124 exit_fail "Expected selected country to be 'xx', got '$SELECTED_COUNTRY'" 125 fi 126 127 echo "OK" 128 129 rm -f "$TFILE" 130 131 exit 0