generated from mitre/saf-training-lab-environment
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test-lab.sh
executable file
·73 lines (57 loc) · 1.89 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
#!/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.
* 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
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 "${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 "${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