Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Converts config tests from Serverspec to TestInfra #1616

Merged
merged 79 commits into from
Mar 16, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
79 commits
Select commit Hold shift + click to select a range
ea22eef
Updates pip versions in development test suite
Feb 27, 2017
87107f4
Converts development env spectests -> testinfra
Feb 27, 2017
b39a755
Converts development networking tests serverspec -> testinfra
Feb 27, 2017
b172edb
Creates testinfra wrapper script
Feb 28, 2017
a455c74
Converts dev app settings tests serverspec -> testinfra
Feb 28, 2017
900b13a
Parametrizes app dev env tests
Feb 28, 2017
ffbd16a
Parametrizes pip dependency tests
Mar 1, 2017
ff4c042
Converts app-code tests Serverspec -> TestInfra
Mar 2, 2017
91794dd
Codify pip requirements for running testinfra
msheiny Mar 6, 2017
68fda9b
Converts xvfb tests Serverspec -> TestInfra
Mar 6, 2017
b926a83
Converts cron-apt tests Serverspec -> TestInfra
Mar 6, 2017
2ffd696
Converts FPF apt repo tests Serverspec -> TestInfra
Mar 6, 2017
37bf01c
Converts user config tests Serverspec -> TestInfra
Mar 6, 2017
5dce129
Converts tor config tests Serverspec -> TestInfra
Mar 6, 2017
8357048
Converts general hardening tests Serverspec -> TestInfra
Mar 6, 2017
82b680d
Convert mon-general/ossec_server_spec.rb -> testinfra
msheiny Mar 7, 2017
faf6ae5
Add monitor to test.sh runner, fix for env changin'
msheiny Mar 7, 2017
e35d529
Converts grsecurity config tests Serverspec -> TestInfra
Mar 7, 2017
e77fe7b
Converts Apache config tests Serverspec -> TestInfra
Mar 7, 2017
2f119db
Breaks up Apache config tests into multiple files
Mar 7, 2017
6048105
Adds Apache config tests for logging functionality
Mar 7, 2017
cb635fa
Adds Apache tests for docroot access grants
Mar 7, 2017
e124765
Converts the IPv6 firewall tests Serverspec -> Testinfra
Mar 7, 2017
ecbd695
Convert mon-staging/iptables_spec.rb -> Testinfra
msheiny Mar 8, 2017
21d2fac
Removing mon server spec tests no longer needed
msheiny Mar 8, 2017
d09ce1d
Exports env var for targeting hosts in testinfra run
Mar 8, 2017
de66c74
Creates conftest.py wrapper for invoking testinfra
Mar 7, 2017
2ca2cc1
Creates per-host YAML vars files for Testinfra
Mar 8, 2017
078464f
Updates Apache config tests to use vars import
Mar 7, 2017
d99309d
Updates app-code tests to use dynamic vars import
Mar 8, 2017
e658110
Includes per-host config test selection in wrapper script
Mar 8, 2017
a3f607e
Updates OSSEC config tests to import vars
Mar 8, 2017
87bb0ff
Beefs up regular expressions in OSSEC config tests
Mar 8, 2017
428c743
Simplifies OSSEC connectivity check
Mar 8, 2017
c75f223
Removes constants.py logic from mon tests
Mar 8, 2017
5322f9c
Updates iptables rules for mon server
Mar 8, 2017
fee91df
Expanded coverage for monitoring specific server
msheiny Mar 8, 2017
166cd97
Added flag for parallel test runners
msheiny Mar 8, 2017
b9b36a9
Added case for mon-prod
msheiny Mar 8, 2017
cc6b2f2
Adds additional test suites to app-staging run
Mar 8, 2017
eb03064
Removes converted Serverspec tests for app and development
Mar 8, 2017
6cc6e2c
Downgrades Ansible to 1.8.4 for testinfra requirements
Mar 8, 2017
88fc1e5
Converts Testinfra wrapper script bash -> python
Mar 8, 2017
f3bcd1b
Fixes config test for all packages being upgraded
Mar 8, 2017
20ce896
Converted ossec_agent_spec -> testinfra (staging)
msheiny Mar 8, 2017
acdb70e
Sudoizes config tests where necessary
Mar 8, 2017
f100aa7
Skips apt autoremove check on app-staging host
Mar 8, 2017
6c83b9e
Convert securedrop_app_spec --> Testinfra (Staging)
msheiny Mar 8, 2017
8c5599c
Migrated apparmor_spec --> Testinfra
msheiny Mar 8, 2017
3581332
Convert tor_spec --> testinfra
msheiny Mar 8, 2017
1625ee1
Combined both tor testinfra common tests together
msheiny Mar 8, 2017
3f31128
Converts build config tests Serverspec -> TestInfra
Mar 8, 2017
6c1dd26
Parametrizes deb package build tests
Mar 8, 2017
074674e
Marks xfail for Homepage test in deb packages
Mar 8, 2017
05f33c5
Adds xfail test for removing .pyc files from deb packages
Mar 8, 2017
1d06206
Updates gitignore logic for built deb packages
Mar 8, 2017
7cbb6de
Removes deprecated Serverspec tests for build host
Mar 9, 2017
79e674c
Adds platform config tests (Ansible and OS)
Mar 9, 2017
86be773
Clean-up duplication of apparmor spec tests
msheiny Mar 9, 2017
dd3714e
Adds config test for analyzing OSSEC log errors
Mar 9, 2017
05115b1
Parametrizes tor hidden service tests
Mar 9, 2017
3b4ec1c
Breaks up tor config tests across multiple files
Mar 9, 2017
a5207b3
Adds missing `os` import for apparmor config tests
Mar 9, 2017
31eb4ac
Removes redundant "unwanted" iptables config test
Mar 10, 2017
b0c445c
Generalizes the iptables config test logic
Mar 10, 2017
0edfb5f
Adds test vars for expected iptables rulesets
Mar 10, 2017
ad3bd78
Renames "spectests" -> "config tests" in developer docs
Mar 10, 2017
6b798af
Trims down config tests requirements.txt
Mar 10, 2017
f849254
Adds note on testing strategy to config test docs
Mar 10, 2017
427eaa2
Removes deprecated Serverspec config test directory
Mar 10, 2017
f7f7aa3
Refactors config test wrapper into defs
Mar 10, 2017
8d71dbd
Partial implementation for running prod tests over Tor
Mar 10, 2017
696b70a
Adds note to developer docs about partial prod tests
Mar 10, 2017
e4eadf5
Explains need to create VMs prior to running config tests
Mar 15, 2017
84dadfe
Makes regex for HidServAuth token less strict
Mar 15, 2017
05d8893
Reenables dynamic networking vars in mon-staging tests
Mar 16, 2017
c50b3b5
Converts iptables config tests for app-staging to dynamic vars
Mar 16, 2017
da7205d
Removes mode check for /vagrant/securedrop directory
Mar 16, 2017
c4f0a8e
Adds config test for tmux installed state
Mar 16, 2017
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 1 addition & 8 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,6 @@ vagrant_ansible_inventory*
# ignore ansible retry files
*.retry

# ignore some things for the rspec tests
spec_tests/gems/*
Gemfile.lock

# ignore "external" Ansible configuration file
secureDropConf.yml

Expand All @@ -50,7 +46,7 @@ __pycache__/
# Distribution / packaging
.Python
env/
build/
build/*.deb
develop-eggs/
dist/
downloads/
Expand Down Expand Up @@ -123,9 +119,6 @@ ENV/
# Emacs
\#*#

# ignore cached gems for serverspec tests
spec_tests/gems/*

# compiled assets
securedrop/static/gen
securedrop/static/.webassets-cache
Expand Down
115 changes: 115 additions & 0 deletions docs/development/config_tests.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
Configuration Tests
===================

testinfra_ tests verify the end state of the vagrant machines. Any
changes to the Ansible configuration should have a corresponding
spectest.

.. _testinfra: https://testinfra.readthedocs.io/en/latest/

Installation
------------

.. code:: sh

pip install -r testinfra/requirements.txt

Running the tests
-----------------

In order to run the tests, first create and provision the VM you intend
to test:

.. code:: sh

vagrant up development
vagrant up /staging/

.. note:: The staging machines must be rebooted via in order to finalize
the iptables config. You must manually reboot the machines via
``vagrant reload /staging/`` prior to running the config tests
to ensure the config is valid.

Running all VMs concurrently may cause performance
problems if you have less than 8GB of RAM. You can isolate specific
machines for faster testing:

.. code:: sh

$ ./testinfra/test.py development
$ ./testinfra/test.py app-staging
$ ./testinfra/test.py mon-staging

.. note:: The config tests for the ``app-prod`` and ``mon-prod`` hosts are
incomplete. Further changes are necessary to run the tests via
SSH over Authenticated Tor Hidden Service (ATHS), for both local
testing via Vagrant and automated testing via CI.

Test failure against any host will generate a report with informative output
about the specific test that triggered the error. The wrapper script
will also exit with a non-zero status code.

Updating the tests
------------------

Changes to the Ansible config should result in failing config tests, but
only if an existing task was modified. If you add a new task, make
sure to add a corresponding spectest to validate that state after a
new provisioning run. Tests import variables from separate YAML files
than the Ansible playbooks: ::

testinfra/vars/
├── app-prod.yml
├── app-staging.yml
├── build.yml
├── development.yml
├── mon-prod.yml
└── mon-staging.yml

Any variable changes in the Ansible config should have a corresponding
entry in these vars files. These vars are dynamically loaded for each
host via the ``testinfra/conftest.py`` file. Make sure to add your tests to
relevant location for the host you plan to test: ::

testinfra/app/
├── apache
│ ├── test_apache_journalist_interface.py
│ ├── test_apache_service.py
│ ├── test_apache_source_interface.py
│ └── test_apache_system_config.py
├── test_apparmor.py
├── test_appenv.py
└── test_ossec.py

In the example above, to add a new test for the ``app-staging`` host,
add a new file to the ``testinfra/spec/app-staging`` directory.

Config test layout
------------------

The config tests are mostly broken up according to machines in the
Vagrantfile: ::

testinfra/
├── app
├── app-code
├── build
├── common
├── development
└── mon

Ideally the config tests would be broken up according to roles,
mirroring the Ansible configuration. Prior to the reorganization of
the Ansible layout, the tests are rather tightly coupled to hosts. The
layout of config tests is therefore subject to change.

Testing strategy
----------------

The config tests currently emphasize testing implementation rather than
functionality. This is a temporary measure to increase the current testing
baseline for validating the Ansible provisioning flow, to aid in migrating
to a current version of Ansible (v2+). After the Ansible version is current,
the config tests can be improved to validate behavior, such as confirming
ports are blocked via external network calls, rather than simply checking
that the iptables rules are formatted as expected.
118 changes: 0 additions & 118 deletions docs/development/spec_tests.rst

This file was deleted.

2 changes: 1 addition & 1 deletion docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ anonymous sources.
development/virtual_environments
development/tips_and_tricks
development/documentation_guidelines
development/spec_tests
development/config_tests
development/apt_repo
development/apparmor_profiles
development/threat_model
3 changes: 0 additions & 3 deletions spec_tests/.bundle/config

This file was deleted.

8 changes: 0 additions & 8 deletions spec_tests/.gemrc

This file was deleted.

4 changes: 0 additions & 4 deletions spec_tests/.rspec

This file was deleted.

5 changes: 0 additions & 5 deletions spec_tests/Gemfile

This file was deleted.

78 changes: 0 additions & 78 deletions spec_tests/Rakefile

This file was deleted.

Loading