test_anastasis_reducer_done_policy_review.sh (2275B)
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 rm -f $TFILE 26 wait 27 } 28 29 # Install cleanup handler (except for kill -9) 30 TFILE=`mktemp test_reducer_stateXXXXXX` 31 trap cleanup EXIT 32 33 34 # Check we can actually run 35 echo -n "Testing for jq ..." 36 jq -h > /dev/null || exit_skip "jq required" 37 echo " FOUND" 38 39 echo -n "Testing for anastasis-reducer ..." 40 anastasis-reducer -h > /dev/null || exit_skip "anastasis-reducer required" 41 echo " FOUND" 42 43 echo -n "Test done policy review (next) in a backup state ..." 44 anastasis-reducer next resources/05-backup.json $TFILE 45 46 STATE=`jq -r -e .backup_state < $TFILE` 47 if test "$STATE" != "SECRET_EDITING" 48 then 49 exit_fail "Expected new state to be 'SECRET_EDITING', got '$STATE'" 50 fi 51 52 ARRAY_LENGTH=`jq -r -e '.authentication_methods | length' < $TFILE` 53 if test $ARRAY_LENGTH -lt 3 54 then 55 exit_fail "Expected auth methods array length to be >= 3, got $ARRAY_LENGTH" 56 fi 57 58 ARRAY_LENGTH=`jq -r -e '.policies | length' < $TFILE` 59 if test $ARRAY_LENGTH -lt 3 60 then 61 exit_fail "Expected policies array length to be >= 3, got $ARRAY_LENGTH" 62 fi 63 64 echo " OK" 65 66 67 68 echo -n "Test adding policy ..." 69 anastasis-reducer -a \ 70 '{ "policy" : [ 71 { "authentication_method" : 1, 72 "provider" : "http://localhost:8088/" }, 73 { "authentication_method" : 1, 74 "provider" : "http://localhost:8089/" } 75 ] }' \ 76 add_policy \ 77 resources/05-backup.json \ 78 $TFILE 2> /dev/null 79 80 ARRAY_LENGTH=`jq -r -e '.policies | length' < $TFILE` 81 if test $ARRAY_LENGTH -lt 4 82 then 83 exit_fail "Expected policy array length to be >= 4, got $ARRAY_LENGTH" 84 fi 85 86 echo " OK" 87 88 89 echo -n "Test deleting policy ..." 90 anastasis-reducer -a \ 91 '{ "policy_index" : 2 }' \ 92 delete_policy \ 93 resources/05-backup.json \ 94 $TFILE 2> /dev/null 95 96 ARRAY_LENGTH=`jq -r -e '.policies | length' < $TFILE` 97 if test $ARRAY_LENGTH -ge 3 98 then 99 exit_fail "Expected policy array length to be < 3, got $ARRAY_LENGTH" 100 fi 101 102 echo " OK" 103 104 105 106 exit 0