Fix Sonobuoy systemd-image for k8 1.18
[validation.git] / tests / os / vuls / vuls.robot
1 ##############################################################################
2 # Copyright (c) 2019 AT&T Intellectual Property.                             #
3 # Copyright (c) 2019 Nokia.                                                  #
4 #                                                                            #
5 # Licensed under the Apache License, Version 2.0 (the "License");            #
6 # you maynot use this file except in compliance with the License.            #
7 #                                                                            #
8 # You may obtain a copy of the License at                                    #
9 #       http://www.apache.org/licenses/LICENSE-2.0                           #
10 #                                                                            #
11 # Unless required by applicable law or agreed to in writing, software        #
12 # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT  #
13 # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.           #
14 # See the License for the specific language governing permissions and        #
15 # limitations under the License.                                             #
16 ##############################################################################
17
18 *** Settings ***
19 Library           SSHLibrary
20 Library           OperatingSystem
21 Library           BuiltIn
22 Suite Setup       Open Connection And Log In
23 Suite Teardown    Close All Connections
24
25 *** Test Cases ***
26 Run Vuls test
27     Set Environment Variable  GOROOT  /root/go
28     Set Environment Variable  GOPATH  /root/go/src/github.com
29     Set Environment Variable  PATH  /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/root/go/bin:/root/go/src/github.com/bin
30     Set Environment Variable  LC_ALL  en_US.UTF-8
31     Set Environment Variable  LANG  en_US.UTF-8
32
33     ${rc} =  Run And Return Rc  install -D ${CURDIR}/config /root/.ssh/
34     Should Be Equal As Integers  ${rc}  0
35
36     ${rc} =  Run And Return Rc  sed -i -e 's/HOST/${HOST}/g' -e 's/USERNAME/${USERNAME}/g' ${CURDIR}/config.toml
37     Should Be Equal As Integers  ${rc}  0
38
39     ${rc} =  Run And Return Rc  tar xvzf ${CURDIR}/db.tar.gz -C ${CURDIR}
40     Should Be Equal As Integers  ${rc}  0
41
42     ${os} =  SSHLibrary.Execute Command   source /etc/os-release && echo $ID
43
44     Run Keyword IF  '${SSH_KEYFILE}' == 'None'  Create ssh_keyfile
45
46     ${rc} =  Run And Return Rc  vuls scan -config ${CURDIR}/config.toml
47     Should Be Equal As Integers  ${rc}  0
48
49     Run Keyword IF  '${os}' == 'ubuntu'  Run vuls for ubuntu  ELSE IF  '${os}' == 'centos'  Run vuls for centos  ELSE  FAIL  Distro '${os}' not supported
50
51     ${status} =  Evaluate  "Total: 0" in """${LOG}"""
52     Run Keyword If  '${status}' == 'False'  FAIL  Vulnerabilities discovered
53     ...                     non-critical
54
55     Run Keyword IF  '${SSH_KEYFILE}' == 'None'  Cleanup ssh
56
57 *** Keywords ***
58 Run vuls for ubuntu
59     ${os_version} =  SSHLibrary.Execute Command  source /etc/os-release && echo $VERSION_ID | cut -d '.' -f1
60
61     ${rc}  ${output} =  Run And Return Rc And Output  vuls report -config ${CURDIR}/config.toml -cvedb-sqlite3-path=${CURDIR}/cve.sqlite3 -ovaldb-sqlite3-path=${CURDIR}/oval_ubuntu_${os_version}.sqlite3
62     Should Be Equal As Integers  ${rc}  0
63     Append To File  ${LOG_PATH}/vuls.log  ${output}${\n}
64     Set Global Variable  ${LOG}  ${output}
65
66 Run vuls for centos
67     ${os_version} =  SSHLibrary.Execute Command  source /etc/os-release && echo $VERSION_ID | cut -d '.' -f1
68
69     ${rc}  ${output} =  Run And Return Rc And Output  vuls report -config ${CURDIR}/config.toml -cvedb-sqlite3-path=${CURDIR}/cve.sqlite3 -ovaldb-sqlite3-path=${CURDIR}/oval_centos_${os_version}.sqlite3 -gostdb-sqlite3-path=${CURDIR}/gost_centos.sqlite3
70     Should Be Equal As Integers  ${rc}  0
71     Append To File  ${LOG_PATH}/vuls.log  ${output}${\n}
72     Set Global Variable  ${LOG}  ${output}
73
74 Create ssh_keyfile
75     ${rc} =  Run And Return Rc  ssh-keygen -t rsa -b 4096 -f /root/.ssh/id_rsa -N ""
76     Should Be Equal As Integers  ${rc}  0
77
78     ${rc} =  Run and Return Rc  sshpass -p '${PASSWORD}' ssh-copy-id -i /root/.ssh/id_rsa.pub '${USERNAME}'@'${HOST}'
79     Should Be Equal As Integers  ${rc}  0
80
81 Cleanup ssh
82     ${rc}  ${idssh} =  Run And Return Rc And Output  cat /root/.ssh/id_rsa.pub
83     Should Be Equal As Integers  ${rc}  0
84     ${rc} =  Run And Return Rc  ssh '${USERNAME}'@'${HOST}' "sed -i 's#${idssh}##' ~/.ssh/authorized_keys"
85     Should Be Equal As Integers  ${rc}  0
86
87 Open Connection And Log In
88     Open Connection  ${HOST}
89     Run Keyword IF  '${SSH_KEYFILE}' != 'None'  Login With Public Key  ${USERNAME}  ${SSH_KEYFILE}  ELSE IF  '${PASSWORD}' != 'None'  Login  ${USERNAME}  ${PASSWORD}  ELSE  FAIL