Skip to content

Commit 8459c32

Browse files
committed
✅ Cover remaining profile planning branches
1 parent 8693ccc commit 8459c32

1 file changed

Lines changed: 51 additions & 0 deletions

File tree

tests/schnee/adapters/ntag/profile/test_planning.py

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
"""Tests for NTAG profile change planning."""
22

33
from schnee.adapters.ntag.profile.models import (
4+
AccessProfile,
45
LockProfile,
56
NdefProfile,
67
NdefRecord,
78
SdmProfile,
9+
SecurityProfile,
10+
TagInfo,
811
TagProfile,
912
)
1013
from schnee.adapters.ntag.profile.planning import plan_profile_changes
@@ -100,3 +103,51 @@ def test_plan_profile_changes_marks_ndef_write_auth_requirement() -> None:
100103
assert plan.operations[0].type == "writeNdef"
101104
assert plan.operations[0].requires_authentication is True
102105
assert plan.requires_authentication is True
106+
107+
108+
def test_plan_profile_changes_detects_access_updates() -> None:
109+
"""Access updates are dangerous authenticated operations."""
110+
current = TagProfile()
111+
requested = current.patch(
112+
access=AccessProfile(ndef_write="free"),
113+
)
114+
115+
plan = plan_profile_changes(current, requested)
116+
117+
assert plan.valid is True
118+
assert [operation.type for operation in plan.operations] == ["updateAccess"]
119+
assert plan.operations[0].risk == "dangerous"
120+
assert plan.operations[0].requires_authentication is True
121+
assert plan.has_dangerous_operations is True
122+
123+
124+
def test_plan_profile_changes_detects_key_rotation() -> None:
125+
"""Key rotation is planned as dangerous and warns callers."""
126+
current = TagProfile()
127+
requested = current.patch(
128+
security=SecurityProfile(default_keys=False),
129+
)
130+
131+
plan = plan_profile_changes(current, requested)
132+
133+
assert plan.valid is True
134+
assert [operation.type for operation in plan.operations] == ["rotateKey"]
135+
assert plan.operations[0].risk == "dangerous"
136+
assert plan.operations[0].requires_authentication is True
137+
assert plan.has_dangerous_operations is True
138+
assert plan.warnings == [
139+
"Key rotation can make the tag inaccessible if keys are lost.",
140+
]
141+
142+
143+
def test_plan_profile_changes_rejects_tag_type_changes() -> None:
144+
"""Tag type changes are rejected."""
145+
current = TagProfile()
146+
requested = current.patch(
147+
tag=TagInfo.model_construct(type="MIFARE"),
148+
)
149+
150+
plan = plan_profile_changes(current, requested)
151+
152+
assert plan.valid is False
153+
assert plan.errors == ["tag type cannot be changed"]

0 commit comments

Comments
 (0)