-
Notifications
You must be signed in to change notification settings - Fork 29
/
Copy pathtest_mccf.sh
executable file
·90 lines (77 loc) · 2.61 KB
/
test_mccf.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
84
85
86
87
88
89
90
#!/bin/bash
set -euo pipefail
declare app_dir=$PWD # application folder for reference
declare certificate_dir="${app_dir}/workspace/mccf_certificates"
declare signing_cert=""
declare signing_key=""
declare interactive=0
function usage {
echo ""
echo "Open a network in mCCF and then run the tests."
echo ""
echo "usage: ./test_mccf.sh --address <ADDRESS> --signing-cert <CERT> --signing-key <CERT> [--interactive]"
echo ""
echo " --address string The address of the primary CCF node"
echo " --signing-cert string The signing certificate (member0)"
echo " --signing-key string The signing key (member0)"
echo " --interactive boolean Optional. Run in Demo mode"
echo ""
}
function failed {
printf "💥 Script failed: %s\n\n" "$1"
exit 1
}
# parse parameters
if [ $# -gt 7 ]; then
usage
exit 1
fi
while [ $# -gt 0 ]
do
case "$1" in
--address) address="$2"; shift 2;;
--signing-cert) signing_cert="$2"; shift 2;;
--signing-key) signing_key="$2"; shift 2;;
--interactive) interactive=1; shift;;
--help) usage; exit 0;;
*) usage; exit 1;;
esac
done
# validate parameters
if [ -z "${signing_cert}" ]; then
failed "You must supply --signing-cert"
fi
if [ -z "${signing_key}" ]; then
failed "You must supply --signing-key"
fi
if [ -z "$address" ]; then
failed "You must supply --address"
fi
server="https://${address}"
echo "💤 Getting the Service cert from $server"
# The node is not up yet and the certificate will not be created until it
# return 200. We can't pass in the ca_cert hence why we use -k
while [ "200" != "$(curl "$server/node/network" -k -s -o /dev/null -w %{http_code})" ]
do
sleep 1
done
echo "🎉 Got the Service certificate"
mkdir -p "${certificate_dir}"
certAsString=$(curl "$server/node/network" -k | jq -r .service_certificate)
# Convert string with \n into file with new lines
echo -e "${certAsString}" > "${certificate_dir}/service_cert.pem"
echo -e "${signing_cert}" > "${certificate_dir}/member0_cert.pem"
echo -e "${signing_key}" > "${certificate_dir}/member0_privk.pem"
"$app_dir/governance/scripts/setup_governance.sh" --nodeAddress "${address}" --certificate_dir "$certificate_dir"
testScript="$app_dir/test/test.sh"
if [ ! -f "$testScript" ]; then
echo "💥📂 Test file $testScript not found."
exit 1
fi
# build testScript command
testScript="${testScript} --nodeAddress ${address} --certificate_dir $certificate_dir"
if [ $interactive -eq 1 ]; then
testScript="${testScript} --interactive"
fi
# call testScript command
${testScript}