Skip to content

Commit

Permalink
Merge pull request #67 from thorgate/updates
Browse files Browse the repository at this point in the history
Support django 4.0 and above
  • Loading branch information
Jyrno42 authored Mar 7, 2023
2 parents 4a4227b + 76d2877 commit 512c8cd
Show file tree
Hide file tree
Showing 23 changed files with 831 additions and 825 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ jobs:
- name: Setup python for test ${{ matrix.python }}
uses: actions/setup-python@v2
with:
python-version: 3.9
python-version: 3.11
- name: Add poetry
uses: abatilo/actions-poetry@v2.1.3
uses: abatilo/actions-poetry@v2.3.0
with:
poetry-version: "1.1.11"
poetry-version: "1.4.0"
- uses: actions/checkout@v2
- name: Set poetry token
run: poetry config http-basic.pypi __token__ ${{ secrets.POETRY_TOKEN }}
Expand Down
33 changes: 16 additions & 17 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,40 +6,39 @@ jobs:
strategy:
matrix:
include:
# Can't enable this as it requires a custom runner.
#- python: "3.6"
# DJANGO: "1.11"
# os: ubuntu-16.07

- python: "3.6"
DJANGO: "2.0"
- python: "3.8"
DJANGO: "2.1"
os: ubuntu-latest

- python: "3.6"
- python: "3.8"
DJANGO: "3.0"
os: ubuntu-latest

- python: "3.7"
DJANGO: "2.1"
COVERALLS: 1
- python: "3.9"
DJANGO: "4.0"
os: ubuntu-latest

- python: "3.8"
DJANGO: "2.0"
- python: "3.9"
DJANGO: "4.1"
os: ubuntu-latest

- python: "3.8"
DJANGO: "3.0"
- python: "3.11"
DJANGO: "4.0"
os: ubuntu-latest

- python: "3.11"
DJANGO: "4.1"
COVERALLS: 1
os: ubuntu-latest
steps:
- name: Setup python for test ${{ matrix.python }}
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python }}
- name: Add poetry
uses: abatilo/actions-poetry@v2.1.3
uses: abatilo/actions-poetry@v2.3.0
with:
poetry-version: "1.1.11"
poetry-version: "1.4.0"
- uses: actions/checkout@v2
- name: Install tox
run: python -m pip install tox
Expand Down
62 changes: 0 additions & 62 deletions .travis.yml

This file was deleted.

4 changes: 4 additions & 0 deletions conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ def signed_doc_dict():
"issuer": "C=EE/O=AS Sertifitseerimiskeskus/CN=TEST of EE Certification Centre Root CA/"
"[email protected]",
"issuer_serial": "138983222239407220571566848351990841243",
"issuer_country": "EE",
"policies": [
{
"description": "Ainult testimiseks. Only for testing.",
Expand All @@ -44,6 +45,7 @@ def signed_doc_dict():
],
"subject": "C=EE/O=AS Sertifitseerimiskeskus/OU=OCSP/CN=TEST of SK OCSP RESPONDER 2011/"
"[email protected]",
"subject_country": "EE",
"valid_from": "2011-03-07T13:22:45Z",
"valid_to": "2024-09-07T12:22:45Z",
},
Expand All @@ -56,6 +58,7 @@ def signed_doc_dict():
"certificate": {
"issuer": "C=EE/O=AS Sertifitseerimiskeskus/CN=TEST of ESTEID-SK 2011/[email protected]",
"issuer_serial": "61232248526689391803484677403602728985",
"issuer_country": "EE",
"policies": [
{
"description": "Ainult testimiseks. Only for testing.",
Expand All @@ -65,6 +68,7 @@ def signed_doc_dict():
],
"subject": "C=EE/O=ESTEID (MOBIIL-ID)/OU=digital signature/CN=TESTNUMBER,SEITSMES,14212128025"
"/SN=TESTNUMBER/GN=SEITSMES/serialNumber=14212128025",
"subject_country": "EE",
"valid_from": "2015-04-06T09:45:41Z",
"valid_to": "2016-12-31T21:59:59Z",
},
Expand Down
2 changes: 1 addition & 1 deletion esteid/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "3.2"
__version__ = "3.3"
1 change: 0 additions & 1 deletion esteid/actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,6 @@ def do_action(
class MobileIdStatusAction(BaseAction):
@classmethod
def do_action(cls, view: "GenericDigitalSignViewMixin", params: dict = None):

request = view.request
session_data = get_esteid_session(request)
if not session_data:
Expand Down
2 changes: 0 additions & 2 deletions esteid/authentication/tests/test_authenticator.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ class MyAuthenticator(Authenticator):


def test_authenticator_init__initial_true(test_session_data):

# Empty session: OK
session = {}
authenticator = Authenticator(session, initial=True)
Expand Down Expand Up @@ -80,7 +79,6 @@ def test_authenticator_init__initial_true(test_session_data):


def test_authenticator_init__initial_false(test_session_data):

# Wrong data: empty
session = {}
with pytest.raises(SigningSessionDoesNotExist):
Expand Down
12 changes: 6 additions & 6 deletions esteid/flowtest/urls.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from django.conf.urls import url
from django.urls import re_path

from esteid.mobileid import MobileIdAuthenticator # noqa
from esteid.signing import Signer
Expand All @@ -10,19 +10,19 @@
# Signing

urlpatterns = [
url(f"^sign/{method}/", SigningTestView.as_view(signing_method=method), name=f"sign-{method}")
re_path(f"^sign/{method}/", SigningTestView.as_view(signing_method=method), name=f"sign-{method}")
for method in Signer.SIGNING_METHODS
]

urlpatterns += [
url(f"^sign-rest/{method}/", SigningTestRestView.as_view(signing_method=method), name=f"sign-rest-{method}")
re_path(f"^sign-rest/{method}/", SigningTestRestView.as_view(signing_method=method), name=f"sign-rest-{method}")
for method in Signer.SIGNING_METHODS
]

# Authentication

urlpatterns += [
url(
re_path(
f"^authenticate/{auth_class.get_method_name()}/",
AuthTestView.as_view(authenticator=auth_class),
name=f"auth-{auth_class.get_method_name()}",
Expand All @@ -31,7 +31,7 @@
]

urlpatterns += [
url(
re_path(
f"^authenticate-rest/{auth_class.get_method_name()}/",
AuthTestRestView.as_view(authenticator=auth_class),
name=f"auth-rest-{auth_class.get_method_name()}",
Expand All @@ -41,5 +41,5 @@

urlpatterns += [
# See idcard/README.md as to why this view is special.
url("^authenticate-id-card/", IDCardAuthTestView.as_view(), name="auth-idcard")
re_path("^authenticate-id-card/", IDCardAuthTestView.as_view(), name="auth-idcard")
]
2 changes: 1 addition & 1 deletion esteid/mobileid/i18n.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from django.core.exceptions import ImproperlyConfigured
from django.utils.translation import ugettext_lazy as _
from django.utils.translation import gettext_lazy as _

from esteid import settings

Expand Down
4 changes: 2 additions & 2 deletions esteid/ocsp.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import warnings
from tempfile import NamedTemporaryFile

from django.utils.encoding import force_bytes, force_text
from django.utils.encoding import force_bytes, force_str
from esteid_certificates import get_certificate_file_name, UnknownCertificateError


Expand Down Expand Up @@ -58,7 +58,7 @@ def verify(self):

try:
output = subprocess.check_output(" ".join(args), stderr=subprocess.STDOUT, shell=True)
output = force_text(output)
output = force_str(output)

if ": good" in output:
result = 0
Expand Down
2 changes: 0 additions & 2 deletions esteid/signing/tests/test_signer.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ class MySigner(Signer):


def test_signer_init__initial_true(test_session_data):

# Empty session: OK
session = {}
signer = Signer(session, initial=True)
Expand Down Expand Up @@ -84,7 +83,6 @@ def test_signer_init__initial_true(test_session_data):


def test_signer_init__initial_false(test_session_data):

# Wrong data: empty session
session = {}
with pytest.raises(SigningSessionDoesNotExist):
Expand Down
2 changes: 1 addition & 1 deletion esteid/smartid/apps.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from django.apps import AppConfig
from django.utils.translation import ugettext_lazy as _
from django.utils.translation import gettext_lazy as _


class SmartIDConfig(AppConfig):
Expand Down
2 changes: 1 addition & 1 deletion esteid/smartid/i18n.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from django.core.exceptions import ImproperlyConfigured
from django.utils.translation import ugettext_lazy as _
from django.utils.translation import gettext_lazy as _

from esteid import settings

Expand Down
8 changes: 4 additions & 4 deletions esteid/smartid/tests/test_auth_and_sign_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ def test_all_hash_algorithms(demo_api, hash_type, SMARTID_DEMO_ID_CODE_EE):
"""
status_res = run_authentication_flow(demo_api, SMARTID_DEMO_ID_CODE_EE, Countries.ESTONIA, hash_type)

assert status_res.document_number == "PNOEE-30303039914-5QSV-Q"
assert status_res.document_number == "PNOEE-30303039914-MOCK-Q"
assert status_res.certificate
assert status_res.certificate_level == CERTIFICATE_LEVEL_QUALIFIED

Expand All @@ -144,7 +144,7 @@ def test_authentication_flow_ee(demo_api, SMARTID_DEMO_ID_CODE_EE):
"""
status_res = run_authentication_flow(demo_api, SMARTID_DEMO_ID_CODE_EE, Countries.ESTONIA)

assert status_res.document_number == f"PNOEE-{SMARTID_DEMO_ID_CODE_EE}-5QSV-Q"
assert status_res.document_number == f"PNOEE-{SMARTID_DEMO_ID_CODE_EE}-MOCK-Q"
assert status_res.certificate
assert status_res.certificate_level == CERTIFICATE_LEVEL_QUALIFIED

Expand All @@ -157,7 +157,7 @@ def test_authentication_flow_lv(demo_api, SMARTID_DEMO_ID_CODE_LV):
"""
status_res = run_authentication_flow(demo_api, SMARTID_DEMO_ID_CODE_LV, Countries.LATVIA)

assert status_res.document_number == f"PNOLV-{SMARTID_DEMO_ID_CODE_LV}-0DJ2-Q"
assert status_res.document_number == f"PNOLV-{SMARTID_DEMO_ID_CODE_LV}-MOCK-Q"
assert status_res.certificate
assert status_res.certificate_level == CERTIFICATE_LEVEL_QUALIFIED

Expand All @@ -170,7 +170,7 @@ def test_authentication_flow_lt(demo_api, SMARTID_DEMO_ID_CODE_LT):
"""
status_res = run_authentication_flow(demo_api, SMARTID_DEMO_ID_CODE_LT, Countries.LITHUANIA)

assert status_res.document_number == f"PNOLT-{SMARTID_DEMO_ID_CODE_LT}-PBZK-Q"
assert status_res.document_number == f"PNOLT-{SMARTID_DEMO_ID_CODE_LT}-MOCK-Q"
assert status_res.certificate
assert status_res.certificate_level == CERTIFICATE_LEVEL_QUALIFIED

Expand Down
2 changes: 2 additions & 0 deletions esteid/tests/test_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,11 @@ def test_certificate_from_cert(static_certificate, cert_type):
"Organization Identifier: NTREE-10747013, "
"Organization: AS Sertifitseerimiskeskus, Country: EE"
)
assert cert_data.issuer_country == "EE"
assert cert_data.valid_from.isoformat() == "2017-02-02T09:14:37+00:00"
assert cert_data.valid_to.isoformat() == "2022-02-01T21:59:59+00:00"
assert cert_data.subject == "SMART-ID,HELLO,PNOEE-11702020200"
assert cert_data.subject_country == "EE"


@pytest.mark.parametrize("cert_type", ["bytes", "asn1", "oscrypto"])
Expand Down
9 changes: 9 additions & 0 deletions esteid/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,20 @@ class CertificatePolicy(FromDictMixin):
description = attr.ib(default=None)


@attr.s
class CertificateIssuer(FromDictMixin):
pass


@attr.s
class Certificate(FromDictMixin):
issuer = attr.ib()
issuer_serial = attr.ib()
subject = attr.ib()
valid_from: datetime = attr.ib(converter=convert_time)
valid_to: datetime = attr.ib(converter=convert_time)
issuer_country = attr.ib(default=None)
subject_country = attr.ib(default=None)

policies = attr.ib(
default=attr.Factory(list),
Expand All @@ -68,8 +75,10 @@ def from_certificate(cls, cert: "Union[bytes, Asn1CryptoCertificate, OsCryptoCer

return cls(
issuer=issuer.human_friendly,
issuer_country=issuer.native["country_name"],
issuer_serial=str(serial),
subject=personal["common_name"],
subject_country=personal["country_name"],
valid_from=valid_from.replace(microsecond=0).astimezone(pytz.utc),
valid_to=valid_to.replace(microsecond=0).astimezone(pytz.utc),
)
Expand Down
Loading

0 comments on commit 512c8cd

Please sign in to comment.