Changeset - e970d4afbea4
[Not reviewed]
27 0 30
Branko Majic (branko) - 6 years ago 2017-11-26 23:57:43
branko@majic.rs
MAR-128: Upgraded tests for xmpp_server role:

- Switch to new Molecule configuration.
- Updated set-up playbook to use become: yes.
- Moved some preparatory steps outside of the main playbook (eases
idempotence tests).
- Updated tests to reference the yml inventory file.
- Updated tests to use new fixture (host instead of individual ones).
- Switched to extracting hostname instead of hard-coding it in a
couple of tests.
- Renamed hosts to include the Debian version.
- Updated names for some of the test data to cater to change in host
names.
- Switched to using more robust task for populating /etc/hosts.
32 files changed with 394 insertions and 261 deletions:
0 comments (0 inline, 0 general)
roles/xmpp_server/molecule.yml
Show inline comments
 
deleted file
roles/xmpp_server/molecule/default/create.yml
Show inline comments
 
new file 100644
 
---
 
- name: Create
 
  hosts: localhost
 
  connection: local
 
  gather_facts: False
 
  no_log: "{{ not lookup('env', 'MOLECULE_DEBUG') | bool }}"
 
  vars:
 
    molecule_file: "{{ lookup('env', 'MOLECULE_FILE') }}"
 
    molecule_instance_config: "{{ lookup('env', 'MOLECULE_INSTANCE_CONFIG') }}"
 
    molecule_yml: "{{ lookup('file', molecule_file) | molecule_from_yaml }}"
 
  tasks:
 
    - name: Create molecule instance(s)
 
      molecule_vagrant:
 
        instance_name: "{{ item.name }}"
 
        instance_interfaces: "{{ item.interfaces | default(omit) }}"
 
        instance_raw_config_args: "{{ item.instance_raw_config_args | default(omit) }}"
 

	
 
        platform_box: "{{ item.box }}"
 
        platform_box_version: "{{ item.box_version | default(omit) }}"
 
        platform_box_url: "{{ item.box_url | default(omit) }}"
 

	
 
        provider_name: "{{ molecule_yml.driver.provider.name }}"
 
        provider_memory: "{{ item.memory | default(omit) }}"
 
        provider_cpus: "{{ item.cpus | default(omit) }}"
 
        provider_raw_config_args: "{{ item.raw_config_args | default(omit) }}"
 

	
 
        state: up
 
      register: server
 
      with_items: "{{ molecule_yml.platforms }}"
 

	
 
    # Mandatory configuration for Molecule to function.
 

	
 
    - name: Populate instance config dict
 
      set_fact:
 
        instance_conf_dict: {
 
          'instance': "{{ item.Host }}",
 
          'address': "{{ item.HostName }}",
 
          'user': "{{ item.User }}",
 
          'port': "{{ item.Port }}",
 
          'identity_file': "{{ item.IdentityFile }}", }
 
      with_items: "{{ server.results }}"
 
      register: instance_config_dict
 
      when: server.changed | bool
 

	
 
    - name: Convert instance config dict to a list
 
      set_fact:
 
        instance_conf: "{{ instance_config_dict.results | map(attribute='ansible_facts.instance_conf_dict') | list }}"
 
      when: server.changed | bool
 

	
 
    - name: Dump instance config
 
      copy:
 
        # NOTE(retr0h): Workaround for Ansible 2.2.
 
        #               https://github.com/ansible/ansible/issues/20885
 
        content: "{{ instance_conf | to_json | from_json | molecule_to_yaml | molecule_header }}"
 
        dest: "{{ molecule_instance_config }}"
 
      when: server.changed | bool
roles/xmpp_server/molecule/default/destroy.yml
Show inline comments
 
new file 100644
 
---
 

	
 
- name: Destroy
 
  hosts: localhost
 
  connection: local
 
  gather_facts: False
 
  no_log: "{{ not lookup('env', 'MOLECULE_DEBUG') | bool }}"
 
  vars:
 
    molecule_file: "{{ lookup('env', 'MOLECULE_FILE') }}"
 
    molecule_instance_config: "{{ lookup('env',' MOLECULE_INSTANCE_CONFIG') }}"
 
    molecule_yml: "{{ lookup('file', molecule_file) | molecule_from_yaml }}"
 
  tasks:
 
    - name: Destroy molecule instance(s)
 
      molecule_vagrant:
 
        instance_name: "{{ item.name }}"
 
        platform_box: "{{ item.box }}"
 
        provider_name: "{{ molecule_yml.driver.provider.name }}"
 
        force_stop: "{{ item.force_stop | default(True) }}"
 

	
 
        state: destroy
 
      register: server
 
      with_items: "{{ molecule_yml.platforms }}"
 

	
 
    # Mandatory configuration for Molecule to function.
 

	
 
    - name: Populate instance config
 
      set_fact:
 
        instance_conf: {}
 

	
 
    - name: Dump instance config
 
      copy:
 
        # NOTE(retr0h): Workaround for Ansible 2.2.
 
        #               https://github.com/ansible/ansible/issues/20885
 
        content: "{{ instance_conf | to_json | from_json | molecule_to_yaml | molecule_header }}"
 
        dest: "{{ molecule_instance_config }}"
 
      when: server.changed | bool
roles/xmpp_server/molecule/default/molecule.yml
Show inline comments
 
new file 100644
 
---
 

	
 
dependency: {}
 

	
 
driver:
 
  name: vagrant
 
  provider:
 
    name: virtualbox
 

	
 
lint:
 
  name: yamllint
 

	
 
platforms:
 

	
 
  - name: ldap-server
 
    box: debian/contrib-jessie64
 
    memory: 512
 
    cpus: 1
 
    interfaces:
 
      - auto_config: true
 
        ip: 10.31.127.10
 
        network_name: private_network
 
        type: static
 

	
 
  - name: client1
 
    box: debian/contrib-jessie64
 
    memory: 256
 
    cpus: 1
 
    interfaces:
 
      - auto_config: true
 
        ip: 10.31.127.20
 
        network_name: private_network
 
        type: static
 

	
 
  - name: parameters-mandatory-jessie64.domain1
 
    groups:
 
      - parameters-mandatory
 
    box: debian/contrib-jessie64
 
    memory: 512
 
    cpus: 1
 
    interfaces:
 
      - auto_config: true
 
        ip: 10.31.127.30
 
        network_name: private_network
 
        type: static
 

	
 
  - name: parameters-optional-jessie64
 
    groups:
 
      - parameters-optional
 
    box: debian/contrib-jessie64
 
    memory: 512
 
    cpus: 1
 
    interfaces:
 
      - auto_config: true
 
        ip: 10.31.127.31
 
        network_name: private_network
 
        type: static
 

	
 
provisioner:
 
  name: ansible
 
  config_options:
 
    ssh_connection:
 
      pipelining: "True"
 
  lint:
 
    name: ansible-lint
 

	
 
scenario:
 
  name: default
 

	
 
verifier:
 
  name: testinfra
 
  lint:
 
    name: flake8
roles/xmpp_server/molecule/default/playbook.yml
Show inline comments
 
new file 100644
 
---
 

	
 
- hosts: parameters-mandatory
 
  become: yes
 
  roles:
 
    - role: xmpp_server
 
      xmpp_administrators:
 
        - john.doe@domain1
 
      xmpp_ldap_base_dn: dc=local
 
      xmpp_ldap_password: prosodypassword
 
      xmpp_ldap_server: ldap-server
 

	
 
      # Common parameters (general, not role).
 
      tls_certificate_dir: tests/data/x509/
 
      tls_private_key_dir: tests/data/x509/
 

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

	
 
- hosts: parameters-optional
 
  become: yes
 
  roles:
 
    - role: xmpp_server
 
      xmpp_administrators:
 
        - jane.doe@domain2
 
        - mick.doe@domain3
 
      xmpp_domains:
 
        - domain2
 
        - domain3
 
      xmpp_ldap_base_dn: dc=local
 
      xmpp_ldap_password: prosodypassword
 
      xmpp_ldap_server: ldap-server
 
      xmpp_tls_certificate: "{{ lookup('file', 'tests/data/x509/parameters-optional_xmpp.cert.pem') }}"
 
      xmpp_tls_key: "{{ lookup('file', 'tests/data/x509/parameters-optional_xmpp.key.pem') }}"
 

	
 
      # Common parameters (general, not role).
 
      tls_certificate_dir: tests/data/x509/
 
      tls_private_key_dir: tests/data/x509/
 

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

	
 
      # backup_client
 
      enable_backup: yes
 
      backup_client_username: bak-parameters-optional
 
      backup_encryption_key: "{{ lookup('file', 'tests/data/gnupg/parameters-optional.asc') }}"
 
      backup_server: backup-server
 
      backup_server_host_ssh_public_keys:
 
        - "{{ lookup('file', 'tests/data/ssh/server_dsa.pub') }}"
 
        - "{{ lookup('file', 'tests/data/ssh/server_rsa.pub') }}"
 
        - "{{ lookup('file', 'tests/data/ssh/server_ed25519.pub') }}"
 
        - "{{ lookup('file', 'tests/data/ssh/server_ecdsa.pub') }}"
 
      backup_ssh_key: "{{ lookup('file', 'tests/data/ssh/parameters-optional' ) }}"
roles/xmpp_server/molecule/default/prepare.yml
Show inline comments
 
file renamed from roles/xmpp_server/playbook.yml to roles/xmpp_server/molecule/default/prepare.yml
 
---
 

	
 
- name: Prepare
 
  hosts: all
 
  gather_facts: False
 
  tasks:
 
    - name: Install python for Ansible
 
      raw: test -e /usr/bin/python || (apt -y update && apt install -y python-minimal)
 
      become: True
 
      changed_when: False
 

	
 
- hosts: all
 
  become: yes
 
  tasks:
 

	
 
    - name: Update all caches to avoid errors due to missing remote archives
 
@@ -8,13 +18,15 @@
 
        update_cache: yes
 
      changed_when: False
 

	
 
- hosts: all
 
  tasks:
 

	
 
    - name: Set-up /etc/hosts entries
 
    - name: Set-up the hosts file
 
      lineinfile:
 
        dest: /etc/hosts
 
        path: /etc/hosts
 
        regexp: "^{{ item.key }}"
 
        line: "{{ item.key }} {{ item.value }}"
 
        owner: root
 
        group: root
 
        mode: 0644
 
        state: present
 
      with_dict:
 
        10.31.127.10: "ldap-server backup-server"
 
        10.31.127.20: "client1"
 
@@ -22,6 +34,7 @@
 
        10.31.127.31: "parameters-optional domain2 proxy.domain2 conference.domain2 domain3 proxy.domain3 conference.domain3"
 

	
 
- hosts: client1
 
  become: yes
 
  tasks:
 

	
 
    - name: Install tool for testing TCP connectivity
 
@@ -95,6 +108,7 @@
 
      command: /usr/sbin/update-ca-certificates --fresh
 

	
 
- hosts: ldap-server
 
  become: yes
 
  roles:
 
    - role: ldap_server
 
      ldap_admin_password: admin
 
@@ -193,59 +207,8 @@
 
          ip: 10.31.127.31
 
          public_key: "{{ lookup('file', 'tests/data/ssh/parameters-optional.pub') }}"
 

	
 
- hosts: parameters-mandatory.domain1
 
  roles:
 
    - role: xmpp_server
 
      xmpp_administrators:
 
        - john.doe@domain1
 
      xmpp_ldap_base_dn: dc=local
 
      xmpp_ldap_password: prosodypassword
 
      xmpp_ldap_server: ldap-server
 

	
 
      # Common parameters (general, not role).
 
      tls_certificate_dir: tests/data/x509/
 
      tls_private_key_dir: tests/data/x509/
 

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

	
 
- hosts: parameters-optional
 
  roles:
 
    - role: xmpp_server
 
      xmpp_administrators:
 
        - jane.doe@domain2
 
        - mick.doe@domain3
 
      xmpp_domains:
 
        - domain2
 
        - domain3
 
      xmpp_ldap_base_dn: dc=local
 
      xmpp_ldap_password: prosodypassword
 
      xmpp_ldap_server: ldap-server
 
      xmpp_tls_certificate: "{{ lookup('file', 'tests/data/x509/parameters-optional_xmpp.cert.pem') }}"
 
      xmpp_tls_key: "{{ lookup('file', 'tests/data/x509/parameters-optional_xmpp.key.pem') }}"
 

	
 
      # Common parameters (general, not role).
 
      tls_certificate_dir: tests/data/x509/
 
      tls_private_key_dir: tests/data/x509/
 

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

	
 
      # backup_client
 
      enable_backup: yes
 
      backup_encryption_key: "{{ lookup('file', 'tests/data/gnupg/parameters-optional.asc') }}"
 
      backup_server: backup-server
 
      backup_server_host_ssh_public_keys:
 
        - "{{ lookup('file', 'tests/data/ssh/server_dsa.pub') }}"
 
        - "{{ lookup('file', 'tests/data/ssh/server_rsa.pub') }}"
 
        - "{{ lookup('file', 'tests/data/ssh/server_ed25519.pub') }}"
 
        - "{{ lookup('file', 'tests/data/ssh/server_ecdsa.pub') }}"
 
      backup_ssh_key: "{{ lookup('file', 'tests/data/ssh/parameters-optional' ) }}"
 

	
 

	
 
- hosts: parameters-optional
 
  become: yes
 
  tasks:
 

	
 
    - name: Install console-based XMPP tool (for non-interactive testing)
roles/xmpp_server/molecule/default/tests/data/gnupg/parameters-optional.asc
Show inline comments
 
file renamed from roles/xmpp_server/tests/data/gnupg/parameters-optional.asc to roles/xmpp_server/molecule/default/tests/data/gnupg/parameters-optional.asc
roles/xmpp_server/molecule/default/tests/data/mcabber.cfg.j2
Show inline comments
 
file renamed from roles/xmpp_server/tests/data/mcabber.cfg.j2 to roles/xmpp_server/molecule/default/tests/data/mcabber.cfg.j2
roles/xmpp_server/molecule/default/tests/data/ssh/parameters-optional
Show inline comments
 
file renamed from roles/xmpp_server/tests/data/ssh/parameters-optional to roles/xmpp_server/molecule/default/tests/data/ssh/parameters-optional
roles/xmpp_server/molecule/default/tests/data/ssh/parameters-optional.pub
Show inline comments
 
file renamed from roles/xmpp_server/tests/data/ssh/parameters-optional.pub to roles/xmpp_server/molecule/default/tests/data/ssh/parameters-optional.pub
roles/xmpp_server/molecule/default/tests/data/ssh/server_dsa
Show inline comments
 
file renamed from roles/xmpp_server/tests/data/ssh/server_dsa to roles/xmpp_server/molecule/default/tests/data/ssh/server_dsa
roles/xmpp_server/molecule/default/tests/data/ssh/server_dsa.pub
Show inline comments
 
file renamed from roles/xmpp_server/tests/data/ssh/server_dsa.pub to roles/xmpp_server/molecule/default/tests/data/ssh/server_dsa.pub
roles/xmpp_server/molecule/default/tests/data/ssh/server_ecdsa
Show inline comments
 
file renamed from roles/xmpp_server/tests/data/ssh/server_ecdsa to roles/xmpp_server/molecule/default/tests/data/ssh/server_ecdsa
roles/xmpp_server/molecule/default/tests/data/ssh/server_ecdsa.pub
Show inline comments
 
file renamed from roles/xmpp_server/tests/data/ssh/server_ecdsa.pub to roles/xmpp_server/molecule/default/tests/data/ssh/server_ecdsa.pub
roles/xmpp_server/molecule/default/tests/data/ssh/server_ed25519
Show inline comments
 
file renamed from roles/xmpp_server/tests/data/ssh/server_ed25519 to roles/xmpp_server/molecule/default/tests/data/ssh/server_ed25519
roles/xmpp_server/molecule/default/tests/data/ssh/server_ed25519.pub
Show inline comments
 
file renamed from roles/xmpp_server/tests/data/ssh/server_ed25519.pub to roles/xmpp_server/molecule/default/tests/data/ssh/server_ed25519.pub
roles/xmpp_server/molecule/default/tests/data/ssh/server_rsa
Show inline comments
 
file renamed from roles/xmpp_server/tests/data/ssh/server_rsa to roles/xmpp_server/molecule/default/tests/data/ssh/server_rsa
roles/xmpp_server/molecule/default/tests/data/ssh/server_rsa.pub
Show inline comments
 
file renamed from roles/xmpp_server/tests/data/ssh/server_rsa.pub to roles/xmpp_server/molecule/default/tests/data/ssh/server_rsa.pub
roles/xmpp_server/molecule/default/tests/data/x509/ca.cert.pem
Show inline comments
 
file renamed from roles/xmpp_server/tests/data/x509/ca.cert.pem to roles/xmpp_server/molecule/default/tests/data/x509/ca.cert.pem
roles/xmpp_server/molecule/default/tests/data/x509/ca.key.pem
Show inline comments
 
file renamed from roles/xmpp_server/tests/data/x509/ca.key.pem to roles/xmpp_server/molecule/default/tests/data/x509/ca.key.pem
roles/xmpp_server/molecule/default/tests/data/x509/ldap-server_ldap.cert.pem
Show inline comments
 
file renamed from roles/xmpp_server/tests/data/x509/ldap-server_ldap.cert.pem to roles/xmpp_server/molecule/default/tests/data/x509/ldap-server_ldap.cert.pem
roles/xmpp_server/molecule/default/tests/data/x509/ldap-server_ldap.key.pem
Show inline comments
 
file renamed from roles/xmpp_server/tests/data/x509/ldap-server_ldap.key.pem to roles/xmpp_server/molecule/default/tests/data/x509/ldap-server_ldap.key.pem
roles/xmpp_server/molecule/default/tests/data/x509/parameters-mandatory-jessie64.domain1_xmpp.key
Show inline comments
 
file renamed from roles/xmpp_server/tests/data/x509/parameters-mandatory.domain1_xmpp.key to roles/xmpp_server/molecule/default/tests/data/x509/parameters-mandatory-jessie64.domain1_xmpp.key
roles/xmpp_server/molecule/default/tests/data/x509/parameters-mandatory-jessie64.domain1_xmpp.pem
Show inline comments
 
file renamed from roles/xmpp_server/tests/data/x509/parameters-mandatory.domain1_xmpp.pem to roles/xmpp_server/molecule/default/tests/data/x509/parameters-mandatory-jessie64.domain1_xmpp.pem
roles/xmpp_server/molecule/default/tests/data/x509/parameters-optional_xmpp.cert.pem
Show inline comments
 
file renamed from roles/xmpp_server/tests/data/x509/parameters-optional_xmpp.cert.pem to roles/xmpp_server/molecule/default/tests/data/x509/parameters-optional_xmpp.cert.pem
roles/xmpp_server/molecule/default/tests/data/x509/parameters-optional_xmpp.key.pem
Show inline comments
 
file renamed from roles/xmpp_server/tests/data/x509/parameters-optional_xmpp.key.pem to roles/xmpp_server/molecule/default/tests/data/x509/parameters-optional_xmpp.key.pem
roles/xmpp_server/molecule/default/tests/test_backup.py
Show inline comments
 
file renamed from roles/xmpp_server/tests/test_backup.py to roles/xmpp_server/molecule/default/tests/test_backup.py
 
@@ -2,32 +2,32 @@ import testinfra.utils.ansible_runner
 

	
 

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

	
 

	
 
def test_backup(Command, File, Sudo):
 
def test_backup(host):
 
    """
 
    Tests if Prosody data directory is correctly backed-up.
 
    """
 

	
 
    # Deliver a couple of messages in order to make sure the directory structure
 
    # is created.
 
    send = Command("echo 'Hello' | sendxmpp -t -u jane.doe -p janepassword -j domain2:5222 jane.doe@domain2")
 
    send = host.run("echo 'Hello' | sendxmpp -t -u jane.doe -p janepassword -j domain2:5222 jane.doe@domain2")
 
    assert send.rc == 0
 

	
 
    send = Command("echo 'Hello' | sendxmpp -t -u mick.doe -p mickpassword -j domain3:5222 mick.doe@domain3")
 
    send = host.run("echo 'Hello' | sendxmpp -t -u mick.doe -p mickpassword -j domain3:5222 mick.doe@domain3")
 
    assert send.rc == 0
 

	
 
    with Sudo():
 
    with host.sudo():
 

	
 
        # Remove restore directory in order to make sure restore has worked
 
        # correctly.
 
        Command("rm -rf /root/restore")
 
        host.run("rm -rf /root/restore")
 

	
 
        backup_run = Command('duply main backup')
 
        backup_run = host.run('duply main backup')
 
        assert backup_run.rc == 0
 

	
 
        restore_run = Command('duply main restore /root/restore')
 
        restore_run = host.run('duply main restore /root/restore')
 
        assert restore_run.rc == 0
 

	
 
        for directory_path in ["/root/restore/var/lib/prosody/domain2",
 
@@ -35,7 +35,7 @@ def test_backup(Command, File, Sudo):
 
                               "/root/restore/var/lib/prosody/domain3",
 
                               "/root/restore/var/lib/prosody/domain3/offline"]:
 

	
 
            directory = File(directory_path)
 
            directory = host.file(directory_path)
 

	
 
            assert directory.is_directory
 
            assert directory.user == "prosody"
 
@@ -45,7 +45,7 @@ def test_backup(Command, File, Sudo):
 
        for file_path in ["/root/restore/var/lib/prosody/domain2/offline/jane%2edoe.list",
 
                          "/root/restore/var/lib/prosody/domain3/offline/mick%2edoe.list"]:
 

	
 
            f = File(file_path)
 
            f = host.file(file_path)
 

	
 
            assert f.is_file
 
            assert f.user == 'prosody'
roles/xmpp_server/molecule/default/tests/test_client.py
Show inline comments
 
new file 100644
 
import testinfra.utils.ansible_runner
 

	
 

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

	
 

	
 
def test_connectivity(host):
 
    """
 
    Tests connectivity to the XMPP server (ports that should be reachable).
 
    """
 

	
 
    with host.sudo():
 

	
 
        for server in ["parameters-mandatory",
 
                       "parameters-optional"]:
 
            # c2s plaintext, c2s TLS, file proxy, s2s.
 
            for port in [5222, 5223, 5000, 5269]:
 

	
 
                ping = host.run('hping3 -S -p %d -c 1 %s' % (port, server))
 
                assert ping.rc == 0
 

	
 

	
 
def test_tls(host):
 
    """
 
    Tests if TLS works as expected.
 
    """
 

	
 
    send = host.run("echo 'Hello' | sendxmpp -t -u john.doe -p johnpassword -j domain1:5222 john.doe@domain1")
 
    assert send.rc == 0
 

	
 
    send = host.run("echo 'Hello' | sendxmpp -e -u john.doe -p johnpassword -j domain1:5223 john.doe@domain1")
 
    assert send.rc == 0
 

	
 
    send = host.run("echo 'Hello' | sendxmpp -t -u jane.doe -p janepassword -j domain2:5222 jane.doe@domain2")
 
    assert send.rc == 0
 

	
 
    send = host.run("echo 'Hello' | sendxmpp -e -u jane.doe -p janepassword -j domain2:5223 jane.doe@domain2")
 
    assert send.rc == 0
 

	
 

	
 
def test_authentication_requires_tls(host):
 
    """
 
    Tests if authentication must be done over TLS.
 
    """
 

	
 
    command = host.run("echo 'Hello' | sendxmpp -u bogus -p bogus -j domain1:5222 john.doe@domain1 -d")
 
    assert "<starttls xmlns='urn:ietf:params:xml:ns:xmpp-tls'><required/></starttls>" in command.stderr
 

	
 
    command = host.run("echo 'Hello' | sendxmpp -u bogus -p bogus -j domain2:5222 jane.doe@domain2 -d")
 
    assert "<starttls xmlns='urn:ietf:params:xml:ns:xmpp-tls'><required/></starttls>" in command.stderr
 

	
 

	
 
def test_authentication(host):
 
    """
 
    Tests if authentication works correctly.
 
    """
 

	
 
    send = host.run("echo 'Hello' | sendxmpp -t -u john.doe -p johnpassword -j domain1:5222 john.doe@domain1")
 
    assert send.rc == 0
 

	
 
    send = host.run("echo 'Hello' | sendxmpp -e -u john.doe -p johnpassword -j domain1:5223 john.doe@domain1")
 
    assert send.rc == 0
 

	
 
    send = host.run("echo 'Hello' | sendxmpp -t -u jane.doe -p janepassword -j domain2:5222 jane.doe@domain2")
 
    assert send.rc == 0
 

	
 
    send = host.run("echo 'Hello' | sendxmpp -e -u mick.doe -p mickpassword -j domain3:5223 mick.doe@domain3")
 
    assert send.rc == 0
 

	
 

	
 
def test_unauthorized_users_rejected(host):
 
    """
 
    Tests if unauthorized users (present in LDAP, but not member of correct
 
    group) are rejected from accessing the XMPP server.
 
    """
 

	
 
    send = host.run("echo 'Hello' | sendxmpp -t -u noxmpp -p noxmpppassword -j domain1:5222 john.doe@domain1")
 
    assert send.rc != 0
 
    assert "Error 'AuthSend': error: not-authorized[?]" in send.stderr
roles/xmpp_server/molecule/default/tests/test_default.py
Show inline comments
 
file renamed from roles/xmpp_server/tests/test_default.py to roles/xmpp_server/molecule/default/tests/test_default.py
 
@@ -2,37 +2,37 @@ import testinfra.utils.ansible_runner
 

	
 

	
 
testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner(
 
    '.molecule/ansible_inventory').get_hosts(['parameters-mandatory', 'parameters-optional'])
 
    '.molecule/ansible_inventory.yml').get_hosts(['parameters-mandatory', 'parameters-optional'])
 

	
 

	
 
def test_installed_packages(Package):
 
def test_installed_packages(host):
 
    """
 
    Tests if all the necessary packages have been installed.
 
    """
 

	
 
    assert Package('python-apt').is_installed
 
    assert Package('lua-sec').is_installed
 
    assert Package('lua-ldap').is_installed
 
    assert Package('prosody').is_installed
 
    assert host.package('python-apt').is_installed
 
    assert host.package('lua-sec').is_installed
 
    assert host.package('lua-ldap').is_installed
 
    assert host.package('prosody').is_installed
 

	
 

	
 
def test_prosody_apt_key(Command):
 
def test_prosody_apt_key(host):
 
    """
 
    Tests if Prosody repository signing key has been imported.
 
    """
 

	
 
    keys = Command("apt-key list")
 
    keys = host.run("apt-key list")
 

	
 
    assert "1024D/74D9DBB5" in keys.stdout
 
    assert "4096g/6C8F28BA" in keys.stdout
 

	
 

	
 
def test_prosody_repository(File):
 
def test_prosody_repository(host):
 
    """
 
    Tests if Prosody repository has been added.
 
    """
 

	
 
    repository = File("/etc/apt/sources.list.d/packages_prosody_im_debian.list")
 
    repository = host.file("/etc/apt/sources.list.d/packages_prosody_im_debian.list")
 

	
 
    assert repository.is_file
 
    assert repository.user == 'root'
 
@@ -41,21 +41,21 @@ def test_prosody_repository(File):
 
    assert repository.content == "deb http://packages.prosody.im/debian jessie main"
 

	
 

	
 
def test_prosody_user(User):
 
def test_prosody_user(host):
 
    """
 
    Tests if Prosody user has been set-up correctly to access TLS material.
 
    """
 

	
 
    assert 'ssl-cert' in User('prosody').groups
 
    assert 'ssl-cert' in host.user('prosody').groups
 

	
 

	
 
def test_prosody_modules_directory(File):
 
def test_prosody_modules_directory(host):
 
    """
 
    Tests if directory for storing additional Prosody modules is set-up
 
    correctly.
 
    """
 

	
 
    directory = File('/usr/local/lib/prosody/modules')
 
    directory = host.file('/usr/local/lib/prosody/modules')
 

	
 
    assert directory.is_directory
 
    assert directory.user == 'root'
 
@@ -63,12 +63,12 @@ def test_prosody_modules_directory(File):
 
    assert directory.mode == 0o755
 

	
 

	
 
def test_prosody_mod_auth_ldap(File):
 
def test_prosody_mod_auth_ldap(host):
 
    """
 
    Tests if Prosody module mod_auth_ldap has been deployed correctly.
 
    """
 

	
 
    module = File('/usr/local/lib/prosody/modules/mod_auth_ldap.lua')
 
    module = host.file('/usr/local/lib/prosody/modules/mod_auth_ldap.lua')
 

	
 
    assert module.is_file
 
    assert module.user == 'root'
 
@@ -78,14 +78,14 @@ def test_prosody_mod_auth_ldap(File):
 
    assert 'mod_auth_ldap' in module.content
 

	
 

	
 
def test_prosody_configuration_file(File, Sudo):
 
def test_prosody_configuration_file(host):
 
    """
 
    Tests if Prosody configuration file has correct permissions.
 
    """
 

	
 
    with Sudo():
 
    with host.sudo():
 

	
 
        config = File('/etc/prosody/prosody.cfg.lua')
 
        config = host.file('/etc/prosody/prosody.cfg.lua')
 

	
 
        assert config.is_file
 
        assert config.user == 'root'
 
@@ -93,25 +93,25 @@ def test_prosody_configuration_file(File, Sudo):
 
        assert config.mode == 0o640
 

	
 

	
 
def test_services(Service):
 
def test_services(host):
 
    """
 
    Tests if services are enabled and running.
 
    """
 

	
 
    service = Service('prosody')
 
    service = host.service('prosody')
 

	
 
    assert service.is_enabled
 
    assert service.is_running
 

	
 

	
 
def test_firewall_configuration_file(File, Sudo):
 
def test_firewall_configuration_file(host):
 
    """
 
    Tests if firewall configuration file has been deployed correctly.
 
    """
 

	
 
    with Sudo():
 
    with host.sudo():
 

	
 
        config = File('/etc/ferm/conf.d/30-xmpp.conf')
 
        config = host.file('/etc/ferm/conf.d/30-xmpp.conf')
 

	
 
        assert config.is_file
 
        assert config.user == 'root'
roles/xmpp_server/molecule/default/tests/test_mandatory.py
Show inline comments
 
file renamed from roles/xmpp_server/tests/test_mandatory.py to roles/xmpp_server/molecule/default/tests/test_mandatory.py
 
@@ -2,58 +2,64 @@ import testinfra.utils.ansible_runner
 

	
 

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

	
 

	
 
def test_prosody_tls_files(File, Sudo):
 
def test_prosody_tls_files(host):
 
    """
 
    Tests if Prosody TLS private key and certificage have been deployed
 
    correctly.
 
    """
 

	
 
    with Sudo():
 
    hostname = host.run('hostname').stdout
 

	
 
        tls_file = File('/etc/ssl/private/parameters-mandatory.domain1_xmpp.key')
 
    with host.sudo():
 

	
 
        tls_file = host.file('/etc/ssl/private/%s.domain1_xmpp.key' % hostname)
 
        assert tls_file.is_file
 
        assert tls_file.user == 'root'
 
        assert tls_file.group == 'prosody'
 
        assert tls_file.mode == 0o640
 
        assert tls_file.content == open("tests/data/x509/parameters-mandatory.domain1_xmpp.key", "r").read().rstrip()
 
        assert tls_file.content == open("tests/data/x509/%s.domain1_xmpp.key" % hostname, "r").read().rstrip()
 

	
 
        tls_file = File('/etc/ssl/certs/parameters-mandatory.domain1_xmpp.pem')
 
        tls_file = host.file('/etc/ssl/certs/%s.domain1_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 == open("tests/data/x509/parameters-mandatory.domain1_xmpp.pem", "r").read().rstrip()
 
        assert tls_file.content == open("tests/data/x509/%s.domain1_xmpp.pem" % hostname, "r").read().rstrip()
 

	
 

	
 
def test_certificate_validity_check_configuration(File):
 
def test_certificate_validity_check_configuration(host):
 
    """
 
    Tests if certificate validity check configuration file has been deployed
 
    correctly.
 
    """
 

	
 
    config = File('/etc/check_certificate/parameters-mandatory.domain1_xmpp.conf')
 
    hostname = host.run('hostname').stdout
 

	
 
    config = host.file('/etc/check_certificate/%s.domain1_xmpp.conf' % hostname)
 
    assert config.is_file
 
    assert config.user == 'root'
 
    assert config.group == 'root'
 
    assert config.mode == 0o644
 
    assert config.content == "/etc/ssl/certs/parameters-mandatory.domain1_xmpp.pem"
 
    assert config.content == "/etc/ssl/certs/%s.domain1_xmpp.pem" % hostname
 

	
 

	
 
def test_prosody_configuration_file_content(File, Sudo):
 
def test_prosody_configuration_file_content(host):
 
    """
 
    Tests if Prosody configuration file has correct content.
 
    """
 

	
 
    with Sudo():
 
    hostname = host.run('hostname').stdout
 

	
 
    with host.sudo():
 

	
 
        config = File('/etc/prosody/prosody.cfg.lua')
 
        config = host.file('/etc/prosody/prosody.cfg.lua')
 

	
 
        assert "admins = { \"john.doe@domain1\",  }" in config.content
 
        assert "key = \"/etc/ssl/private/parameters-mandatory.domain1_xmpp.key\";" in config.content
 
        assert "certificate = \"/etc/ssl/certs/parameters-mandatory.domain1_xmpp.pem\";" in config.content
 
        assert "key = \"/etc/ssl/private/%s.domain1_xmpp.key\";" % hostname in config.content
 
        assert "certificate = \"/etc/ssl/certs/%s.domain1_xmpp.pem\";" % hostname in config.content
 
        assert "ldap_server = \"ldap-server\"" in config.content
 
        assert "ldap_rootdn = \"cn=prosody,ou=services,dc=local\"" in config.content
 
        assert "ldap_password = \"prosodypassword\"" in config.content
roles/xmpp_server/molecule/default/tests/test_optional.py
Show inline comments
 
file renamed from roles/xmpp_server/tests/test_optional.py to roles/xmpp_server/molecule/default/tests/test_optional.py
 
@@ -2,25 +2,27 @@ import testinfra.utils.ansible_runner
 

	
 

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

	
 

	
 
def test_prosody_tls_files(File, Sudo):
 
def test_prosody_tls_files(host):
 
    """
 
    Tests if Prosody TLS private key and certificage have been deployed
 
    correctly.
 
    """
 

	
 
    with Sudo():
 
    hostname = host.run('hostname').stdout
 

	
 
        tls_file = File('/etc/ssl/private/parameters-optional_xmpp.key')
 
    with host.sudo():
 

	
 
        tls_file = host.file('/etc/ssl/private/%s_xmpp.key' % hostname)
 
        assert tls_file.is_file
 
        assert tls_file.user == 'root'
 
        assert tls_file.group == 'prosody'
 
        assert tls_file.mode == 0o640
 
        assert tls_file.content == open("tests/data/x509/parameters-optional_xmpp.key.pem", "r").read().rstrip()
 

	
 
        tls_file = File('/etc/ssl/certs/parameters-optional_xmpp.pem')
 
        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'
 
@@ -28,32 +30,36 @@ def test_prosody_tls_files(File, Sudo):
 
        assert tls_file.content == open("tests/data/x509/parameters-optional_xmpp.cert.pem", "r").read().rstrip()
 

	
 

	
 
def test_certificate_validity_check_configuration(File):
 
def test_certificate_validity_check_configuration(host):
 
    """
 
    Tests if certificate validity check configuration file has been deployed
 
    correctly.
 
    """
 

	
 
    config = File('/etc/check_certificate/parameters-optional_xmpp.conf')
 
    hostname = host.run('hostname').stdout
 

	
 
    config = host.file('/etc/check_certificate/%s_xmpp.conf' % hostname)
 
    assert config.is_file
 
    assert config.user == 'root'
 
    assert config.group == 'root'
 
    assert config.mode == 0o644
 
    assert config.content == "/etc/ssl/certs/parameters-optional_xmpp.pem"
 
    assert config.content == "/etc/ssl/certs/%s_xmpp.pem" % hostname
 

	
 

	
 
def test_prosody_configuration_file_content(File, Sudo):
 
def test_prosody_configuration_file_content(host):
 
    """
 
    Tests if Prosody configuration file has correct content.
 
    """
 

	
 
    with Sudo():
 
    hostname = host.run('hostname').stdout
 

	
 
    with host.sudo():
 

	
 
        config = File('/etc/prosody/prosody.cfg.lua')
 
        config = host.file('/etc/prosody/prosody.cfg.lua')
 

	
 
        assert "admins = { \"jane.doe@domain2\", \"mick.doe@domain3\",  }" in config.content
 
        assert "key = \"/etc/ssl/private/parameters-optional_xmpp.key\";" in config.content
 
        assert "certificate = \"/etc/ssl/certs/parameters-optional_xmpp.pem\";" in config.content
 
        assert "key = \"/etc/ssl/private/%s_xmpp.key\";" % hostname in config.content
 
        assert "certificate = \"/etc/ssl/certs/%s_xmpp.pem\";" % hostname in config.content
 
        assert "ldap_server = \"ldap-server\"" in config.content
 
        assert "ldap_rootdn = \"cn=prosody,ou=services,dc=local\"" in config.content
 
        assert "ldap_password = \"prosodypassword\"" in config.content
roles/xmpp_server/tests/test_client.py
Show inline comments
 
deleted file
0 comments (0 inline, 0 general)