|
1 | 1 | """Tests for NTAG profile change planning.""" |
2 | 2 |
|
3 | 3 | from schnee.adapters.ntag.profile.models import ( |
| 4 | + AccessProfile, |
4 | 5 | LockProfile, |
5 | 6 | NdefProfile, |
6 | 7 | NdefRecord, |
7 | 8 | SdmProfile, |
| 9 | + SecurityProfile, |
| 10 | + TagInfo, |
8 | 11 | TagProfile, |
9 | 12 | ) |
10 | 13 | 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: |
100 | 103 | assert plan.operations[0].type == "writeNdef" |
101 | 104 | assert plan.operations[0].requires_authentication is True |
102 | 105 | 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