forked from microsoft/ccf-app-samples
-
Notifications
You must be signed in to change notification settings - Fork 1
/
test.sh
executable file
·83 lines (68 loc) · 2.36 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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#!/bin/bash
set -euo pipefail
declare nodeAddress=""
declare certificate_dir=""
declare interactive=0
function usage {
echo ""
echo "Test this sample."
echo ""
echo "usage: ./test.sh --nodeAddress <IPADDRESS:PORT> --certificate_dir <workspace/sandbox_common> [--interactive]"
echo ""
echo " --nodeAddress string The IP and port of the primary CCF node"
echo " --certificate_dir string The directory where the certificates are"
echo " --interactive boolean Optional. Run in Demo mode"
echo ""
}
function failed {
printf "💥 Script failed: %s\n\n" "$1"
exit 1
}
# parse parameters
if [ $# -gt 5 ]; then
usage
exit 1
fi
while [ $# -gt 0 ]
do
name="${1/--/}"
name="${name/-/_}"
case "--$name" in
--nodeAddress) nodeAddress="$2"; shift;;
--certificate_dir) certificate_dir="$2"; shift;;
--interactive) interactive=1;;
--help) usage; exit 0;;
--) shift;;
esac
shift;
done
# validate parameters
if [ -z "$nodeAddress" ]; then
failed "You must supply --nodeAddress"
fi
if [ -z "$certificate_dir" ]; then
failed "You must supply --certificate_dir"
fi
server="https://${nodeAddress}"
echo "📂 Directory for certificates: ${certificate_dir}"
only_status_code="-s -o /dev/null -w %{http_code}"
echo "💤 Waiting for the app frontend..."
# Using the same way as https://github.com/microsoft/CCF/blob/1f26340dea89c06cf615cbd4ec1b32665840ef4e/tests/start_network.py#L94
# There is a side effect here in the case of the sandbox as it creates the 'workspace/sandbox_common' everytime
# it starts up. The following condition not only checks that this pem file has been created, it also checks it
# is valid. Don't be caught out by the folder existing from a previous run.
while [ "200" != "$(curl "$server/app/commit" --cacert "${certificate_dir}/service_cert.pem" $only_status_code)" ]
do
sleep 1
done
# DataReconciliation test flow goes through TypeScript application located in ./test/e2e-test
echo "Running TypeScript flow..."
# adding read permission to .pem files so node application can have access
sudo chmod +r ${certificate_dir}/*.pem
# Calling npm command with the necessary variables
export SERVER=${server}
export CERTS_FOLDER=${certificate_dir}
export INTERACTIVE_MODE=${interactive}
npm run e2e-test
printf "\n\n🏁 Test Completed...\n"
exit 0