Skip to content

Commit

Permalink
apply manual fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
mathiasertl committed Oct 20, 2024
1 parent b5b79b9 commit a3ab134
Show file tree
Hide file tree
Showing 69 changed files with 1,425 additions and 1,688 deletions.
3 changes: 1 addition & 2 deletions ca/django_ca/tests/acme/views/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@

import abc
import typing
from collections.abc import Iterator
from http import HTTPStatus
from typing import Optional, Union
from unittest import mock
Expand Down Expand Up @@ -255,7 +254,7 @@ class AcmeWithAccountViewTestCaseMixin(
"""Mixin that also adds accounts to the database."""

@pytest.fixture
def main_account(self, account: AcmeAccount) -> Iterator[AcmeAccount]:
def main_account(self, account: AcmeAccount) -> AcmeAccount:
"""Return the main account to be used for this test case.
This is overwritten by the revocation test case.
Expand Down
22 changes: 10 additions & 12 deletions ca/django_ca/tests/acme/views/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@

# pylint: disable=redefined-outer-name

from collections.abc import Iterator

from django.test import Client

import pytest
Expand All @@ -36,32 +34,32 @@


@pytest.fixture
def account_slug() -> Iterator[str]:
def account_slug() -> str:
"""Fixture for an account slug."""
return acme_slug()


@pytest.fixture
def order_slug() -> Iterator[str]:
def order_slug() -> str:
"""Fixture for an order slug."""
return acme_slug()


@pytest.fixture
def acme_cert_slug() -> Iterator[str]:
def acme_cert_slug() -> str:
"""Fixture for an ACME certificate slug."""
return acme_slug()


@pytest.fixture
def client(client: Client) -> Iterator[Client]:
def client(client: Client) -> Client:
"""Override client fixture to set the default server name."""
client.defaults["SERVER_NAME"] = SERVER_NAME
return client


@pytest.fixture
def account(root: CertificateAuthority, account_slug: str, kid: str) -> Iterator[AcmeAccount]:
def account(root: CertificateAuthority, account_slug: str, kid: str) -> AcmeAccount:
"""Fixture for an account."""
return AcmeAccount.objects.create(
ca=root,
Expand All @@ -75,25 +73,25 @@ def account(root: CertificateAuthority, account_slug: str, kid: str) -> Iterator


@pytest.fixture
def kid(root: CertificateAuthority, account_slug: str) -> Iterator[str]:
def kid(root: CertificateAuthority, account_slug: str) -> str:
"""Fixture for a full KID."""
return absolute_acme_uri(":acme-account", serial=root.serial, slug=account_slug)


@pytest.fixture
def order(account: AcmeAccount, order_slug: str) -> Iterator[AcmeOrder]:
def order(account: AcmeAccount, order_slug: str) -> AcmeOrder:
"""Fixture for an order."""
return AcmeOrder.objects.create(account=account, slug=order_slug)


@pytest.fixture
def authz(order: AcmeOrder) -> Iterator[AcmeAuthorization]:
def authz(order: AcmeOrder) -> AcmeAuthorization:
"""Fixture for an authorization."""
return AcmeAuthorization.objects.create(order=order, value=HOST_NAME)


@pytest.fixture
def challenge(authz: AcmeAuthorization) -> Iterator[AcmeChallenge]:
def challenge(authz: AcmeAuthorization) -> AcmeChallenge:
"""Fixture for a challenge."""
challenge = authz.get_challenges()[0]
challenge.token = "foobar"
Expand All @@ -102,6 +100,6 @@ def challenge(authz: AcmeAuthorization) -> Iterator[AcmeChallenge]:


@pytest.fixture
def acme_cert(root_cert: Certificate, order: AcmeOrder, acme_cert_slug: str) -> Iterator[AcmeCertificate]:
def acme_cert(root_cert: Certificate, order: AcmeOrder, acme_cert_slug: str) -> AcmeCertificate:
"""Fixture for an ACME certificate."""
return AcmeCertificate.objects.create(order=order, cert=root_cert, slug=acme_cert_slug)
5 changes: 2 additions & 3 deletions ca/django_ca/tests/acme/views/test_authorization.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@

# pylint: disable=redefined-outer-name # because of fixtures

from collections.abc import Iterator
from http import HTTPStatus

import josepy as jose
Expand All @@ -41,13 +40,13 @@


@pytest.fixture
def url(authz: AcmeAuthorization) -> Iterator[str]:
def url(authz: AcmeAuthorization) -> str:
"""URL under test."""
return root_reverse("acme-authz", slug=authz.slug)


@pytest.fixture
def message() -> Iterator[bytes]:
def message() -> bytes:
"""Yield an empty bytestring, since this is a POST-AS-GET request."""
return b""

Expand Down
5 changes: 2 additions & 3 deletions ca/django_ca/tests/acme/views/test_challenge.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
# pylint: disable=redefined-outer-name # because of fixtures

import unittest
from collections.abc import Iterator
from http import HTTPStatus
from typing import Optional
from unittest import mock
Expand All @@ -42,13 +41,13 @@


@pytest.fixture
def url(challenge: AcmeChallenge) -> Iterator[str]:
def url(challenge: AcmeChallenge) -> str:
"""URL under test."""
return root_reverse("acme-challenge", slug=challenge.slug)


@pytest.fixture
def message() -> Iterator[bytes]:
def message() -> bytes:
"""Yield an empty bytestring, since this is a POST-AS-GET request."""
return b""

Expand Down
9 changes: 4 additions & 5 deletions ca/django_ca/tests/acme/views/test_new_account.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@

# pylint: disable=redefined-outer-name # because of fixtures

from collections.abc import Iterator
from http import HTTPStatus
from unittest import mock

Expand Down Expand Up @@ -53,19 +52,19 @@


@pytest.fixture
def url() -> Iterator[str]:
def url() -> str:
"""URL under test."""
return root_reverse("acme-new-account")


@pytest.fixture
def message() -> Iterator[Registration]:
def message() -> Registration:
"""Default message sent to the server."""
return Registration(contact=(CONTACT,), terms_of_service_agreed=True)


@pytest.fixture
def kid() -> Iterator[None]:
def kid() -> None:
"""Request requires no kid, yield None."""
return

Expand Down Expand Up @@ -228,7 +227,7 @@ def test_unsupported_contact(client: Client, url: str, root: CertificateAuthorit


@pytest.mark.parametrize(
"value,expected",
("value", "expected"),
(
('mailto:"with spaces"@example.com', "Quoted local part in email is not allowed."),
("mailto:[email protected],[email protected]", "More than one addr-spec is not allowed."),
Expand Down
8 changes: 3 additions & 5 deletions ca/django_ca/tests/acme/views/test_new_order.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@

# pylint: disable=redefined-outer-name # because of fixtures

from collections.abc import Iterator
from datetime import timedelta, timezone as tz
from http import HTTPStatus
from typing import Any
Expand Down Expand Up @@ -46,13 +45,13 @@


@pytest.fixture
def url() -> Iterator[str]:
def url() -> str:
"""URL under test."""
return root_reverse("acme-new-order")


@pytest.fixture
def message() -> Iterator[NewOrder]:
def message() -> NewOrder:
"""Default message sent to the server."""
return NewOrder(identifiers=[{"type": "dns", "value": SERVER_NAME}])

Expand Down Expand Up @@ -187,7 +186,7 @@ def test_no_identifiers(client: Client, url: str, root: CertificateAuthority, ki

@pytest.mark.usefixtures("account")
@pytest.mark.parametrize(
"values,expected",
("values", "expected"),
(
({"not_before": now - timedelta(days=1)}, "Certificate cannot be valid before now."),
({"not_after": now + timedelta(days=3650)}, "Certificate cannot be valid that long."),
Expand All @@ -201,7 +200,6 @@ def test_invalid_not_before_after(
client: Client, url: str, root: CertificateAuthority, kid: str, values: dict[str, Any], expected: str
) -> None:
"""Test invalid not_before/not_after dates."""
print(values)
message = NewOrder(identifiers=[{"type": "dns", "value": SERVER_NAME}], **values)
resp = acme_request(client, url, root, message, kid=kid)
assert_malformed(resp, root, expected)
Expand Down
5 changes: 2 additions & 3 deletions ca/django_ca/tests/acme/views/test_order.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@

# pylint: disable=redefined-outer-name # because of fixtures

from collections.abc import Iterator
from http import HTTPStatus
from typing import Optional
from unittest import mock
Expand Down Expand Up @@ -51,13 +50,13 @@


@pytest.fixture
def url(order: AcmeOrder) -> Iterator[str]:
def url(order: AcmeOrder) -> str:
"""URL under test."""
return root_reverse("acme-order", slug=order.slug)


@pytest.fixture
def message() -> Iterator[bytes]:
def message() -> bytes:
"""Yield an empty bytestring, since this is a POST-AS-GET request."""
return b""

Expand Down
9 changes: 4 additions & 5 deletions ca/django_ca/tests/acme/views/test_order_finalize.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@

# pylint: disable=redefined-outer-name

from collections.abc import Iterator
from http import HTTPStatus
from typing import Optional
from unittest import mock
Expand Down Expand Up @@ -64,29 +63,29 @@


@pytest.fixture
def order(order: AcmeOrder) -> Iterator[AcmeOrder]:
def order(order: AcmeOrder) -> AcmeOrder:
"""Override the module-level fixture to set the status to ready."""
order.status = AcmeOrder.STATUS_READY
order.save()
return order


@pytest.fixture
def authz(authz: AcmeAuthorization) -> Iterator[AcmeAuthorization]:
def authz(authz: AcmeAuthorization) -> AcmeAuthorization:
"""Override the module-level fixture to set the status to valid."""
authz.status = AcmeAuthorization.STATUS_VALID
authz.save()
return authz


@pytest.fixture
def url(order: AcmeOrder) -> Iterator[str]:
def url(order: AcmeOrder) -> str:
"""URL under test."""
return root_reverse("acme-order-finalize", slug=order.slug)


@pytest.fixture
def message() -> Iterator[CertificateRequest]:
def message() -> CertificateRequest:
"""Default message sent to the server."""
req = X509Req.from_cryptography(CSR)
return CertificateRequest(csr=jose.util.ComparableX509(req))
Expand Down
11 changes: 5 additions & 6 deletions ca/django_ca/tests/acme/views/test_revocation.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
# pylint: disable=redefined-outer-name # because of fixtures

import unittest
from collections.abc import Iterator
from datetime import datetime
from http import HTTPStatus
from typing import Any, Optional, Union
Expand Down Expand Up @@ -58,13 +57,13 @@


@pytest.fixture
def url() -> Iterator[str]:
def url() -> str:
"""URL under test."""
return root_reverse("acme-revoke")


@pytest.fixture
def message() -> Iterator[Revocation]:
def message() -> Revocation:
"""Default message sent to the server."""
default_certificate = CERT_DATA["root-cert"]["pub"]["parsed"]
return Revocation(certificate=jose.util.ComparableX509(X509.from_cryptography(default_certificate)))
Expand Down Expand Up @@ -107,7 +106,7 @@ def acme(
return acme_request(client, url, ca, message, kid=kid)

@pytest.mark.parametrize(
"use_tz, timestamp",
("use_tz", "timestamp"),
((True, TIMESTAMPS["everything_valid"]), (False, TIMESTAMPS["everything_valid_naive"])),
)
def test_basic(
Expand Down Expand Up @@ -218,7 +217,7 @@ class TestAcmeCertificateRevocationWithAuthorizationsView(TestAcmeCertificateRev
CHILD_SLUG = acme_slug()

@pytest.fixture
def child_kid_fixture(self, root: CertificateAuthority) -> Iterator[str]:
def child_kid_fixture(self, root: CertificateAuthority) -> str:
"""Fixture to set compute the child KID."""
return self.absolute_uri(":acme-account", serial=root.serial, slug=self.CHILD_SLUG)

Expand Down Expand Up @@ -287,7 +286,7 @@ def test_wrong_url(self) -> None: # type: ignore[override]
pass

@pytest.fixture
def kid(self, child_kid_fixture: str) -> Iterator[Optional[str]]:
def kid(self, child_kid_fixture: str) -> Optional[str]:
"""Override kid to return the child kid."""
return child_kid_fixture

Expand Down
5 changes: 2 additions & 3 deletions ca/django_ca/tests/acme/views/test_update_account.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
# pylint: disable=redefined-outer-name # because of fixtures

import unittest
from collections.abc import Iterator
from http import HTTPStatus

from acme.messages import IDENTIFIER_FQDN, Identifier, Registration
Expand All @@ -39,13 +38,13 @@


@pytest.fixture
def url(account_slug: str) -> Iterator[str]:
def url(account_slug: str) -> str:
"""URL under test."""
return root_reverse("acme-account", slug=account_slug)


@pytest.fixture
def message() -> Iterator[Registration]:
def message() -> Registration:
"""Default message sent to the server."""
return Registration()

Expand Down
Loading

0 comments on commit a3ab134

Please sign in to comment.