aboutsummaryrefslogtreecommitdiff
path: root/src/cli/test_anastasis_reducer_done_policy_review.sh
diff options
context:
space:
mode:
Diffstat (limited to 'src/cli/test_anastasis_reducer_done_policy_review.sh')
-rwxr-xr-xsrc/cli/test_anastasis_reducer_done_policy_review.sh105
1 files changed, 105 insertions, 0 deletions
diff --git a/src/cli/test_anastasis_reducer_done_policy_review.sh b/src/cli/test_anastasis_reducer_done_policy_review.sh
new file mode 100755
index 0000000..7052067
--- /dev/null
+++ b/src/cli/test_anastasis_reducer_done_policy_review.sh
@@ -0,0 +1,105 @@
1#!/bin/bash
2
3set -eu
4
5# Exit, with status code "skip" (no 'real' failure)
6function exit_skip() {
7 echo " SKIP: $1"
8 exit 77
9}
10
11# Exit, with error message (hard failure)
12function exit_fail() {
13 echo " ERROR: $1"
14 exit 1
15}
16
17# Cleanup to run whenever we exit
18function 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)
29TFILE=`mktemp test_reducer_stateXXXXXX`
30trap cleanup EXIT
31
32
33# Check we can actually run
34echo -n "Testing for jq ..."
35jq -h > /dev/null || exit_skip "jq required"
36echo " FOUND"
37
38echo -n "Testing for anastasis-reducer ..."
39anastasis-reducer -h > /dev/null || exit_skip "anastasis-reducer required"
40echo " FOUND"
41
42echo -n "Test done policy review (next) in a backup state ..."
43anastasis-reducer next resources/05-backup.json $TFILE
44
45STATE=`jq -r -e .backup_state < $TFILE`
46if test "$STATE" != "SECRET_EDITING"
47then
48 exit_fail "Expected new state to be 'SECRET_EDITING', got '$STATE'"
49fi
50
51ARRAY_LENGTH=`jq -r -e '.authentication_methods | length' < $TFILE`
52if test $ARRAY_LENGTH -lt 3
53then
54 exit_fail "Expected auth methods array length to be >= 3, got $ARRAY_LENGTH"
55fi
56
57ARRAY_LENGTH=`jq -r -e '.policies | length' < $TFILE`
58if test $ARRAY_LENGTH -lt 3
59then
60 exit_fail "Expected policies array length to be >= 3, got $ARRAY_LENGTH"
61fi
62
63echo " OK"
64
65
66
67echo -n "Test adding policy ..."
68anastasis-reducer -a \
69 '{ "policy" : [
70 { "authentication_method" : 1,
71 "provider" : "http://localhost:8088/" },
72 { "authentication_method" : 1,
73 "provider" : "http://localhost:8089/" }
74 ] }' \
75 add_policy \
76 resources/05-backup.json \
77 $TFILE 2> /dev/null
78
79ARRAY_LENGTH=`jq -r -e '.policies | length' < $TFILE`
80if test $ARRAY_LENGTH -lt 4
81then
82 exit_fail "Expected policy array length to be >= 4, got $ARRAY_LENGTH"
83fi
84
85echo " OK"
86
87
88echo -n "Test deleting policy ..."
89anastasis-reducer -a \
90 '{ "policy_index" : 2 }' \
91 delete_policy \
92 resources/05-backup.json \
93 $TFILE 2> /dev/null
94
95ARRAY_LENGTH=`jq -r -e '.policies | length' < $TFILE`
96if test $ARRAY_LENGTH -ge 3
97then
98 exit_fail "Expected policy array length to be < 3, got $ARRAY_LENGTH"
99fi
100
101echo " OK"
102
103
104
105exit 0