gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[taler-anastasis] 05/05: reducer testing


From: gnunet
Subject: [taler-anastasis] 05/05: reducer testing
Date: Mon, 23 Nov 2020 13:47:34 +0100

This is an automated email from the git hooks/post-receive script.

dennis-neufeld pushed a commit to branch master
in repository anastasis.

commit eff66d03ff4d49a1a30320779c7b656f71de89d2
Author: Dennis Neufeld <dennis.neufeld@students.bfh.ch>
AuthorDate: Mon Nov 23 13:47:24 2020 +0100

    reducer testing
---
 src/cli/Makefile.am                                |   5 +-
 .../test_anastasis_reducer_add_authentication.sh   | 116 +++++++++++++++++++++
 .../test_anastasis_reducer_done_authentication.sh  |  64 ++++++++++++
 ...test_anastasis_reducer_enter_user_attributes.sh |  21 ++--
 src/cli/test_anastasis_reducer_select_country.sh   |  15 +--
 5 files changed, 200 insertions(+), 21 deletions(-)

diff --git a/src/cli/Makefile.am b/src/cli/Makefile.am
index 3b9533b..d1769aa 100644
--- a/src/cli/Makefile.am
+++ b/src/cli/Makefile.am
@@ -10,11 +10,12 @@ if USE_COVERAGE
 endif
 
 check_SCRIPTS = \
-  test_reducer.sh \
   test_anastasis_reducer_initialize_state.sh \
   test_anastasis_reducer_select_continent.sh \
   test_anastasis_reducer_select_country.sh \
-  test_anastasis_reducer_enter_user_attributes.sh
+  test_anastasis_reducer_enter_user_attributes.sh \
+  test_anastasis_reducer_add_authentication.sh \
+  test_anastasis_reducer_done_authentication.sh
 
 
 AM_TESTS_ENVIRONMENT=export 
ANASTASIS_PREFIX=$${ANASTASIS_PREFIX:-@libdir@};export 
PATH=$${ANASTASIS_PREFIX:-@prefix@}/bin:$$PATH;unset XDG_DATA_HOME;unset 
XDG_CONFIG_HOME;
diff --git a/src/cli/test_anastasis_reducer_add_authentication.sh 
b/src/cli/test_anastasis_reducer_add_authentication.sh
new file mode 100755
index 0000000..353a460
--- /dev/null
+++ b/src/cli/test_anastasis_reducer_add_authentication.sh
@@ -0,0 +1,116 @@
+#!/bin/bash
+
+set -eu
+
+# Exit, with status code "skip" (no 'real' failure)
+function exit_skip() {
+    echo $1
+    exit 77
+}
+
+# Exit, with error message (hard failure)
+function exit_fail() {
+    echo $1
+    exit 1
+}
+
+# Cleanup to run whenever we exit
+function cleanup()
+{
+    for n in `jobs -p`
+    do
+        kill $n 2> /dev/null || true
+    done
+    rm -f $SFILE $TFILE $UFILE
+    wait
+}
+
+# Install cleanup handler (except for kill -9)
+SFILE=`mktemp test_reducer_stateXXXXXX`
+TFILE=`mktemp test_reducer_stateXXXXXX`
+UFILE=test_reducer_stateAESTATE
+# Tempfile used und deleted by other test
+VFILE=test_reducer_stateAESTATE_FINAL
+
+
+trap cleanup EXIT
+
+# Check we can actually run
+echo -n "Testing for jq"
+jq -h > /dev/null || exit_skip "jq required"
+echo " FOUND"
+
+echo " "
+echo "Beginning with actual reducer test"
+
+# Test add authentication in a backup state
+# First method
+echo " "
+echo "Test add authentication in a backup state"
+./anastasis-reducer -a \
+  '{"authentication_method": {
+    "method": "question",
+    "data": {
+      "question": "Whats your name?",
+      "answer": "Hans"
+    }}}' \
+  add_authentication $UFILE $SFILE
+
+STATE=`jq -r -e .backup_state < $SFILE`
+if test "$STATE" != "AUTHENTICATIONS_EDITING"
+then
+    exit_fail "Expected new state to be AUTHENTICATIONS_EDITING, got $STATE"
+fi
+
+ARRAY_LENGTH=`jq -r -e '.authentication_methods | length' < $SFILE`
+if test $ARRAY_LENGTH != 1
+then
+    exit_fail "Expected array length to be 1, got $ARRAY_LENGTH"
+fi
+
+#Second method
+./anastasis-reducer -a \
+  '{"authentication_method": {
+    "method": "question",
+    "data": {
+      "question": "How old are you?",
+      "answer": "123"
+    }}}' \
+  add_authentication $SFILE $TFILE
+
+STATE=`jq -r -e .backup_state < $TFILE`
+if test "$STATE" != "AUTHENTICATIONS_EDITING"
+then
+    exit_fail "Expected new state to be AUTHENTICATIONS_EDITING, got $STATE"
+fi
+
+ARRAY_LENGTH=`jq -r -e '.authentication_methods | length' < $TFILE`
+if test $ARRAY_LENGTH != 2
+then
+    exit_fail "Expected array length to be 2, got $ARRAY_LENGTH"
+fi
+
+#Third method
+touch $VFILE
+./anastasis-reducer -a \
+  '{"authentication_method": {
+    "method": "question",
+    "data": {
+      "question": "Where do you live?",
+      "answer": "Mars"
+    }}}' \
+  add_authentication $TFILE $VFILE
+
+STATE=`jq -r -e .backup_state < $VFILE`
+if test "$STATE" != "AUTHENTICATIONS_EDITING"
+then
+    exit_fail "Expected new state to be AUTHENTICATIONS_EDITING, got $STATE"
+fi
+
+ARRAY_LENGTH=`jq -r -e '.authentication_methods | length' < $VFILE`
+if test $ARRAY_LENGTH != 3
+then
+    exit_fail "Expected array length to be 3, got $ARRAY_LENGTH"
+fi
+
+exit 0
diff --git a/src/cli/test_anastasis_reducer_done_authentication.sh 
b/src/cli/test_anastasis_reducer_done_authentication.sh
new file mode 100755
index 0000000..eb4e6ec
--- /dev/null
+++ b/src/cli/test_anastasis_reducer_done_authentication.sh
@@ -0,0 +1,64 @@
+#!/bin/bash
+
+set -eu
+
+# Exit, with status code "skip" (no 'real' failure)
+function exit_skip() {
+    echo $1
+    exit 77
+}
+
+# Exit, with error message (hard failure)
+function exit_fail() {
+    echo $1
+    exit 1
+}
+
+# Cleanup to run whenever we exit
+function cleanup()
+{
+    for n in `jobs -p`
+    do
+        kill $n 2> /dev/null || true
+    done
+    rm -f $UFILE
+    wait
+}
+
+# Install cleanup handler (except for kill -9)
+UFILE=test_reducer_stateAESTATE_FINAL
+# Tempfile used und deleted by other test
+VFILE=test_reducer_statePRSTATE
+
+
+trap cleanup EXIT
+
+# Check we can actually run
+echo -n "Testing for jq"
+jq -h > /dev/null || exit_skip "jq required"
+echo " FOUND"
+
+echo " "
+echo "Beginning with actual reducer test"
+
+# Test done authentication in a backup state
+echo " "
+echo "Test done authentication (next) in a backup state"
+touch $VFILE
+./anastasis-reducer -a \
+  '{}' \
+  next $UFILE $VFILE
+
+STATE=`jq -r -e .backup_state < $VFILE`
+if test "$STATE" != "POLICIES_REVIEWING"
+then
+    exit_fail "Expected new state to be AUTHENTICATIONS_EDITING, got $STATE"
+fi
+
+ARRAY_LENGTH=`jq -r -e '.policies | length' < $VFILE`
+if test $ARRAY_LENGTH >= 3
+then
+    exit_fail "Expected policy array to be >= 3, got $ARRAY_LENGTH"
+fi
+
+exit 0
diff --git a/src/cli/test_anastasis_reducer_enter_user_attributes.sh 
b/src/cli/test_anastasis_reducer_enter_user_attributes.sh
index fffc87b..7a85d8e 100755
--- a/src/cli/test_anastasis_reducer_enter_user_attributes.sh
+++ b/src/cli/test_anastasis_reducer_enter_user_attributes.sh
@@ -21,13 +21,14 @@ function cleanup()
     do
         kill $n 2> /dev/null || true
     done
-    rm -f $SFILE $TFILE
+    rm -f $UFILE
     wait
 }
 
 # Install cleanup handler (except for kill -9)
-SFILE=`mktemp test_reducer_stateXXXXXX`
-TFILE=`mktemp test_reducer_stateXXXXXX`
+UFILE=test_reducer_stateUACSTATE
+# Tempfile used und deleted by other test
+VFILE=test_reducer_stateAESTATE
 
 trap cleanup EXIT
 
@@ -42,13 +43,7 @@ echo "Beginning with actual reducer test"
 # Test user attributes collection in a backup state
 echo " "
 echo "Test user attributes collection in a backup state"
-./anastasis-reducer -b $SFILE
-./anastasis-reducer -a '{"continent": "Europe"}' select_continent $SFILE $TFILE
-./anastasis-reducer -a \
-  '{"country": "Switzerland", 
-    "country_code": "ch", 
-    "currency":"TESTKUDOS"}' \
-  select_country $TFILE $SFILE
+touch $VFILE
 ./anastasis-reducer -a \
   '{"identity_attributes": {
     "full_name": "Max Musterman",
@@ -56,15 +51,15 @@ echo "Test user attributes collection in a backup state"
     "birth_year": 2000 ,
     "birth_month": 1, 
     "birth_day": 1}}' \
-  enter_user_attributes $SFILE $TFILE
+  enter_user_attributes $UFILE $VFILE
 
-STATE=`jq -r -e .backup_state < $TFILE`
+STATE=`jq -r -e .backup_state < $VFILE`
 if test "$STATE" != "AUTHENTICATIONS_EDITING"
 then
     exit_fail "Expected new state to be AUTHENTICATIONS_EDITING, got $STATE"
 fi
 
-SELECTED_COUNTRY=`jq -r -e .selected_country < $TFILE`
+SELECTED_COUNTRY=`jq -r -e .selected_country < $VFILE`
 if test "$SELECTED_COUNTRY" != "ch"
 then
     exit_fail "Expected selected country to be ch, got $SELECTED_COUNTRY"
diff --git a/src/cli/test_anastasis_reducer_select_country.sh 
b/src/cli/test_anastasis_reducer_select_country.sh
index ea2049f..4a060ca 100755
--- a/src/cli/test_anastasis_reducer_select_country.sh
+++ b/src/cli/test_anastasis_reducer_select_country.sh
@@ -32,6 +32,8 @@ CONF_3=`mktemp test_reducerXXXXXX_3.conf`
 CONF_4=`mktemp test_reducerXXXXXX_4.conf`
 SFILE=`mktemp test_reducer_stateXXXXXX`
 TFILE=`mktemp test_reducer_stateXXXXXX`
+# Tempfile used und deleted by other test
+UFILE=test_reducer_stateUACSTATE
 
 trap cleanup EXIT
 
@@ -102,37 +104,38 @@ echo " "
 echo "Test country selection in a backup state"
 ./anastasis-reducer -b $SFILE
 ./anastasis-reducer -a '{"continent": "Europe"}' select_continent $SFILE $TFILE
+touch $UFILE
 ./anastasis-reducer -a \
   '{"country": "Switzerland", 
     "country_code": "ch", 
     "currency":"TESTKUDOS"}' \
-  select_country $TFILE $SFILE
+  select_country $TFILE $UFILE
 
-STATE=`jq -r -e .backup_state < $SFILE`
+STATE=`jq -r -e .backup_state < $UFILE`
 if test "$STATE" != "USER_ATTRIBUTES_COLLECTING"
 then
     exit_fail "Expected new state to be USER_ATTRIBUTES_COLLECTING, got $STATE"
 fi
 
-SELECTED_COUNTRY=`jq -r -e .selected_country < $SFILE`
+SELECTED_COUNTRY=`jq -r -e .selected_country < $UFILE`
 if test "$SELECTED_COUNTRY" != "ch"
 then
     exit_fail "Expected selected country to be ch, got $SELECTED_COUNTRY"
 fi
 
-SELECTED_CURRENCY=`jq -r -e .currency < $SFILE`
+SELECTED_CURRENCY=`jq -r -e .currency < $UFILE`
 if test "$SELECTED_CURRENCY" != "TESTKUDOS"
 then
     exit_fail "Expected selected currency to be TESTKUDOS, got 
$SELECTED_CURRENCY"
 fi
 
-REQ_ATTRIBUTES=`jq -r -e .required_attributes < $SFILE`
+REQ_ATTRIBUTES=`jq -r -e .required_attributes < $UFILE`
 if test "$REQ_ATTRIBUTES" == NULL
 then
     exit_fail "Expected required attributes array not to be NULL"
 fi
 
-AUTH_PROVIDERS=`jq -r -e .authentication_providers < $SFILE`
+AUTH_PROVIDERS=`jq -r -e .authentication_providers < $UFILE`
 if test "$AUTH_PROVIDERS" == NULL
 then
     exit_fail "Expected authentication_providers array not to be NULL"

-- 
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]