update velocity always at the end of iteration
[oweals/gnunet.git] / src / credential / test_credential_verify_simple.sh
1 #!/bin/bash
2 trap "gnunet-arm -e -c test_credential_lookup.conf" SIGINT
3
4 LOCATION=$(which gnunet-config)
5 if [ -z $LOCATION ]
6 then
7   LOCATION="gnunet-config"
8 fi
9 $LOCATION --version 1> /dev/null
10 if test $? != 0
11 then
12         echo "GNUnet command line tools cannot be found, check environmental variables PATH and GNUNET_PREFIX"
13         exit 77
14 fi
15
16 rm -rf `gnunet-config -c test_credential_lookup.conf -s PATHS -o GNUNET_HOME -f`
17
18 #  (3) Isser.user -> Subject
19
20
21 which timeout &> /dev/null && DO_TIMEOUT="timeout 30"
22 gnunet-arm -s -c test_credential_lookup.conf
23 gnunet-identity -C testissuer -c test_credential_lookup.conf
24 gnunet-identity -C testsubject -c test_credential_lookup.conf
25
26 TEST_ATTR="user"
27 SUBJECT_KEY=$(gnunet-identity -d -c test_credential_lookup.conf | grep testsubject | awk '{print $3}')
28 ISSUER_KEY=$(gnunet-identity -d -c test_credential_lookup.conf | grep testissuer | awk '{print $3}')
29 CRED=`$DO_TIMEOUT gnunet-credential --issue --ego=testissuer --subject=$SUBJECT_KEY --attribute=$TEST_ATTR --ttl=5m -c test_credential_lookup.conf`
30
31 TEST_CREDENTIAL="t1"
32 gnunet-namestore -p -z testsubject -a -n $TEST_CREDENTIAL -t CRED -V "$CRED" -e 5m -c test_credential_lookup.conf
33
34 CREDS=`$DO_TIMEOUT gnunet-credential --collect --issuer=$ISSUER_KEY --attribute=$TEST_ATTR --ego=testsubject -c test_credential_lookup.conf | paste -d, -s`
35
36
37 #TODO2 Add -z swich like in gnunet-gns
38 #RES_CRED=`$DO_TIMEOUT gnunet-credential --verify --issuer=$ISSUER_KEY --attribute="$TEST_ATTR" --subject=$SUBJECT_KEY --credential=$TEST_CREDENTIAL -c test_credential_lookup.conf`
39 RES_CRED=`gnunet-credential --verify --issuer=$ISSUER_KEY --attribute=$TEST_ATTR --subject=$SUBJECT_KEY --credential="$CREDS" -c test_credential_lookup.conf`
40
41 #TODO cleanup properly
42 gnunet-namestore -z testsubject -d -n $TEST_CREDENTIAL -t CRED -e never -c test_credential_lookup.conf
43 gnunet-identity -D testsubject -c test_credential_lookup.conf
44 gnunet-arm -e -c test_credential_lookup.conf
45 #TODO3 proper test
46 if [ "$RES_CRED" != "Failed." ]
47 then
48   exit 0
49 else
50   echo "FAIL: Failed to verify credential."
51   exit 1
52 fi