---
# Copyright (c) Ansible Project
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
# SPDX-License-Identifier: GPL-3.0-or-later

####################################################################
# WARNING: These are designed specifically for Ansible tests       #
# and should not be used as examples of how to write Ansible roles #
####################################################################

- name: Case A => works
  certificate_complete_chain:
    input_chain: "{{ read_certificates['d-leaf'] }}"
    intermediate_certificates:
    - '{{ remote_tmp_dir }}/b-intermediate.pem'
    root_certificates:
    - '{{ remote_tmp_dir }}/a-root.pem'

- name: Case B => doesn't work, but this is expected
  failed_when: false
  register: caseb
  certificate_complete_chain:
    input_chain: "{{ read_certificates['d-leaf'] }}"
    intermediate_certificates:
    - '{{ remote_tmp_dir }}/c-intermediate.pem'
    root_certificates:
    - '{{ remote_tmp_dir }}/a-root.pem'

- name: Assert that case B failed
  assert:
    that: "'Cannot complete chain' in caseb.msg"

- name: Case C => works
  certificate_complete_chain:
    input_chain: "{{ read_certificates['d-leaf'] }}"
    intermediate_certificates:
    - '{{ remote_tmp_dir }}/c-intermediate.pem'
    - '{{ remote_tmp_dir }}/b-intermediate.pem'
    root_certificates:
    - '{{ remote_tmp_dir }}/a-root.pem'

- name: Case D => works as well after PR 403
  certificate_complete_chain:
    input_chain: "{{ read_certificates['d-leaf'] }}"
    intermediate_certificates:
    - '{{ remote_tmp_dir }}/b-intermediate.pem'
    - '{{ remote_tmp_dir }}/c-intermediate.pem'
    root_certificates:
    - '{{ remote_tmp_dir }}/a-root.pem'
