forked from mitre/saf-training-lab-environment
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test-lab.sh
executable file
·116 lines (98 loc) · 3.78 KB
/
test-lab.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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
#!/bin/bash
source ./set-prettyOutputVariables.sh
echo -e "${LINE_ASCII_CONSOLE}\n"
echo -e "${VERB}Verify the script returns the following information:
* A \"MITRE SAF\" version number.
* An \"InSpec\" version number.
* The Git integrity of the Heimdall Lite and SAF CLI repositories.
* A Node package installation verification for the the Heimdall Lite and SAF CLI repositories.
* Two running containers:
- nginx
- redhat
${RSET}"
echo -e "${LINE_ASCII_CONSOLE}\n"
echo -e "${VERB}Collecting verification information...${RSET}\n"
npm update -g @mitre/saf &> /dev/null
versionSaf=$(saf --version 2> /dev/null)
versionInspec=$(inspec --version 2> /dev/null)
containersRunning=$(docker ps)
containersMissing=''
verificationSuccessful=true
cd dev_repos/heimdall2 &> /dev/null
gitIntegrityHeimdall=$(git status)
yarnCheckHeimdall=$(yarn check --verify-tree)
cd ../saf &> /dev/null
gitIntegritySaf=$(git status)
yarnCheckSaf=$(yarn check --verify-tree)
cd ../.. &> /dev/null
if [ -z "${versionSaf}" ]
then
verificationSuccessful=false
statusSaf="${FAIL}\"saf\" is not installed.${RSET}"
else
statusSaf="${PASS}${versionSaf}${RSET}"
fi
if [ -z "${versionInspec}" ]
then
verificationSuccessful=false
statusInspec="${FAIL}\"inspec\" is not installed.${RSET}"
else
statusInspec="${PASS}${versionInspec}${RSET}"
fi
if ! echo "${gitIntegrityHeimdall}" | grep --silent --extended-regexp 'working tree clean'
then
verificationSuccessful=false
statusGitHeimdall="${FAIL}The Heimdall Lite repository has mismatched files.${RSET}"
else
statusGitHeimdall="${PASS}The Heimdall Lite repository is in sync with remote.${RSET}"
fi
if ! echo "${yarnCheckHeimdall}" | grep --silent --extended-regexp 'success Folder in sync'
then
verificationSuccessful=false
statusNodeHeimdall="${FAIL}The Heimdall Lite repository has mismatched Node packages.${RSET}"
else
statusNodeHeimdall="${PASS}The Heimdall Lite repository has correct Node packages.${RSET}"
fi
if ! echo "${gitIntegritySaf}" | grep --silent --extended-regexp 'working tree clean'
then
verificationSuccessful=false
statusGitSaf="${FAIL}The SAF CLI repository has mismatched files.${RSET}"
else
statusGitSaf="${PASS}The SAF CLI repository is in sync with remote.${RSET}"
fi
if ! echo "${yarnCheckSaf}" | grep --silent --extended-regexp 'success Folder in sync'
then
verificationSuccessful=false
statusNodeSaf="${FAIL}The SAF CLI repository has mismatched Node packages.${RSET}"
else
statusNodeSaf="${PASS}The SAF CLI repository has correct Node packages.${RSET}"
fi
if ! echo "${containersRunning}" | grep --silent --extended-regexp 'nginx'
then
verificationSuccessful=false
containersMissing="${containersMissing}The \"nginx\" container is missing.\n"
fi
if ! echo "${containersRunning}" | grep --silent --extended-regexp 'redhat8'
then
verificationSuccessful=false
containersMissing="${containersMissing}The \"redhat8\" container is missing.\n"
fi
echo -e "${HIGH}* MITRE SAF Version:${RSET} ${statusSaf}"
echo -e "${HIGH}* InSpec Version:${RSET} ${statusInspec}"
echo -e "${HIGH}* Docker is running the following container(s):${RSET}"
echo -e "${HIGH}* Heimdall repository integrity:${RSET} ${statusGitHeimdall}"
echo -e "${HIGH}* Heimdall Node verification:${RSET} ${statusNodeHeimdall}"
echo -e "${HIGH}* SAF CLI repository integrity:${RSET} ${statusGitSaf}"
echo -e "${HIGH}* SAF CLI Node verification:${RSET} ${statusNodeSaf}"
echo "${containersRunning}" | \
GREP_COLORS='mt=0;32' \
grep --color=always --extended-regexp \
'nginx$|redhat8$|$'
echo -e "${FAIL}${containersMissing}${RSET}"
echo -e "${LINE_ASCII_CONSOLE}\n"
if $verificationSuccessful
then
echo -e "${PASS}All verification tests completed successfully.${RSET}\n"
else
echo -e "${FAIL}One or more verification tests FAILED.${RSET}\n"
fi