Skip to content

Commit

Permalink
Add factory to tests module
Browse files Browse the repository at this point in the history
  • Loading branch information
Viicos committed Oct 9, 2023
1 parent b3478a9 commit 703fe74
Show file tree
Hide file tree
Showing 8 changed files with 139 additions and 6 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:
name: Run the test suite (Python ${{ matrix.python }}, Django ${{ matrix.django }})

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python }}
Expand All @@ -42,7 +42,7 @@ jobs:
DJANGO: ${{ matrix.django }}

- name: Publish coverage report
uses: codecov/codecov-action@v3
uses: codecov/codecov-action@v4

publish:
name: Publish package to PyPI
Expand All @@ -52,10 +52,10 @@ jobs:
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags')

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- uses: actions/setup-python@v4
with:
python-version: '3.9'
python-version: '3.10'

- name: Build sdist and wheel
run: |
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/code_quality.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ jobs:
matrix:
toxenv: [isort, black, flake8, docs]
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- uses: actions/setup-python@v4
with:
python-version: '3.9'
python-version: '3.10'
- name: Install dependencies
run: pip install tox
- run: tox
Expand Down
3 changes: 3 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ classifiers =
zip_safe = False
include_package_data = True
packages = find:
python_requires = >=3.7
install_requires =
django >= 3.2
django-privates >= 1.5
Expand All @@ -56,6 +57,8 @@ include =
simple_certmanager.*

[options.extras_require]
testsutils =
factory-boy
tests =
pytest
pytest-django
Expand Down
Empty file.
16 changes: 16 additions & 0 deletions simple_certmanager/tests/data/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Test files for mTLS via simple_certmanager.Certificate models

## Certificate and key

The test.certificate and the test.key were generated using the following command:

```bash
openssl req -newkey rsa:4096 -x509 -sha256 -days 365 -nodes -out test.certificate -keyout test.key
```

The tests making use of these certificates are:

- `src/zgw_consumers_ext/tests/test_client_factory.py`
- `src/openforms/appointments/contrib/qmatic/tests/test_client.py`

These tests will potentially start failing once the test certificate expires.
33 changes: 33 additions & 0 deletions simple_certmanager/tests/data/test.certificate
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
-----BEGIN CERTIFICATE-----
MIIFvTCCA6WgAwIBAgIUMzTMR5GJmyJOvSl6rXId64MDha4wDQYJKoZIhvcNAQEL
BQAwbjELMAkGA1UEBhMCTkwxFjAUBgNVBAgMDU5vb3JkLUhvbGxhbmQxEjAQBgNV
BAcMCUFtc3RlcmRhbTEZMBcGA1UECgwQT3BlbiBGb3JtdWxpZXJlbjEYMBYGA1UE
AwwPb3BlbmZvcm11bGllcmVuMB4XDTIzMDkxODE2MzYzOVoXDTI0MDkxNzE2MzYz
OVowbjELMAkGA1UEBhMCTkwxFjAUBgNVBAgMDU5vb3JkLUhvbGxhbmQxEjAQBgNV
BAcMCUFtc3RlcmRhbTEZMBcGA1UECgwQT3BlbiBGb3JtdWxpZXJlbjEYMBYGA1UE
AwwPb3BlbmZvcm11bGllcmVuMIICIjANBgkqhkiG9w0BAQEFAAOCAg8AMIICCgKC
AgEAw2ZCq8faQO81SdqjmcnMLK1of978Sz+F8ywFGsrV/1kEL4IZpucn7TTkJ4Aa
x0YFh3EYf4kRdB9OoL9ZfCLC4ccA9gcSV6FjL8l5SxSUlderMgtqSEqQuYsb2Yoa
GkNZ2I0XZg1iiFZDDX/TpHNhUy/rD9ZPZQ0jK1SKvyPhJy24Q5PqECuhkqBHuQnP
AxcVaHUf2LMU5v6ZPkQfBjrsD9XNPia/v/Lp5IaPLGqMLDtryU609XxB4I0Wncri
aGV5NGRB9ajzB4TpVIFjpeG9nqt5EYqRKuV9MHus4fY4gP/Jmxuy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9jc4VUj1BX5rxGOZHLxreZ5HhO4Bec3FO/DnCih15LPeX3+
1knK3WO0iDF4IvGNcdLAGOvxo4IJs1BvGWrGCDdaxdk+z7a3UhiM+kwdrMA3Jv3s
7CAM8RLViegSaC+onpQkctn+JVBMq2NUVM1ZiyHIJtD5
-----END CERTIFICATE-----
52 changes: 52 additions & 0 deletions simple_certmanager/tests/data/test.key
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
-----BEGIN PRIVATE KEY-----
MIIJQgIBADANBgkqhkiG9w0BAQEFAASCCSwwggkoAgEAAoICAQDDZkKrx9pA7zVJ
2qOZycwsrWh/3vxLP4XzLAUaytX/WQQvghmm5yftNOQngBrHRgWHcRh/iRF0H06g
v1l8IsLhxwD2BxJXoWMvyXlLFJSV16syC2pISpC5ixvZihoaQ1nYjRdmDWKIVkMN
f9Okc2FTL+sP1k9lDSMrVIq/I+EnLbhDk+oQK6GSoEe5Cc8DFxVodR/YsxTm/pk+
RB8GOuwP1c0+Jr+/8unkho8saowsO2vJTrT1fEHgjRadyuJoZXk0ZEH1qPMHhOlU
gWOl4b2eq3kRipEq5X0we6zh9jiA/8mbG7JYvI8RhLlVYkwk4KnJva3/x3tkSf9L
L9kHcmtCZofpWkK++wxfdqMYDrYTEHLb6eCA3gMXZenf2YyLv/bq2PcljhIoPSh7
xJBWfCYfifz3EhVUPm0s6pBWRKj4++bqPdbIJYd0xGndGnA3Ow5JxTOndWzvhTS2
mD2nJ7Ev12+Ouxmp6RODlnqTaKAmwKa9yKFppOv3+UZmXBc4aT7w3jXUCcNau/dV
9mOV8rz0pNK7pUUXJz80CtUWK76cMe8GbpxrSYUC5DpQ6KyprIzdeAzZ/0M2egjB
nzRtJ2agVtOTvjsTUhYhf1t/Ephk5xTB/BCm5t8k8CpuTCJm73I9sRY+VD2ZoFFo
4HK/UpGll3Pzq6LL2EJfw/mdz76cIwIDAQABAoICAAMZaqJN47TW9nnq6WBlloL4
5yjsEQVihw3h21ze7cEEmO/l+OEw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4emPfNwjk92va60MH6IlAgwaSPGS7Qsgxpu8UoU1FPV
1Qpw9+loft8eUdRl6H2i1GU2LWjcjG5BnLKyCuly9eCrOkEsjqrX/59ggPjs02Ok
d95R9LXgCA+XZGyfMKp/9ndIrCxCSYdq5zXWK6mTYl6tvI7crBd6shPk6fVS1Nni
uAFbCr9IxKpwJ9GKuC/hakit9EnOqrl0F8rEJGpuOFCsGXGt0lSmksEN6G64Gs6I
LFg4KO/pXNCP8nnieqfzHufJYz0wzA==
-----END PRIVATE KEY-----
29 changes: 29 additions & 0 deletions simple_certmanager/tests/factories.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
from pathlib import Path

import factory

from ..constants import CertificateTypes
from ..models import Certificate

DATA_DIR = Path(__file__).parent.resolve() / "data"


class CertificateFactory(factory.django.DjangoModelFactory):
label = factory.Sequence(lambda n: f"certificate-{n}")
type = CertificateTypes.cert_only
public_certificate = factory.django.FileField(
from_path=str(DATA_DIR / "test.certificate"),
filename="cert.pem",
)

class Meta:
model = Certificate

class Params:
with_private_key = factory.Trait(
type=CertificateTypes.key_pair,
private_key=factory.django.FileField(
from_path=str(DATA_DIR / "test.key"),
filename="key.pem",
),
)

0 comments on commit 703fe74

Please sign in to comment.