2019-08-17 16:02:14 +02:00
|
|
|
---
|
2018-12-07 14:27:16 +01:00
|
|
|
- name: Get servers certificate
|
|
|
|
get_certificate:
|
|
|
|
host: "{{ httpbin_host }}"
|
|
|
|
port: 443
|
2019-08-17 16:02:14 +02:00
|
|
|
select_crypto_backend: "{{ select_crypto_backend }}"
|
2018-12-07 14:27:16 +01:00
|
|
|
register: result
|
|
|
|
|
|
|
|
- debug: var=result
|
|
|
|
|
|
|
|
- assert:
|
|
|
|
that:
|
|
|
|
# This module should never change anything
|
|
|
|
- result is not changed
|
|
|
|
- result is not failed
|
|
|
|
# We got the correct ST from the cert
|
|
|
|
- "'North Carolina' == result.subject.ST"
|
|
|
|
|
|
|
|
- name: Connect to http port (will fail because there is no SSL cert to get)
|
|
|
|
get_certificate:
|
|
|
|
host: "{{ httpbin_host }}"
|
|
|
|
port: 80
|
2019-08-17 16:02:14 +02:00
|
|
|
select_crypto_backend: "{{ select_crypto_backend }}"
|
2018-12-07 14:27:16 +01:00
|
|
|
register: result
|
|
|
|
ignore_errors: true
|
|
|
|
|
|
|
|
- assert:
|
|
|
|
that:
|
|
|
|
- result is not changed
|
|
|
|
- result is failed
|
|
|
|
# We got the expected error message
|
|
|
|
- "'The handshake operation timed out' in result.msg or 'unknown protocol' in result.msg or 'wrong version number' in result.msg"
|
|
|
|
|
|
|
|
- name: Test timeout option
|
|
|
|
get_certificate:
|
|
|
|
host: "{{ httpbin_host }}"
|
|
|
|
port: 1234
|
|
|
|
timeout: 1
|
2019-08-17 16:02:14 +02:00
|
|
|
select_crypto_backend: "{{ select_crypto_backend }}"
|
2018-12-07 14:27:16 +01:00
|
|
|
register: result
|
|
|
|
ignore_errors: true
|
|
|
|
|
|
|
|
- assert:
|
|
|
|
that:
|
|
|
|
- result is not changed
|
|
|
|
- result is failed
|
|
|
|
# We got the expected error message
|
|
|
|
- "'Failed to get cert from port with error: timed out' == result.msg or 'Connection refused' in result.msg"
|
|
|
|
|
2019-03-28 15:38:18 +01:00
|
|
|
- name: Test failure if ca_cert is not a valid file
|
2018-12-07 14:27:16 +01:00
|
|
|
get_certificate:
|
|
|
|
host: "{{ httpbin_host }}"
|
|
|
|
port: 443
|
2019-03-28 15:38:18 +01:00
|
|
|
ca_cert: dn.e
|
2019-08-17 16:02:14 +02:00
|
|
|
select_crypto_backend: "{{ select_crypto_backend }}"
|
2018-12-07 14:27:16 +01:00
|
|
|
register: result
|
|
|
|
ignore_errors: true
|
|
|
|
|
|
|
|
- assert:
|
|
|
|
that:
|
|
|
|
- result is not changed
|
|
|
|
- result is failed
|
|
|
|
# We got the correct response from the module
|
2019-03-28 06:19:28 +01:00
|
|
|
- "'ca_cert file does not exist' == result.msg"
|
2018-12-07 14:27:16 +01:00
|
|
|
|
|
|
|
- name: Download CA Cert as pem from server
|
|
|
|
get_url:
|
|
|
|
url: "http://ansible.http.tests/cacert.pem"
|
|
|
|
dest: "{{ output_dir }}/temp.pem"
|
|
|
|
|
|
|
|
- name: Get servers certificate comparing it to its own ca_cert file
|
|
|
|
get_certificate:
|
2019-03-28 15:38:18 +01:00
|
|
|
ca_cert: '{{ output_dir }}/temp.pem'
|
2018-12-07 14:27:16 +01:00
|
|
|
host: "{{ httpbin_host }}"
|
|
|
|
port: 443
|
2019-08-17 16:02:14 +02:00
|
|
|
select_crypto_backend: "{{ select_crypto_backend }}"
|
2018-12-07 14:27:16 +01:00
|
|
|
register: result
|
|
|
|
|
|
|
|
- assert:
|
|
|
|
that:
|
|
|
|
- result is not changed
|
|
|
|
- result is not failed
|
|
|
|
|
|
|
|
- name: Get a temp directory
|
|
|
|
tempfile:
|
|
|
|
state: directory
|
|
|
|
register: my_temp_dir
|
|
|
|
|
|
|
|
- name: Deploy the bogus_ca.pem file
|
|
|
|
copy:
|
|
|
|
src: "bogus_ca.pem"
|
|
|
|
dest: "{{ my_temp_dir.path }}/bogus_ca.pem"
|
|
|
|
|
|
|
|
- name: Get servers certificate comparing it to an invalid ca_cert file
|
|
|
|
get_certificate:
|
2019-03-28 15:38:18 +01:00
|
|
|
ca_cert: '{{ my_temp_dir.path }}/bogus_ca.pem'
|
2018-12-07 14:27:16 +01:00
|
|
|
host: "{{ httpbin_host }}"
|
|
|
|
port: 443
|
2019-08-17 16:02:14 +02:00
|
|
|
select_crypto_backend: "{{ select_crypto_backend }}"
|
2018-12-07 14:27:16 +01:00
|
|
|
register: result
|
|
|
|
ignore_errors: true
|
|
|
|
|
|
|
|
- assert:
|
|
|
|
that:
|
|
|
|
- result is not changed
|
|
|
|
- result.failed
|