-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.sh
executable file
·45 lines (35 loc) · 1.26 KB
/
test.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#!/bin/bash
set -euxo pipefail
TESTDIR="./testtmp"
KEYSET="${TESTDIR}/ks.pb"
PRIV="${TESTDIR}/priv.pb"
PUB="${TESTDIR}/pub.pb"
cleanup() {
exit_status=$?
rm -rf ${TESTDIR}
exit "$exit_status"
}
trap cleanup EXIT
mkdir "${TESTDIR}"
go build -o "${TESTDIR}" ./...
echo "Generating a new key"
"${TESTDIR}/tokenpb" gen-key --subject "jdtw" --pub "${PUB}" --priv "${PRIV}" | yq -P
"${TESTDIR}/tokenpb" dump-pub "${PUB}" | yq -P
"${TESTDIR}/tokenpb" dump-priv "${PRIV}" | yq -P
echo "Creating new keyset..."
"${TESTDIR}/tokenpb" add-key --pub "${PUB}" "${KEYSET}"
"${TESTDIR}/tokenpb" dump-keyset "${KEYSET}" | yq -P
echo "Reading from stdin..."
"${TESTDIR}/tokenpb" dump-pub < "${PUB}" | yq -P
"${TESTDIR}/tokenpb" dump-priv < "${PRIV}" | yq -P
"${TESTDIR}/tokenpb" dump-keyset < "${KEYSET}" | yq -P
echo "Signing and verifying a token..."
"${TESTDIR}/tokenpb" sign-token --resource "resource" "${PRIV}" | \
"${TESTDIR}/tokenpb" verify-token --resource "resource" "${KEYSET}" | \
"${TESTDIR}/tokenpb" parse-token | yq -P
echo "Removing a key from the keyset..."
key_id=$("${TESTDIR}/tokenpb" dump-pub --id "${PUB}")
"${TESTDIR}/tokenpb" remove-key --id "${key_id}" "${KEYSET}"
result=$("${TESTDIR}/tokenpb" dump-keyset "${KEYSET}")
test "${result}" = "{}"
echo "Tests pass!"