| 1 |
--- |
| 2 |
# Copyright (c) Ansible Project |
| 3 |
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt) |
| 4 |
# SPDX-License-Identifier: GPL-3.0-or-later |
| 5 |
|
| 6 |
#################################################################### |
| 7 |
# WARNING: These are designed specifically for Ansible tests # |
| 8 |
# and should not be used as examples of how to write Ansible roles # |
| 9 |
#################################################################### |
| 10 |
|
| 11 |
- block: |
| 12 |
- name: Find root for cert 1 using directory |
| 13 |
community.crypto.certificate_complete_chain: |
| 14 |
input_chain: '{{ fullchain | trim }}' |
| 15 |
root_certificates: |
| 16 |
- '{{ remote_tmp_dir }}/files/roots/' |
| 17 |
register: cert1_root |
| 18 |
- name: Verify root for cert 1 |
| 19 |
ansible.builtin.assert: |
| 20 |
that: |
| 21 |
- cert1_root.complete_chain | join('') == (fullchain ~ root) |
| 22 |
- cert1_root.root == root |
| 23 |
vars: |
| 24 |
fullchain: "{{ lookup('file', 'cert1-fullchain.pem', rstrip=False) }}" |
| 25 |
root: "{{ lookup('file', 'cert1-root.pem', rstrip=False) }}" |
| 26 |
|
| 27 |
- block: |
| 28 |
- name: Find rootchain for cert 1 using intermediate and root PEM |
| 29 |
community.crypto.certificate_complete_chain: |
| 30 |
input_chain: '{{ cert }}' |
| 31 |
intermediate_certificates: |
| 32 |
- '{{ remote_tmp_dir }}/files/cert1-chain.pem' |
| 33 |
root_certificates: |
| 34 |
- '{{ remote_tmp_dir }}/files/roots.pem' |
| 35 |
register: cert1_rootchain |
| 36 |
- name: Verify rootchain for cert 1 |
| 37 |
ansible.builtin.assert: |
| 38 |
that: |
| 39 |
- cert1_rootchain.complete_chain | join('') == (cert ~ chain ~ root) |
| 40 |
- cert1_rootchain.chain[:-1] | join('') == chain |
| 41 |
- cert1_rootchain.root == root |
| 42 |
vars: |
| 43 |
cert: "{{ lookup('file', 'cert1.pem', rstrip=False) }}" |
| 44 |
chain: "{{ lookup('file', 'cert1-chain.pem', rstrip=False) }}" |
| 45 |
root: "{{ lookup('file', 'cert1-root.pem', rstrip=False) }}" |
| 46 |
|
| 47 |
- block: |
| 48 |
- name: Find root for cert 2 using directory |
| 49 |
community.crypto.certificate_complete_chain: |
| 50 |
input_chain: "{{ fullchain | trim }}" |
| 51 |
root_certificates: |
| 52 |
- '{{ remote_tmp_dir }}/files/roots/' |
| 53 |
register: cert2_root |
| 54 |
- name: Verify root for cert 2 |
| 55 |
ansible.builtin.assert: |
| 56 |
that: |
| 57 |
- cert2_root.complete_chain | join('') == (fullchain ~ root) |
| 58 |
- cert2_root.root == root |
| 59 |
vars: |
| 60 |
fullchain: "{{ lookup('file', 'cert2-fullchain.pem', rstrip=False) }}" |
| 61 |
root: "{{ lookup('file', 'cert2-root.pem', rstrip=False) }}" |
| 62 |
|
| 63 |
- block: |
| 64 |
- name: Find rootchain for cert 2 using intermediate and root PEM |
| 65 |
community.crypto.certificate_complete_chain: |
| 66 |
input_chain: '{{ cert }}' |
| 67 |
intermediate_certificates: |
| 68 |
- '{{ remote_tmp_dir }}/files/cert2-chain.pem' |
| 69 |
root_certificates: |
| 70 |
- '{{ remote_tmp_dir }}/files/roots.pem' |
| 71 |
register: cert2_rootchain |
| 72 |
- name: Verify rootchain for cert 2 |
| 73 |
ansible.builtin.assert: |
| 74 |
that: |
| 75 |
- cert2_rootchain.complete_chain | join('') == (cert ~ chain ~ root) |
| 76 |
- cert2_rootchain.chain[:-1] | join('') == chain |
| 77 |
- cert2_rootchain.root == root |
| 78 |
vars: |
| 79 |
cert: "{{ lookup('file', 'cert2.pem', rstrip=False) }}" |
| 80 |
chain: "{{ lookup('file', 'cert2-chain.pem', rstrip=False) }}" |
| 81 |
root: "{{ lookup('file', 'cert2-root.pem', rstrip=False) }}" |
| 82 |
|
| 83 |
- block: |
| 84 |
- name: Find alternate rootchain for cert 2 using intermediate and root PEM |
| 85 |
community.crypto.certificate_complete_chain: |
| 86 |
input_chain: '{{ cert }}' |
| 87 |
intermediate_certificates: |
| 88 |
- '{{ remote_tmp_dir }}/files/cert2-altchain.pem' |
| 89 |
root_certificates: |
| 90 |
- '{{ remote_tmp_dir }}/files/roots.pem' |
| 91 |
register: cert2_rootchain_alt |
| 92 |
- name: Verify rootchain for cert 2 |
| 93 |
ansible.builtin.assert: |
| 94 |
that: |
| 95 |
- cert2_rootchain_alt.complete_chain | join('') == (cert ~ chain ~ root) |
| 96 |
- cert2_rootchain_alt.chain[:-1] | join('') == chain |
| 97 |
- cert2_rootchain_alt.root == root |
| 98 |
vars: |
| 99 |
cert: "{{ lookup('file', 'cert2.pem', rstrip=False) }}" |
| 100 |
chain: "{{ lookup('file', 'cert2-altchain.pem', rstrip=False) }}" |
| 101 |
root: "{{ lookup('file', 'cert2-altroot.pem', rstrip=False) }}" |
| 102 |
|
| 103 |
- block: |
| 104 |
- name: Find alternate rootchain for cert 2 when complete chain is already presented to the module |
| 105 |
community.crypto.certificate_complete_chain: |
| 106 |
input_chain: '{{ cert ~ chain ~ root }}' |
| 107 |
root_certificates: |
| 108 |
- '{{ remote_tmp_dir }}/files/roots.pem' |
| 109 |
register: cert2_complete_chain |
| 110 |
- name: Verify rootchain for cert 2 |
| 111 |
ansible.builtin.assert: |
| 112 |
that: |
| 113 |
- cert2_complete_chain.complete_chain | join('') == (cert ~ chain ~ root) |
| 114 |
- cert2_complete_chain.chain == [] |
| 115 |
- cert2_complete_chain.root == root |
| 116 |
vars: |
| 117 |
cert: "{{ lookup('file', 'cert2.pem', rstrip=False) }}" |
| 118 |
chain: "{{ lookup('file', 'cert2-altchain.pem', rstrip=False) }}" |
| 119 |
root: "{{ lookup('file', 'cert2-altroot.pem', rstrip=False) }}" |
| 120 |
|
| 121 |
- name: Check failure when no intermediate certificate can be found |
| 122 |
community.crypto.certificate_complete_chain: |
| 123 |
input_chain: '{{ lookup("file", "cert2.pem", rstrip=true) }}' |
| 124 |
intermediate_certificates: |
| 125 |
- '{{ remote_tmp_dir }}/files/cert1-chain.pem' |
| 126 |
root_certificates: |
| 127 |
- '{{ remote_tmp_dir }}/files/roots.pem' |
| 128 |
register: cert2_no_intermediate |
| 129 |
ignore_errors: true |
| 130 |
- name: Verify failure |
| 131 |
ansible.builtin.assert: |
| 132 |
that: |
| 133 |
- cert2_no_intermediate is failed |
| 134 |
- "cert2_no_intermediate.msg.startswith('Cannot complete chain. Stuck at certificate ')" |
| 135 |
|
| 136 |
- name: Check failure when infinite loop is found |
| 137 |
community.crypto.certificate_complete_chain: |
| 138 |
input_chain: '{{ lookup("file", "cert1-fullchain.pem", rstrip=true) }}' |
| 139 |
intermediate_certificates: |
| 140 |
- '{{ remote_tmp_dir }}/files/roots.pem' |
| 141 |
root_certificates: |
| 142 |
- '{{ remote_tmp_dir }}/files/cert2-chain.pem' |
| 143 |
register: cert2_infinite_loop |
| 144 |
ignore_errors: true |
| 145 |
- name: Verify failure |
| 146 |
ansible.builtin.assert: |
| 147 |
that: |
| 148 |
- cert2_infinite_loop is failed |
| 149 |
- "cert2_infinite_loop.msg == 'Found cycle while building certificate chain'" |