Changeset - 0c2178fd95a5
[Not reviewed]
0 1 5
Branko Majic (branko) - 7 years ago 2017-06-27 11:32:53
branko@majic.rs
MAR-25: Implemented tests for ldap_client role:

- Added Molecule configuration.
- Added test playbook.
- Fixed issue with mode not including leading zero.
- Implemented a couple of simple tests.
6 files changed with 120 insertions and 1 deletions:
0 comments (0 inline, 0 general)
roles/ldap_client/molecule.yml
Show inline comments
 
new file 100644
 
---
 

	
 
dependency: {}
 

	
 
driver:
 
  name: vagrant
 

	
 
vagrant:
 

	
 
  platforms:
 
    - name: debian-jessie64
 
      box: debian/contrib-jessie64
 

	
 
  providers:
 
    - name: virtualbox
 
      type: virtualbox
 
      options:
 
        memory: 512
 
        cpus: 1
 

	
 
  instances:
 

	
 
    - name: parameters-mandatory
 
    - name: parameters-optional
 

	
 
verifier:
 
  name: testinfra
roles/ldap_client/playbook.yml
Show inline comments
 
new file 100644
 
---
 

	
 
- hosts: all
 
  tasks:
 

	
 
    - name: Update all caches to avoid errors due to missing remote archives
 
      apt:
 
        update_cache: yes
 

	
 
- hosts: parameters-mandatory
 
  roles:
 
    - ldap_client
 

	
 
- hosts: parameters-optional
 
  roles:
 
    - role: ldap_client
 
      ldap_client_config:
 
        - comment: CA truststore
 
          option: TLS_CACERT
 
          value: /etc/ssl/certs/testca.cert.pem
 
        - comment: Ensure TLS is enforced
 
          option: TLS_REQCERT
 
          value: demand
 
        - comment: Default URI to connect to
 
          option: URI
 
          value: ldaps://ldap-server/
 
        - comment: Base entry
 
          option: BASE
 
          value: dc=local
roles/ldap_client/tasks/main.yml
Show inline comments
 
@@ -4,7 +4,7 @@
 
  apt: name=ldap-utils state=installed
 

	
 
- name: Deploy LDAP client configuration file
 
  template: src=ldap.conf.j2 dest=/etc/ldap/ldap.conf owner=root group=root mode=644
 
  template: src=ldap.conf.j2 dest=/etc/ldap/ldap.conf owner=root group=root mode=0644
 

	
 
- name: Explicitly run all handlers
 
  include: ../handlers/main.yml
roles/ldap_client/tests/test_default.py
Show inline comments
 
new file 100644
 
import testinfra.utils.ansible_runner
 

	
 
testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner(
 
    '.molecule/ansible_inventory').get_hosts('all')
 

	
 

	
 
def test_installed_packages(Package):
 
    """
 
    Tests if correct packages are installed.
 
    """
 

	
 
    assert Package('ldap-utils').is_installed
 

	
 

	
 
def test_ldap_configuration_file(File):
 
    """
 
    Tests if LDAP configuration files has been deployed with correct
 
    permissions.
 
    """
 

	
 
    config = File('/etc/ldap/ldap.conf')
 

	
 
    assert config.is_file
 
    assert config.user == 'root'
 
    assert config.group == 'root'
 
    assert config.mode == 0o644
roles/ldap_client/tests/test_mandatory.py
Show inline comments
 
new file 100644
 
import testinfra.utils.ansible_runner
 

	
 
testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner(
 
    '.molecule/ansible_inventory').get_hosts('parameters-mandatory')
 

	
 

	
 
def test_ldap_configuration_file_content(File):
 
    """
 
    Tests if LDAP configuration file has correct content
 
    """
 

	
 
    config = File('/etc/ldap/ldap.conf')
 

	
 
    assert config.content == ""
roles/ldap_client/tests/test_optional.py
Show inline comments
 
new file 100644
 
import testinfra.utils.ansible_runner
 

	
 
testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner(
 
    '.molecule/ansible_inventory').get_hosts('parameters-optional')
 

	
 

	
 
def test_ldap_configuration_file_content(File):
 
    """
 
    Tests if LDAP configuration file has correct content
 
    """
 

	
 
    expected_content = """# CA truststore
 
TLS_CACERT /etc/ssl/certs/testca.cert.pem
 
# Ensure TLS is enforced
 
TLS_REQCERT demand
 
# Default URI to connect to
 
URI ldaps://ldap-server/
 
# Base entry
 
BASE dc=local"""
 

	
 
    config = File('/etc/ldap/ldap.conf')
 

	
 
    assert config.content == expected_content
0 comments (0 inline, 0 general)