Changeset - 87f4f8572370
[Not reviewed]
8 6 1
Branko Majic (branko) - 4 years ago 2020-09-15 14:55:09
branko@majic.rs
MAR-150: Use fixtures for X.509 artefacts in the xmpp_server role:

- Removed the statically generated artefacts.
- Generate X.509 artefacts for tests using Gimmecert.
- Updated paths to point to generated artefacts.
- Introduced cleanup playbook for removing generated artefacts.
15 files changed with 67 insertions and 697 deletions:
0 comments (0 inline, 0 general)
roles/xmpp_server/molecule/default/cleanup.yml
Show inline comments
 
new file 100644
 
---
 

	
 
- name: Clean-up fixtures
 
  hosts: localhost
 
  connection: local
 
  gather_facts: false
 
  tasks:
 

	
 
    - name: Remove X.509 material
 
      file:
 
        path: "{{ item }}"
 
        state: absent
 
      with_items:
 
        - "tests/data/x509"
 
        - "tests/data/.gimmecert"
roles/xmpp_server/molecule/default/group_vars/parameters-mandatory.yml
Show inline comments
 
@@ -5,9 +5,9 @@ xmpp_administrators:
 
xmpp_ldap_base_dn: dc=local
 
xmpp_ldap_password: prosodypassword
 
xmpp_ldap_server: ldap-server
 
xmpp_tls_certificate: "{{ lookup('file', 'tests/data/x509/{{ inventory_hostname }}_xmpp.cert.pem') }}"
 
xmpp_tls_key: "{{ lookup('file', 'tests/data/x509/{{ inventory_hostname }}_xmpp.key.pem') }}"
 
xmpp_tls_certificate: "{{ lookup('file', 'tests/data/x509/server/{{ inventory_hostname }}_xmpp.cert.pem') }}"
 
xmpp_tls_key: "{{ lookup('file', 'tests/data/x509/server/{{ inventory_hostname }}_xmpp.key.pem') }}"
 

	
 
# common
 
ca_certificates:
 
  testca: "{{ lookup('file', 'tests/data/x509/ca.cert.pem') }}"
 
  testca: "{{ lookup('file', 'tests/data/x509/ca/level1.cert.pem') }}"
roles/xmpp_server/molecule/default/group_vars/parameters-optional.yml
Show inline comments
 
@@ -10,12 +10,12 @@ xmpp_ldap_base_dn: dc=local
 
xmpp_ldap_password: prosodypassword
 
xmpp_ldap_server: ldap-server
 
xmpp_prosody_package: prosody-0.9
 
xmpp_tls_certificate: "{{ lookup('file', 'tests/data/x509/{{ inventory_hostname }}_xmpp.cert.pem') }}"
 
xmpp_tls_key: "{{ lookup('file', 'tests/data/x509/{{ inventory_hostname }}_xmpp.key.pem') }}"
 
xmpp_tls_certificate: "{{ lookup('file', 'tests/data/x509/server/{{ inventory_hostname }}_xmpp.cert.pem') }}"
 
xmpp_tls_key: "{{ lookup('file', 'tests/data/x509/server/{{ inventory_hostname }}_xmpp.key.pem') }}"
 

	
 
# common
 
ca_certificates:
 
  testca: "{{ lookup('file', 'tests/data/x509/ca.cert.pem') }}"
 
  testca: "{{ lookup('file', 'tests/data/x509/ca/level1.cert.pem') }}"
 

	
 
# backup_client
 
enable_backup: true
roles/xmpp_server/molecule/default/host_vars/ldap-server.yml
Show inline comments
 
@@ -11,12 +11,12 @@ ldap_server_domain: "local"
 
ldap_server_groups:
 
  - name: xmpp
 
ldap_server_organization: "Example"
 
ldap_server_tls_certificate: "{{ lookup('file', 'tests/data/x509/ldap-server_ldap.cert.pem') }}"
 
ldap_server_tls_key: "{{ lookup('file', 'tests/data/x509/ldap-server_ldap.key.pem') }}"
 
ldap_server_tls_certificate: "{{ lookup('file', 'tests/data/x509/server/ldap-server_ldap.cert.pem') }}"
 
ldap_server_tls_key: "{{ lookup('file', 'tests/data/x509/server/ldap-server_ldap.key.pem') }}"
 

	
 
# common
 
ca_certificates:
 
  testca: "{{ lookup('file', 'tests/data/x509/ca.cert.pem') }}"
 
  testca: "{{ lookup('file', 'tests/data/x509/ca/level1.cert.pem') }}"
 

	
 
# ldap_client
 
ldap_client_config:
roles/xmpp_server/molecule/default/molecule.yml
Show inline comments
 
@@ -65,6 +65,8 @@ platforms:
 

	
 
provisioner:
 
  name: ansible
 
  playbooks:
 
    cleanup: cleanup.yml
 
  config_options:
 
    defaults:
 
      force_valid_group_names: "ignore"
roles/xmpp_server/molecule/default/prepare.yml
Show inline comments
 
---
 

	
 
- name: Set-up fixtures
 
  hosts: localhost
 
  connection: local
 
  gather_facts: false
 
  tasks:
 

	
 
    - name: Initialise CA hierarchy
 
      command: "gimmecert init"
 
      args:
 
        creates: ".gimmecert/ca/level1.cert.pem"
 
        chdir: "tests/data/"
 

	
 
    - name: Generate server private keys and certificates
 
      command:
 
      args:
 
        chdir: "tests/data/"
 
        creates: ".gimmecert/server/{{ item.name }}.cert.pem"
 
        argv: "{{ ['gimmecert', 'server', item.name] + item.fqdn }}"
 
      with_items:
 
        - name: ldap-server_ldap
 
          fqdn:
 
            - ldap-server
 
        - name: parameters-mandatory-stretch64.domain1_xmpp
 
          fqdn:
 
            - parameters-mandatory
 
            - domain1
 
        - name: parameters-optional-stretch64_xmpp
 
          fqdn:
 
            - parameters-optional
 
            - domain2
 
            - domain3
 

	
 
    - name: Set-up link to generated X.509 material
 
      file:
 
        src: ".gimmecert"
 
        dest: "tests/data/x509"
 
        state: link
 

	
 
- name: Prepare
 
  hosts: all
 
  gather_facts: false
 
@@ -53,7 +91,7 @@
 

	
 
    - name: Deploy CA certificate
 
      copy:
 
        src: tests/data/x509/ca.cert.pem
 
        src: tests/data/x509/ca/level1.cert.pem
 
        dest: /usr/local/share/ca-certificates/testca.crt
 
        owner: root
 
        group: root
roles/xmpp_server/molecule/default/tests/data/x509/ca.cert.pem
Show inline comments
 
deleted file
roles/xmpp_server/molecule/default/tests/data/x509/ca.key.pem
Show inline comments
 
deleted file
roles/xmpp_server/molecule/default/tests/data/x509/ldap-server_ldap.cert.pem
Show inline comments
 
deleted file
roles/xmpp_server/molecule/default/tests/data/x509/ldap-server_ldap.key.pem
Show inline comments
 
deleted file
roles/xmpp_server/molecule/default/tests/data/x509/parameters-mandatory-stretch64.domain1_xmpp.cert.pem
Show inline comments
 
deleted file
roles/xmpp_server/molecule/default/tests/data/x509/parameters-mandatory-stretch64.domain1_xmpp.key.pem
Show inline comments
 
deleted file
roles/xmpp_server/molecule/default/tests/data/x509/parameters-optional-stretch64_xmpp.cert.pem
Show inline comments
 
deleted file
roles/xmpp_server/molecule/default/tests/data/x509/parameters-optional-stretch64_xmpp.key.pem
Show inline comments
 
deleted file
roles/xmpp_server/molecule/default/tests/test_default.py
Show inline comments
 
@@ -160,14 +160,14 @@ def test_prosody_tls_files(host):
 
        assert tls_file.user == 'root'
 
        assert tls_file.group == 'prosody'
 
        assert tls_file.mode == 0o640
 
        assert tls_file.content_string == open("tests/data/x509/%s_xmpp.key.pem" % hostname, "r").read().rstrip()
 
        assert tls_file.content_string == open("tests/data/x509/server/%s_xmpp.key.pem" % hostname, "r").read().rstrip()
 

	
 
        tls_file = host.file('/etc/ssl/certs/%s_xmpp.pem' % hostname)
 
        assert tls_file.is_file
 
        assert tls_file.user == 'root'
 
        assert tls_file.group == 'root'
 
        assert tls_file.mode == 0o644
 
        assert tls_file.content_string == open("tests/data/x509/%s_xmpp.cert.pem" % hostname, "r").read().rstrip()
 
        assert tls_file.content_string == open("tests/data/x509/server/%s_xmpp.cert.pem" % hostname, "r").read().rstrip()
 

	
 

	
 
# @TODO: Tests which were not implemented due to lack of out-of-box tools:
0 comments (0 inline, 0 general)