test_anastasis_reducer_done_authentication.sh (1400B)
1 #!/bin/bash 2 3 set -eu 4 5 # Exit, with status code "skip" (no 'real' failure) 6 function exit_skip() { 7 echo " SKIP: $1" 8 exit 77 9 } 10 11 # Exit, with error message (hard failure) 12 function exit_fail() { 13 echo " ERROR: $1" 14 exit 1 15 } 16 17 # Cleanup to run whenever we exit 18 function cleanup() 19 { 20 for n in `jobs -p` 21 do 22 kill $n 2> /dev/null || true 23 done 24 rm -f $TFILE 25 wait 26 } 27 28 # Install cleanup handler (except for kill -9) 29 TFILE=`mktemp test_reducer_stateXXXXXX` 30 trap cleanup EXIT 31 32 # Check we can actually run 33 echo -n "Testing for jq ..." 34 jq -h > /dev/null || exit_skip "jq required" 35 echo " FOUND" 36 37 echo -n "Testing for anastasis-reducer ..." 38 anastasis-reducer -h > /dev/null || exit_skip "anastasis-reducer required" 39 echo " FOUND" 40 41 42 echo -n "Test failing done authentication (next) ..." 43 anastasis-reducer next resources/03-backup.json $TFILE 2> /dev/null && exit_fail "Should have failed without challenges" 44 45 echo " OK" 46 47 48 echo -n "Test done authentication (next) ..." 49 anastasis-reducer next resources/04-backup.json "$TFILE" 50 51 STATE=$(jq -r -e .backup_state < "$TFILE") 52 if test "$STATE" != "POLICIES_REVIEWING" 53 then 54 exit_fail "Expected new state to be AUTHENTICATIONS_EDITING, got $STATE" 55 fi 56 57 ARRAY_LENGTH=`jq -r -e '.policies | length' < $TFILE` 58 if test $ARRAY_LENGTH -lt 3 59 then 60 exit_fail "Expected policy array length to be >= 3, got $ARRAY_LENGTH" 61 fi 62 63 echo " OK" 64 65 exit 0