Skip to content

Commit ec7649f

Browse files
committed
🐛 reject unsupported PC/SC profile reads
1 parent 91fa58a commit ec7649f

2 files changed

Lines changed: 26 additions & 15 deletions

File tree

src/schnee/adapters/backend/pcsc/backend.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ class PcscBackendError(Exception):
2020
class UnsupportedPlanError(PcscBackendError):
2121
"""Raised when a write plan is not implemented by the PC/SC backend."""
2222

23+
class UnsupportedProfileReadError(PcscBackendError):
24+
"""Raised when full profile reads are not implemented."""
25+
2326
def __init__(self, reader: PcscReader) -> None:
2427
self.reader = reader
2528
self.client = PcscApduClient(reader)
@@ -38,13 +41,16 @@ def send_apdu(self, apdu: CommandAPDU | list[int]) -> ResponseAPDU:
3841
return self.client.send_apdu(apdu)
3942

4043
def read_profile(self) -> TagProfile:
41-
"""Read the currently reachable NTAG profile summary."""
44+
"""Read the currently reachable NTAG profile."""
45+
msg = "PC/SC full profile reads are not implemented yet"
46+
raise self.UnsupportedProfileReadError(msg)
47+
48+
def read_tag_info(self) -> TagInfo:
49+
"""Read the currently reachable NTAG tag identity summary."""
4250
uid = self._read_uid()
43-
return TagProfile(
44-
tag=TagInfo(
45-
uid=uid,
46-
features=["pcsc"],
47-
),
51+
return TagInfo(
52+
uid=uid,
53+
features=["pcsc"],
4854
)
4955

5056
def apply_plan(self, plan: ChangePlan) -> TagProfile:

tests/schnee/adapters/backend/pcsc/test_backend.py

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,12 @@
22

33
from __future__ import annotations
44

5-
from typing import TYPE_CHECKING
5+
import pytest
66

77
from schnee.adapters.backend import PcscBackend
88
from schnee.adapters.backend.pcsc import PcscReaderProvider
99
from schnee.adapters.ntag.apdu import CommandAPDU
1010

11-
if TYPE_CHECKING:
12-
import pytest
13-
1411

1512
class FakeConnection:
1613
"""Fake PC/SC connection."""
@@ -44,19 +41,27 @@ def create_connection(self) -> FakeConnection:
4441
return self.connection
4542

4643

47-
def test_pcsc_backend_wraps_reader_and_reads_profile_uid() -> None:
48-
"""PC/SC backend reads a profile through the wrapped reader."""
44+
def test_pcsc_backend_reads_tag_info_uid() -> None:
45+
"""PC/SC backend reads tag identity through the wrapped reader."""
4946
reader = FakeReader()
5047
backend = PcscBackend(reader=reader)
5148

52-
profile = backend.read_profile()
49+
tag = backend.read_tag_info()
5350

5451
assert backend.reader_name == "Fake PCSC Reader"
55-
assert profile.tag.uid == "04112233445566"
56-
assert profile.tag.features == ["pcsc"]
52+
assert tag.uid == "04112233445566"
53+
assert tag.features == ["pcsc"]
5754
assert reader.connection.commands == [[0xFF, 0xCA, 0x00, 0x00, 0x00]]
5855

5956

57+
def test_pcsc_backend_rejects_full_profile_reads() -> None:
58+
"""PC/SC backend does not fabricate full profile data from UID-only reads."""
59+
backend = PcscBackend(reader=FakeReader())
60+
61+
with pytest.raises(PcscBackend.UnsupportedProfileReadError):
62+
backend.read_profile()
63+
64+
6065
def test_pcsc_backend_sends_command_apdu() -> None:
6166
"""PC/SC backend accepts CommandAPDU objects."""
6267
reader = FakeReader()

0 commit comments

Comments
 (0)