-add tests
[oweals/gnunet.git] / src / credential / test_credential_issue.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 #  (1) PKEY1.user -> PKEY2.resu.user
19 #  (2) PKEY2.resu -> PKEY3
20 #  (3) PKEY3.user -> PKEY4
21
22
23 which timeout &> /dev/null && DO_TIMEOUT="timeout 30"
24
25 TEST_ATTR="test"
26 gnunet-arm -s -c test_credential_lookup.conf
27 gnunet-identity -C testissuer -c test_credential_lookup.conf
28 gnunet-identity -C testsubject -c test_credential_lookup.conf
29 SUBJECT_KEY=$(gnunet-identity -d -c test_credential_lookup.conf | grep testsubject | awk '{print $3}')
30 ISSUER_KEY=$(gnunet-identity -d -c test_credential_lookup.conf | grep testissuer | awk '{print $3}')
31 EXPECTED="$SUBJECT_KEY $ISSUER_KEY $TEST_ATTR"
32 #TODO1 Get credential and store it with subject (3)
33 CRED=`$DO_TIMEOUT gnunet-credential --issue --ego=testissuer --subject=$SUBJECT_KEY --attribute=$TEST_ATTR -c test_credential_lookup.conf`
34
35 gnunet-arm -e -c test_credential_lookup.conf
36
37 if [ "$EXPECTED" == "$CRED" ]
38 then
39   exit 0
40 else
41   echo "FAIL: Failed to issue credential, got $CRED."
42   exit 1
43 fi