fix: CAP compatibility test review fixes (v3.6.49)

Review of v3.6.48 found six issues; the two that matter in use:

- ramProbeParse('') errored, so the basic 'is this CAP compatible with
  this card at all?' run (no overrides) was refused by an alert.  An empty
  list is valid now: the test runs with the CAP's own versions.
- ramCompatVerdict said 'Import list rejected' for every failure.  It now
  distinguishes: a request error (no steps), a failed format probe (the
  card not answering), an INSTALL [for load] refusal, and only then the
  import list - each with its own headline.

Plus:
- the result line shows the applied probe (ramCompatProbeNote: 'probe:
  7 imports -> 0.0 · +1 appended', unmatched AIDs included);
- #ram-compat-block validates 1..240 like the install's block size;
- the server reports probe_unmatched (override AIDs matching no entry,
  previously silent when another override matched) and logs them;
- tests: the endpoint's probe-400 path (a mini CAP + a dummy scc),
  _cap_import_aids, the verdict cases and the probe note.

sw cache simple-v322; tests: 540 Python / 687 Node.
This commit is contained in:
2026-09-30 08:13:12 +03:00
parent 0dc79a3ba4
commit 80c26f14f2
7 changed files with 170 additions and 25 deletions
+6 -2
View File
@@ -9,8 +9,8 @@ import zipfile
from pysim_simple_server import capmem
from pysim_simple_server.server import (
_ber_len, _cap_apdu_sequence, _cap_compat_blocks, _cap_import_end,
_cap_info_body, _cap_parse, _probe_import_versions)
_ber_len, _cap_apdu_sequence, _cap_compat_blocks, _cap_import_aids,
_cap_import_end, _cap_info_body, _cap_parse, _probe_import_versions)
# ─── synthetic CAP builder ───────────────────────────────────────────────
@@ -272,6 +272,10 @@ class ImportProbeTests(unittest.TestCase):
self.assertEqual(data[3 + 3 * 2:3 + 3 * 2 + 2], import_size.to_bytes(2, 'big'))
self.assertTrue(self._walk_ok(patched))
def test_cap_import_aids(self):
self.assertEqual(_cap_import_aids(self._load_file()),
[JAVACARD_FRAMEWORK.hex().upper(), self.OTHER_AID.hex().upper()])
def test_probe_rejects_bad_additions(self):
load = self._load_file()
with self.assertRaises(ValueError):
+31
View File
@@ -157,6 +157,28 @@ class CardFreeGetTests(unittest.TestCase):
self.assertNotIn(path, _CARD_FREE_GET)
def _mini_cap_hex():
"""A minimal parseable CAP archive (Header + Applet + one Import)."""
import io as _io
import struct as _struct
import zipfile as _zipfile
def comp(tag, payload):
return bytes([tag]) + _struct.pack('>H', len(payload)) + payload
aid = bytes.fromhex('0102030405')
header = comp(0x01, _struct.pack('>I', 0xDECAFFED) + bytes([1, 2, 0, 1, 2]) +
bytes([len(aid)]) + aid)
applet = comp(0x03, bytes([1, len(aid)]) + aid + b'\x00\x01')
imports = comp(0x04, bytes([1]) + bytes([0, 1, 7]) + bytes.fromhex('A0000000620101'))
buf = _io.BytesIO()
with _zipfile.ZipFile(buf, 'w') as z:
z.writestr('Header.cap', header)
z.writestr('Applet.cap', applet)
z.writestr('Import.cap', imports)
return buf.getvalue().hex().upper()
class CapCompatHttpTests(unittest.TestCase):
"""POST /api/cap-compat exists (the CAP compatibility test, v3.6.48)."""
@@ -190,6 +212,15 @@ class CapCompatHttpTests(unittest.TestCase):
self.assertEqual(status, 503, resp)
self.assertIn('error', resp)
def test_cap_compat_rejects_a_bad_probe(self):
# a parseable CAP + a bad override -> 400 from the probe validation,
# before any card I/O (a dummy scc object is enough)
self.server.scc = object()
status, resp = self._post('/api/cap-compat',
{'cap_hex': _mini_cap_hex(), 'probe_imports': {'all': 'x'}})
self.assertEqual(status, 400, resp)
self.assertIn('import probe', resp['error'])
if __name__ == '__main__':
unittest.main()