blob: a3290d3e88d7771935fb8143fd61843839b8aabd [file] [log] [blame]
Jiri Simsaa942b752014-08-08 17:55:12 -07001#!/bin/bash
Asim Shankar76f431a2014-07-23 10:03:20 -07002
3# Test the identity command-line tool.
4#
5# This tests most operations of the identity command-line tool.
6# Not the "seekblessing" command yet, since that requires
7# starting a separate server.
8
Jiri Simsaf8727f22014-09-24 19:08:49 -07009source "${VEYRON_ROOT}/scripts/lib/shell_test.sh"
Asim Shankar76f431a2014-07-23 10:03:20 -070010
Jiri Simsaa942b752014-08-08 17:55:12 -070011main() {
12 # Build binaries.
13 cd "${TMPDIR}"
Jiri Simsad993b392014-09-29 21:22:00 -070014 veyron go build veyron.io/veyron/veyron/tools/identity || shell_test::fail "line ${LINENO}: failed to build identity"
Asim Shankar76f431a2014-07-23 10:03:20 -070015
Jiri Simsaa942b752014-08-08 17:55:12 -070016 ./identity print >/dev/null || shell_test::fail "line ${LINENO}: print failed"
17 ./identity generate >/dev/null || shell_test::fail "line ${LINENO}: generate failed"
18 ./identity generate root >root || shell_test::fail "line ${LINENO}: generate root failed"
Asim Shankar76f431a2014-07-23 10:03:20 -070019
Jiri Simsaa942b752014-08-08 17:55:12 -070020 export VEYRON_IDENTITY="root"
21
22 # Generate an identity and get it blessed by root using "identity bless"
23 local GOT=$(./identity generate ignoreme | ./identity bless - child | ./identity print - | awk '/Name/ {print $3}')
24 local WANT="root/child"
25 if [ "${GOT}" != "${WANT}" ]; then
Asim Shankar8ed43e52014-09-15 18:38:02 -070026 shell_test::fail "line ${LINENO}: Got ${GOT}, want ${WANT}"
Jiri Simsaa942b752014-08-08 17:55:12 -070027 fi
28
29 # Generate an identity and get it blessed by root using "identity bless --with"
30 ./identity generate other >other || shell_test::fail
31 GOT=$(./identity generate ignoreme | ./identity bless --with=other - child | ./identity print - | awk '/Name/ {print $3}')
32 WANT="unknown/other/child"
33 if [ "${GOT}" != "${WANT}" ]; then
Asim Shankar8ed43e52014-09-15 18:38:02 -070034 shell_test::fail "line ${LINENO}: Got ${GOT}, want ${WANT}"
Jiri Simsaa942b752014-08-08 17:55:12 -070035 fi
36
Asim Shankar8ed43e52014-09-15 18:38:02 -070037 # Test that previously generated identities can be interpreted
38 # (i.e., any changes to the Certificate or Signature scheme are backward compatible).
39 # To regenerate testdata:
40 # identity generate "root" >testdata/root.id
41 # identity generate "other" | VEYRON_IDENTITY=testdata/root.id identity bless - "blessed" >testdata/blessed.id
Asim Shankar45c89552014-09-18 10:58:10 -070042 local -r TESTDATA_DIR="${VEYRON_ROOT}/veyron/go/src/veyron.io/veyron/veyron/tools/identity/testdata"
Asim Shankar8ed43e52014-09-15 18:38:02 -070043 GOT=$(VEYRON_IDENTITY="${TESTDATA_DIR}/root.id" ./identity print | awk '/Name/ {print $3}')
44 WANT="root"
45 if [ "${GOT}" != "${WANT}" ]; then
46 shell_test::fail "line ${LINENO}: Got '${GOT}' from previously generated root.id, want '${WANT}'"
47 fi
48 GOT=$(VEYRON_IDENTITY="${TESTDATA_DIR}/root.id" ./identity print "${TESTDATA_DIR}/blessed.id" | awk '/Name/ {print $3}')
49 WANT="root/blessed"
50 if [ "${GOT}" != "${WANT}" ]; then
51 shell_test::fail "line ${LINENO}: Got '${GOT}' from previously generated blessed.id, want '${WANT}'"
52 fi
Jiri Simsaa942b752014-08-08 17:55:12 -070053 shell_test::pass
Asim Shankar76f431a2014-07-23 10:03:20 -070054}
55
Jiri Simsaa942b752014-08-08 17:55:12 -070056main "$@"