{{% macro fedora_gpgkey_criterion(fedora_version, pkg_release, pkg_version) %}}
   <criterion comment="Fedora {{{ fedora_version }}} package gpg-pubkey-{{{ pkg_version }}}-{{{ pkg_release }}} is installed"
        test_ref="test_fedora_package_gpgkey-{{{ pkg_version }}}-{{{ pkg_release }}}_installed" />
{{% endmacro %}}

{{% macro fedora_gpgkey_check(fedora_version, pkg_release, pkg_version) %}}
  <!-- Test for Fedora {{{ fedora_version }}} release key -->
  <linux:rpminfo_test check="only one" check_existence="at_least_one_exists"
  id="test_fedora_package_gpgkey-{{{ pkg_version }}}-{{{ pkg_release }}}_installed" version="1"
  comment="Fedora {{{ pkg_version }}} release key package is installed">
    <linux:object object_ref="object_fedora_package_gpg-pubkey" />
    <linux:state state_ref="state_fedora_package_gpg-pubkey-{{{ pkg_version }}}-{{{ pkg_release }}}" />
  </linux:rpminfo_test>

  <linux:rpminfo_state id="state_fedora_package_gpg-pubkey-{{{ pkg_version }}}-{{{ pkg_release }}}" version="1">
    <linux:release>{{{ pkg_release }}}</linux:release>
    <linux:version>{{{ pkg_version }}}</linux:version>
  </linux:rpminfo_state>
{{% endmacro %}}

<def-group>
  <definition class="compliance" id="ensure_fedora_gpgkey_installed" version="2">
    {{{ oval_metadata("The Fedora release key package is required to be installed.", rule_title=rule_title) }}}
    <criteria comment="Fedora Vendor keys" operator="AND">
      <extend_definition comment="Fedora installed" definition_ref="installed_OS_is_fedora" />
      <criteria comment="Supported Fedora key is installed" operator="OR">
          {{{ fedora_gpgkey_criterion(rawhide_version, rawhide_pkg_release, rawhide_pkg_version) }}}
          {{{ fedora_gpgkey_criterion(future_version, future_pkg_release, future_pkg_version) }}}
          {{{ fedora_gpgkey_criterion(latest_version, latest_pkg_release, latest_pkg_version) }}}
          {{{ fedora_gpgkey_criterion(previous_version, previous_pkg_release, previous_pkg_version) }}}
      </criteria>
    </criteria>
  </definition>

  <!-- First define global "object_fedora_package_gpg-pubkey" to be shared (reused) across multiple tests -->
  <linux:rpminfo_object id="object_fedora_package_gpg-pubkey" version="1">
    <linux:name>gpg-pubkey</linux:name>
  </linux:rpminfo_object>

  <!-- Perform the particular tests themselves -->
  {{{ fedora_gpgkey_check(rawhide_version, rawhide_pkg_release, rawhide_pkg_version) }}}
  {{{ fedora_gpgkey_check(future_version, future_pkg_release, future_pkg_version) }}}
  {{{ fedora_gpgkey_check(latest_version, latest_pkg_release, latest_pkg_version) }}}
  {{{ fedora_gpgkey_check(previous_version, previous_pkg_release, previous_pkg_version) }}}

</def-group>
