We already know how to setup tests with ServerSpec and Testinfra in Quick start for ServerSpec and Testinfra, also comparison of them and Quick start for integrating ZAP into CI. Now, let’s see how to integrate them with CentOS 7 Minimal.
Prerequisite:
Install CentOS 7 Minimal successfully with root user setup and login.
Enable network on CentOS 7 Minimal following this article.
The detailed steps are:
1) Open Network Manager through
nmtui
;2) Choose “Edit connection” and press Enter (Use TAB button for choosing options);
3) Choose your network interfaces and click “Edit”;
4) Choose “Automatic” in “IPv4 CONFIGURATION” and check “Automatically connect” checkbox, then press “OK” to quit from Network Manager;
5) Reset network services through
service network restart
.Adjust the screen resolution following this article.
The detailed steps are:
1) Edit GRUB file:
vi /etc/default/grub
2) Append
vga=792
to the lineGRUB_CMDLINE_LINUX="crashkernel=auto rd.lvm.lv=cl/root rd.lvm.lv=cl/swap rhgb quiet
,and you will have
GRUB_CMDLINE_LINUX="crashkernel=auto rd.lvm.lv=cl/root rd.lvm.lv=cl/swap rhgb quiet vga=792
;Check for the detailed GRUB VGA Modes, or scroll down to the bottom of this article.
3) Add this change to GRUB configuration:
grub2-mkconfig -o /boot/grub2/grub.cfg
4) Reboot to take effect:
reboot
.Add a Yum source and update.
12yum install epel-releaseyum -y updateConfigure ssh key to connect server easily.
- Generate ssh key:
ssh-keygen -t rsa
- Copy ssh public key to server:
ssh-copy-id -i ~/.ssh/id_rsa.pub username@server
Add following lines to ~/.ssh/config.
12Host serverUser username
- Generate ssh key:
Quick start for ServerSpec:
Install Ruby.
yum install ruby
Install RubyGems.
yum install rubygems
Install Rake.
gem install rake
Install ServerSpec.
gem install serverspec
Initial ServerSpec folder with basic settings. Please note the server will be set in this step.
serverspec-init
Write and run the ServerSpec script according to its API document.
You can reference the script here.
Using
rake spec
under the test folder to run and check the result.To run specific test rather than the entire test suite.
Using
rake spec spec/host_server/sample_spec.rb
under the test folder to run and check the result.
Quick Start for Testinfra:
Python 2.7 is installed by default, so we just need to install Pip.
-y install python-pip 1pip install --upgrade pipInstall Testinfra and Paramiko.
pip install testinfra
pip install paramiko
Write and run the Testinfra script according to its API document.
You can reference the script here.
Using
testinfra testinfra_test.py
to run and check the result.Some useful arguments we can use to make the test result more clear.
Instead of using
testinfra testinfra_test.py
directly, we can add some arguments, such as-q
,-s
,--disable-warnings
and--junit-xml
.- The argument
-q
will run Testinfra in quiet mode, with less info exposed - The argument
-s
will let Testinfra capture No pre-test info - The argument
--disable-warnings
will disable warnings during Testinfra runs - The argument
--junit-xml
will export Testinfra test result into a xml file
After adding those arguments, the command should be look like
testinfra -q -s --disable-warnings testinfra_test.py --junit-xml=report.xml
- The argument
Now we can run Testinfra against the server using
testinfra -q -s --disable-warnings --ssh-config=/Path/to/ssh/config --hosts=server testinfra_test.py --junit-xml=report.xml
.
Quick Start for ZAP:
Install JDK.
yum install java-1.8.0-openjdk*
Download ZAP installation script.
wget https://github.com/zaproxy/zaproxy/releases/download/2.6.0/ZAP_2_6_0_unix.sh
Change permission of the installation script and execute it.
12chmod 777 ZAP_2_6_0_unix.sh./ZAP_2_6_0_unix.shInstall required libraries.
1) Install Selenium-WebDriver
gem install selenium-webdriver
2) Install IO
gem install io
3) Install Rest-Client
12yum install gcc-c++gem install rest-client4) Install RSpec
gem install rspec
5) Install and configure the headless Firefox
1234yum -y install firefox Xvfb libXfont Xorgyum -y groupinstall "X Window System" "Desktop" "Fonts" "General Purpose Desktop"Xvfb :99 -ac -screen 0 1280x1024x24 &export DISPLAY=:996) Download and setup geckodriver.
123wget https://github.com/mozilla/geckodriver/releases/download/v0/geckodriver-v0 -linux64.tar.gztar -xvzf geckodriver-v0-linux64.tar.gzmv geckodriver /usr/lib647) Add following lines to ~/.bash_profile.
$PATH=$PATH:/usr/lib64
And run
source ~/.bash_profile
.8) Alternatively, we can use Chromedriver:
i) Create a file called /etc/yum.repos.d/google-chrome.repo and add the following lines of code to it.
123456[google-chrome]name=google-chromebaseurl=http://dl.google.com/linux/chrome/rpm/stable/$basearchenabled=1gpgcheck=1gpgkey=https://dl-ssl.google.com/linux/linux_signing_key.pubii) Check whether the latest version available from the Google�s own repository using
yum info google-chrome-stable
iii) Update yum using ‘yum update’
ix) Install Chrome using
yum install google-chrome-stable unzip
x) Download Chromedriver using
wget https://chromedriver.storage.googleapis.com/2.32/chromedriver_linux64.zip
xi) Unzip Chromedriver using
unzip chromedriver_linux64.zip
xii) Move Chromedriver to a place in $PATH using
mv chromedriver bin/
Using
ruby add_assertions_to_check_zap_result.rb
to run and check the result.You can reference the script here.
GRUB VGA Modes
Colour Depth | 640x480 | 800x600 | 1024x768 | 1280x1024 | 1400x1050 | 1600x1200 |
---|---|---|---|---|---|---|
8 (256) | 769 | 771 | 773 | 775 | ||
15 (32K) | 784 | 787 | 790 | 793 | ||
16 (65K) | 785 | 788 | 791 | 794 | 834 | 884 |
24 (16M) | 786 | 789 | 792 | 795 |