Update tests (#2)

* Update testing library

* Refactored tests to use new testing library

* Add travis

* Modify travis to use https for git submodules

* Add shellcheck

* Remove shellcheck

* Add debian apt sources

* Add shellcheck

* Add travis status image
This commit is contained in:
Jason Hee authored and GitHub committed 2018-04-18 15:12:52 +08:00
1 parent 65eb29e4fe
commit 79ccba4ac2
6 files changed
+64 -18

No files matched your search

+1
View File
@@ -3,3 +3,4 @@
.DS_Store .DS_Store
!/tests/results/.gitkeep !/tests/results/.gitkeep
/tests/results/* /tests/results/*
Vagrantfile
+16
View File
@@ -0,0 +1,16 @@
language: generic
sudo: required
matrix:
include:
- dist: trusty
sudo: required
# Use https (public access) instead of git for git-submodules. This modifies only Travis-CI behavior
git:
submodules: false
# use sed to replace the SSH URL with the public URL, then init and update submodules
before_install:
- sed -i 's/[email protected]:/https:\/\/github.com\//' .gitmodules
- git submodule update --init --recursive
script:
- bash -c 'shopt -s globstar; shellcheck ./*.sh; shellcheck ./tests/*.sh'
- bash tests/unit-tests.sh -skip
+6
View File
@@ -1,4 +1,6 @@
# Bash setup script for Ubuntu servers # Bash setup script for Ubuntu servers
[![Build Status](https://travis-ci.org/jasonheecs/ubuntu-server-setup.svg?branch=master)](https://travis-ci.org/jasonheecs/ubuntu-server-setup)
This is a setup script to automate the setup and provisioning of Ubuntu servers. It does the following: This is a setup script to automate the setup and provisioning of Ubuntu servers. It does the following:
* Adds a new user account with sudo access * Adds a new user account with sudo access
* Adds a public ssh key for the new user account * Adds a public ssh key for the new user account
@@ -41,3 +43,7 @@ Finally, you will be prompted to specify a [timezone](https://en.wikipedia.org/w
# Supported versions # Supported versions
This setup script has been tested against Ubuntu 14.04 and Ubuntu 16.04. This setup script has been tested against Ubuntu 14.04 and Ubuntu 16.04.
# Running tests
Tests are run against a set of Vagrant VMs. To run the tests, run the following in the project's directory:
`./tests/tests.sh`
Regular → Executable
View File
File mode changed.
+40 -17
View File
@@ -1,5 +1,13 @@
#!/bin/bash #!/bin/bash
set -e
while getopts "skip" opt; do
case $opt in
s) SKIP_SETUP=true ;;
esac
done
function getCurrentDir() { function getCurrentDir() {
local current_dir="${BASH_SOURCE%/*}" local current_dir="${BASH_SOURCE%/*}"
if [[ ! -d "${current_dir}" ]]; then current_dir="$PWD"; fi if [[ ! -d "${current_dir}" ]]; then current_dir="$PWD"; fi
@@ -7,12 +15,17 @@ function getCurrentDir() {
} }
current_dir=$(getCurrentDir) current_dir=$(getCurrentDir)
source "${current_dir}/lib/BashScriptTestingLibrary.shl" # shellcheck source=/dev/null
source "${current_dir}/lib/bunit.shl"
# shellcheck source=/dev/null
source "${current_dir}/../setupLibrary.sh" source "${current_dir}/../setupLibrary.sh"
test_user_account=testuser test_user_account=testuser
test_account_password="123%pass_321" test_account_password="123%pass_321"
# shellcheck disable=SC2034
VERBOSE_MODE="true"
### Unit Tests ### ### Unit Tests ###
function testSetup () { function testSetup () {
@@ -27,29 +40,35 @@ function testUserAccountCreated() {
} }
function testIfUserIsSudo() { function testIfUserIsSudo() {
local user_access if [[ $SKIP_SETUP != true ]]; then
user_access="$(sudo -l -U ${test_user_account})" local user_access
assertContains "(ALL : ALL) ALL" "${user_access}" user_access="$(sudo -l -U ${test_user_account})"
assertContains "(ALL : ALL) ALL" "${user_access}"
fi
} }
function testAddingOfSSHKey() { function testAddingOfSSHKey() {
disableSudoPassword "${test_user_account}" if [[ $SKIP_SETUP != true ]]; then
disableSudoPassword "${test_user_account}"
local dummy_key="ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDBGTO0tsVejssuaYR5R3Y/i73SppJAhme1dH7W2c47d4gOqB4izP0+fRLfvbz/tnXFz4iOP/H6eCV05hqUhF+KYRxt9Y8tVMrpDZR2l75o6+xSbUOMu6xN+uVF0T9XzKcxmzTmnV7Na5up3QM3DoSRYX/EP3utr2+zAqpJIfKPLdA74w7g56oYWI9blpnpzxkEd3edVJOivUkpZ4JoenWManvIaSdMTJXMy3MtlQhva+j9CgguyVbUkdzK9KKEuah+pFZvaugtebsU+bllPTB0nlXGIJk98Ie9ZtxuY3nCKneB+KjKiXrAvXUPCI9mWkYS/1rggpFmu3HbXBnWSUdf [email protected]" local dummy_key="ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDBGTO0tsVejssuaYR5R3Y/i73SppJAhme1dH7W2c47d4gOqB4izP0+fRLfvbz/tnXFz4iOP/H6eCV05hqUhF+KYRxt9Y8tVMrpDZR2l75o6+xSbUOMu6xN+uVF0T9XzKcxmzTmnV7Na5up3QM3DoSRYX/EP3utr2+zAqpJIfKPLdA74w7g56oYWI9blpnpzxkEd3edVJOivUkpZ4JoenWManvIaSdMTJXMy3MtlQhva+j9CgguyVbUkdzK9KKEuah+pFZvaugtebsU+bllPTB0nlXGIJk98Ie9ZtxuY3nCKneB+KjKiXrAvXUPCI9mWkYS/1rggpFmu3HbXBnWSUdf [email protected]"
addSSHKey "${test_user_account}" "${dummy_key}" addSSHKey "${test_user_account}" "${dummy_key}"
local ssh_file local ssh_file
ssh_file="$(sudo cat /home/${test_user_account}/.ssh/authorized_keys)" ssh_file="$(sudo cat /home/${test_user_account}/.ssh/authorized_keys)"
assertEquals "${ssh_file}" "${dummy_key}" assertEquals "${ssh_file}" "${dummy_key}"
fi
} }
function testChangeSSHConfig() { function testChangeSSHConfig() {
changeSSHConfig if [[ $SKIP_SETUP != true ]]; then
changeSSHConfig
local ssh_config local ssh_config
ssh_config="$(sudo cat /etc/ssh/sshd_config)" ssh_config="$(sudo cat /etc/ssh/sshd_config)"
assertContains "PasswordAuthentication no" "${ssh_config}" assertContains "PasswordAuthentication no" "${ssh_config}"
assertContains "PermitRootLogin no" "${ssh_config}" assertContains "PermitRootLogin no" "${ssh_config}"
fi
} }
function testUfw() { function testUfw() {
@@ -101,8 +120,12 @@ function testTeardown () {
echo "Test Teardown" echo "Test Teardown"
deleteTestUser deleteTestUser
revertSudoers
revertSSHConfig if [[ $SKIP_SETUP != true ]]; then
revertSudoers
revertSSHConfig
fi
revertUfw revertUfw
deleteSwap deleteSwap