Fix Sonobuoy systemd-image for k8 1.18
[validation.git] / tests / os / vuls / vuls.robot
index d79fab9..3118021 100644 (file)
@@ -25,8 +25,8 @@ Suite Teardown    Close All Connections
 *** Test Cases ***
 Run Vuls test
     Set Environment Variable  GOROOT  /root/go
-    Set Environment Variable  GOPATH  /root/go/src
-    Set Environment Variable  PATH  /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/root/go/bin:/root/go/src/bin
+    Set Environment Variable  GOPATH  /root/go/src/github.com
+    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
     Set Environment Variable  LC_ALL  en_US.UTF-8
     Set Environment Variable  LANG  en_US.UTF-8
 
@@ -41,7 +41,9 @@ Run Vuls test
 
     ${os} =  SSHLibrary.Execute Command   source /etc/os-release && echo $ID
 
-    ${rc} =  Run And Return Rc  vuls scan -config ${CURDIR}/config.toml -ssh-config
+    Run Keyword IF  '${SSH_KEYFILE}' == 'None'  Create ssh_keyfile
+
+    ${rc} =  Run And Return Rc  vuls scan -config ${CURDIR}/config.toml
     Should Be Equal As Integers  ${rc}  0
 
     Run Keyword IF  '${os}' == 'ubuntu'  Run vuls for ubuntu  ELSE IF  '${os}' == 'centos'  Run vuls for centos  ELSE  FAIL  Distro '${os}' not supported
@@ -50,6 +52,8 @@ Run Vuls test
     Run Keyword If  '${status}' == 'False'  FAIL  Vulnerabilities discovered
     ...                     non-critical
 
+    Run Keyword IF  '${SSH_KEYFILE}' == 'None'  Cleanup ssh
+
 *** Keywords ***
 Run vuls for ubuntu
     ${os_version} =  SSHLibrary.Execute Command  source /etc/os-release && echo $VERSION_ID | cut -d '.' -f1
@@ -60,11 +64,26 @@ Run vuls for ubuntu
     Set Global Variable  ${LOG}  ${output}
 
 Run vuls for centos
-    ${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.sqlite3 -gostdb-sqlite3-path=${CURDIR}/gost_centos.sqlite3
+    ${os_version} =  SSHLibrary.Execute Command  source /etc/os-release && echo $VERSION_ID | cut -d '.' -f1
+
+    ${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
     Should Be Equal As Integers  ${rc}  0
     Append To File  ${LOG_PATH}/vuls.log  ${output}${\n}
     Set Global Variable  ${LOG}  ${output}
 
+Create ssh_keyfile
+    ${rc} =  Run And Return Rc  ssh-keygen -t rsa -b 4096 -f /root/.ssh/id_rsa -N ""
+    Should Be Equal As Integers  ${rc}  0
+
+    ${rc} =  Run and Return Rc  sshpass -p '${PASSWORD}' ssh-copy-id -i /root/.ssh/id_rsa.pub '${USERNAME}'@'${HOST}'
+    Should Be Equal As Integers  ${rc}  0
+
+Cleanup ssh
+    ${rc}  ${idssh} =  Run And Return Rc And Output  cat /root/.ssh/id_rsa.pub
+    Should Be Equal As Integers  ${rc}  0
+    ${rc} =  Run And Return Rc  ssh '${USERNAME}'@'${HOST}' "sed -i 's#${idssh}##' ~/.ssh/authorized_keys"
+    Should Be Equal As Integers  ${rc}  0
+
 Open Connection And Log In
     Open Connection  ${HOST}
-    Login With Public Key  ${USERNAME}  ${SSH_KEYFILE}
+    Run Keyword IF  '${SSH_KEYFILE}' != 'None'  Login With Public Key  ${USERNAME}  ${SSH_KEYFILE}  ELSE IF  '${PASSWORD}' != 'None'  Login  ${USERNAME}  ${PASSWORD}  ELSE  FAIL