mirror of
https://github.com/ansible-collections/community.crypto.git
synced 2026-05-06 21:33:00 +00:00
* Enable basic type checking. * Fix first errors. * Add changelog fragment. * Add types to module_utils and plugin_utils (without module backends). * Add typing hints for acme_* modules. * Add typing to X.509 certificate modules, and add more helpers. * Add typing to remaining module backends. * Add typing for action, filter, and lookup plugins. * Bump ansible-core 2.19 beta requirement for typing. * Add more typing definitions. * Add typing to some unit tests.
57 lines
1.6 KiB
Python
57 lines
1.6 KiB
Python
# 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
|
|
|
|
from __future__ import annotations
|
|
|
|
from unittest.mock import (
|
|
MagicMock,
|
|
)
|
|
|
|
import pytest
|
|
from ansible_collections.community.crypto.plugins.module_utils.acme.errors import (
|
|
ACMEProtocolException,
|
|
)
|
|
from ansible_collections.community.crypto.plugins.module_utils.acme.orders import Order
|
|
|
|
|
|
def test_order_from_json() -> None:
|
|
client = MagicMock()
|
|
|
|
data = {
|
|
"status": "valid",
|
|
"identifiers": [],
|
|
"authorizations": [],
|
|
}
|
|
client.version = 2
|
|
order = Order.from_json(client, data, "xxx")
|
|
assert order.data == data
|
|
assert order.url == "xxx"
|
|
assert order.status == "valid"
|
|
assert order.identifiers == []
|
|
assert order.finalize_uri is None
|
|
assert order.certificate_uri is None
|
|
assert order.authorization_uris == []
|
|
assert order.authorizations == {}
|
|
|
|
|
|
def test_wait_for_finalization_error() -> None:
|
|
client = MagicMock()
|
|
client.version = 2
|
|
|
|
data = {
|
|
"status": "invalid",
|
|
"identifiers": [],
|
|
"authorizations": [],
|
|
}
|
|
order = Order.from_json(client, data, "xxx")
|
|
|
|
client.get_request = MagicMock(return_value=(data, {}))
|
|
with pytest.raises(ACMEProtocolException) as exc:
|
|
order.wait_for_finalization(client)
|
|
|
|
assert exc.value.msg.startswith(
|
|
'Failed to wait for order to complete; got status "invalid". The JSON result: '
|
|
)
|
|
assert exc.value.module_fail_args == {}
|