Skip to content

Commit

Permalink
Version 1.4.1
Browse files Browse the repository at this point in the history
Revert pinning of httpx
Minor changes to use newer server cert validation mechanics
Fixing broken tests
Updated demo app

Fixes #74
  • Loading branch information
hbldh committed Dec 9, 2024
1 parent e1d3025 commit 9a74282
Show file tree
Hide file tree
Showing 8 changed files with 22 additions and 17 deletions.
2 changes: 1 addition & 1 deletion bankid/__version__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
Version info
"""

__version__ = "1.4.0"
__version__ = "1.4.1"
version = __version__ # backwards compatibility name
2 changes: 1 addition & 1 deletion bankid/asyncclient.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def __init__(self, certificates: Tuple[str, str], test_server: bool = False, req
super().__init__(certificates, test_server, request_timeout)

headers = {"Content-Type": "application/json"}
self.client = httpx.AsyncClient(cert=self.certs, headers=headers, verify=str(self.verify_cert), timeout=request_timeout)
self.client = httpx.AsyncClient(cert=self.certs, headers=headers, verify=self.ctx, timeout=request_timeout)

async def authenticate(
self,
Expand Down
2 changes: 2 additions & 0 deletions bankid/baseclient.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import base64
import ssl
from datetime import datetime
from typing import Tuple, Dict, Any, Union, TypeVar, Generic
from urllib.parse import urljoin
Expand Down Expand Up @@ -33,6 +34,7 @@ def __init__(
else:
self.api_url = "https://appapi2.bankid.com/rp/v6.0/"
self.verify_cert = resolve_cert_path("appapi2.bankid.com.pem")
self.ctx = ssl.create_default_context(cafile=self.verify_cert)

self._auth_endpoint = urljoin(self.api_url, "auth")
self._phone_auth_endpoint = urljoin(self.api_url, "phone/auth")
Expand Down
4 changes: 2 additions & 2 deletions bankid/syncclient.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ class BankIDClient(BankIDClientBaseclass[httpx.Client]):
def __init__(self, certificates: Tuple[str, str], test_server: bool = False, request_timeout: int = 5):
super().__init__(certificates, test_server, request_timeout)

headers= {"Content-Type": "application/json"}
self.client = httpx.Client(cert=self.certs, headers=headers, verify=str(self.verify_cert), timeout=request_timeout)
headers = {"Content-Type": "application/json"}
self.client = httpx.Client(cert=self.certs, headers=headers, verify=self.ctx, timeout=request_timeout)

def authenticate(
self,
Expand Down
7 changes: 5 additions & 2 deletions examples/qrdemo/qrdemo/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from flask_caching import Cache
from bankid import BankIDClient
from bankid.exceptions import BankIDError
from bankid.certutils import create_bankid_test_server_cert_and_key
from bankid.certutils import resolve_cert_path

USE_TEST_SERVER = True

Expand All @@ -16,7 +16,10 @@
# The client should be initialized in a better way, e.g. with Flask_BankID so that it is stored in the
# Flask app. For this demo it is sufficient to let it reside globally in this file.
if USE_TEST_SERVER:
cert_paths = create_bankid_test_server_cert_and_key(str(pathlib.Path(__file__).parent))
cert_paths = (
str(resolve_cert_path("FPTestcert5_20240610_cert.pem")),
str(resolve_cert_path("FPTestcert5_20240610_key.pem"))
)
client = BankIDClient(cert_paths, test_server=True)
else:
# Set your own cert paths for you production certificate and key here.
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
httpx < 0.28
httpx
importlib_resources; python_version < "3.9"
10 changes: 5 additions & 5 deletions tests/test_asyncclient.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ async def test_authentication_and_collect(cert_and_key: Tuple[str, str], ip_addr

assert isinstance(out, dict)
# UUID.__init__ performs the UUID compliance assertion.
order_ref = uuid.UUID(out["orderRef"], version=4)
order_ref = uuid.UUID(out["orderRef"])
collect_status = await c.collect(str(order_ref))
assert collect_status.get("status") == "pending"
assert collect_status.get("hintCode") in ("outstandingTransaction", "noClient")
Expand All @@ -47,7 +47,7 @@ async def test_sign_and_collect(cert_and_key: Tuple[str, str], ip_address: str)
)
assert isinstance(out, dict)
# UUID.__init__ performs the UUID compliance assertion.
order_ref = uuid.UUID(out["orderRef"], version=4)
order_ref = uuid.UUID(out["orderRef"])
collect_status = await c.collect(str(order_ref))
assert collect_status.get("status") == "pending"
assert collect_status.get("hintCode") in ("outstandingTransaction", "noClient")
Expand All @@ -61,7 +61,7 @@ async def test_phone_sign_and_collect(cert_and_key: Tuple[str, str], random_pers
out = await c.phone_sign(random_personal_number, "RP", user_visible_data="The data to be signed")
assert isinstance(out, dict)
# UUID.__init__ performs the UUID compliance assertion.
order_ref = uuid.UUID(out["orderRef"], version=4)
order_ref = uuid.UUID(out["orderRef"])
collect_status = await c.collect(str(order_ref))
assert collect_status.get("status") == "pending"
assert collect_status.get("hintCode") in ("outstandingTransaction", "noClient")
Expand Down Expand Up @@ -103,7 +103,7 @@ async def test_authentication_and_cancel(cert_and_key: Tuple[str, str], ip_addre
out = await c.authenticate(ip_address)
assert isinstance(out, dict)
# UUID.__init__ performs the UUID compliance assertion.
order_ref = uuid.UUID(out["orderRef"], version=4)
order_ref = uuid.UUID(out["orderRef"])
collect_status = await c.collect(str(order_ref))
assert collect_status.get("status") == "pending"
assert collect_status.get("hintCode") in ("outstandingTransaction", "noClient")
Expand All @@ -121,7 +121,7 @@ async def test_phone_authentication_and_cancel(cert_and_key: Tuple[str, str], ra
out = await c.phone_authenticate(random_personal_number, "user")
assert isinstance(out, dict)
# UUID.__init__ performs the UUID compliance assertion.
order_ref = uuid.UUID(out["orderRef"], version=4)
order_ref = uuid.UUID(out["orderRef"])
collect_status = await c.collect(str(order_ref))
assert collect_status.get("status") == "pending"
assert collect_status.get("hintCode") in ("outstandingTransaction", "noClient")
Expand Down
10 changes: 5 additions & 5 deletions tests/test_syncclient.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def test_authentication_and_collect(cert_and_key: Tuple[str, str], ip_address: s
out = c.authenticate(ip_address, requirement={"personalNumber": random_personal_number})
assert isinstance(out, dict)
# UUID.__init__ performs the UUID compliance assertion.
order_ref = uuid.UUID(out["orderRef"], version=4)
order_ref = uuid.UUID(out["orderRef"])
collect_status = c.collect(str(order_ref))
assert collect_status["status"] == "pending"
assert collect_status["hintCode"] in ("outstandingTransaction", "noClient")
Expand All @@ -51,7 +51,7 @@ def test_sign_and_collect(cert_and_key: Tuple[str, str], ip_address: str) -> Non
)
assert isinstance(out, dict)
# UUID.__init__ performs the UUID compliance assertion.
order_ref = uuid.UUID(out["orderRef"], version=4)
order_ref = uuid.UUID(out["orderRef"])
collect_status = c.collect(str(order_ref))
assert collect_status["status"] == "pending"
assert collect_status["hintCode"] in ("outstandingTransaction", "noClient")
Expand All @@ -64,7 +64,7 @@ def test_phone_sign_and_collect(cert_and_key: Tuple[str, str], random_personal_n
out = c.phone_sign(random_personal_number, "user", user_visible_data="The data to be signed")
assert isinstance(out, dict)
# UUID.__init__ performs the UUID compliance assertion.
order_ref = uuid.UUID(out["orderRef"], version=4)
order_ref = uuid.UUID(out["orderRef"])
collect_status = c.collect(str(order_ref))
assert collect_status["status"] == "pending"
assert collect_status["hintCode"] in ("outstandingTransaction", "noClient")
Expand Down Expand Up @@ -99,7 +99,7 @@ def test_authentication_and_cancel(cert_and_key: Tuple[str, str], ip_address: st
out = c.authenticate(ip_address, requirement={"personalNumber": random_personal_number})
assert isinstance(out, dict)
# UUID.__init__ performs the UUID compliance assertion.
order_ref = uuid.UUID(out["orderRef"], version=4)
order_ref = uuid.UUID(out["orderRef"])
collect_status = c.collect(str(order_ref))
assert collect_status["status"] == "pending"
assert collect_status["hintCode"] in ("outstandingTransaction", "noClient")
Expand All @@ -116,7 +116,7 @@ def test_phone_authentication_and_cancel(cert_and_key: Tuple[str, str], random_p
out = c.phone_authenticate(random_personal_number, "user")
assert isinstance(out, dict)
# UUID.__init__ performs the UUID compliance assertion.
order_ref = uuid.UUID(out["orderRef"], version=4)
order_ref = uuid.UUID(out["orderRef"])
collect_status = c.collect(str(order_ref))
assert collect_status["status"] == "pending"
assert collect_status["hintCode"] in ("outstandingTransaction", "noClient")
Expand Down

0 comments on commit 9a74282

Please sign in to comment.