v3.22.0 (review fixes): the quota zero, the suite repair paths, the docs
Second review round on the unpushed v3.20.0-v3.22.0 batch: - install parameters: a zero memory quota (nv_quota: 0 - the vendor reference form's C7 02 0000 C8 02 0000) is composed instead of being dropped as "unset" (only None/blank leaves the TLV out); a truncated EF length in stk_params is refused instead of read as an empty EF. - test suites: a suite whose member script is gone is repairable - the update endpoint accepts pruning a dangling reference (a removal of a live script stays refused; the PWA's row Delete prunes it), and reconcile_scripts_to_suites() lists an orphan even when its suite_id write is refused by the validator, so a stored script that no longer validates stays visible in the editor and fails at run start with the message instead of disappearing. - engine/PWA: the proactive action refuses a check.data (its result data is the drained-command list - the check was silently ignored); the vestigial _testScriptDraft is gone; berLenStr emits the 2/3-byte BER long form (a >255-byte C9 composes correctly). - docs: api.md (the stop cleanup answers ok, never an automatic cancel; the server persists the counters - the PWA does not write them back; the suite bundle import always merges the scripts; the quota-0 note) and test-scripts.md (the event action covers all modelled events; the direct-create path needs a suite_id; the format history); help EN/RU counter wording. - tests: the zero quota / truncated EF, the prune path, the invalid-script listing, the proactive data-check refusal, berLenStr and the >255-byte C9. Tests: 839 frontend + 804 Python; sw cache simple-v403.
This commit is contained in:
@@ -1330,6 +1330,36 @@ class TestScriptStoreHttpTests(unittest.TestCase):
|
||||
self.assertEqual(status, 400, resp)
|
||||
self.assertIn('member set changes through the script endpoints', resp['error'])
|
||||
|
||||
def test_suite_update_prunes_a_dangling_reference(self):
|
||||
# The store keeps a suite whose script is gone (servable by design);
|
||||
# pruning the member entry is the one member-set change the update
|
||||
# endpoint accepts - no script endpoint can reach it any more.
|
||||
suite = self._suite(name='stale')
|
||||
self.suites.update(suite['id'], {'scripts': [
|
||||
{'script_id': 'f' * 32, 'role': 'member', 'on_fail': 'stop'}]})
|
||||
# the full list (with the dangling id) is still refused...
|
||||
status, resp = self._post('/api/test/suites/update', {
|
||||
'id': suite['id'], 'suite': {'name': 'renamed', 'scripts': [
|
||||
{'script_id': 'f' * 32, 'role': 'member', 'on_fail': 'stop'}]}})
|
||||
self.assertEqual(status, 400, resp)
|
||||
self.assertIn('unknown test script', resp['error'])
|
||||
# ...but the prune is accepted, and the suite is editable again
|
||||
status, resp = self._post('/api/test/suites/update', {
|
||||
'id': suite['id'], 'suite': {'scripts': []}})
|
||||
self.assertEqual(status, 200, resp)
|
||||
self.assertEqual(resp['suite']['scripts'], [])
|
||||
status, resp = self._post('/api/test/suites/update', {
|
||||
'id': suite['id'], 'suite': {'name': 'renamed'}})
|
||||
self.assertEqual(status, 200, resp)
|
||||
self.assertEqual(resp['suite']['name'], 'renamed')
|
||||
# removing a script that still exists stays the script endpoint's job
|
||||
status, resp = self._post('/api/test/scripts', self._script(suite_id=suite['id']))
|
||||
self.assertEqual(status, 200, resp)
|
||||
status, resp = self._post('/api/test/suites/update', {
|
||||
'id': suite['id'], 'suite': {'scripts': []}})
|
||||
self.assertEqual(status, 400, resp)
|
||||
self.assertIn('member set changes', resp['error'])
|
||||
|
||||
def test_move_and_copy_between_suites(self):
|
||||
a = self._suite(name='a')
|
||||
b = self._suite(name='b')
|
||||
|
||||
@@ -1612,6 +1612,30 @@ class CapApduSequenceTest(unittest.TestCase):
|
||||
self.assertEqual(_compose_install_params('C900EF04C7020064', 'EA0480000000'),
|
||||
'C900EF04C7020064EA0480000000')
|
||||
|
||||
def test_install_params_zero_quota_and_truncated_ef(self):
|
||||
# `0` is a valid quota (the vendor reference form carried
|
||||
# `C7 02 0000 C8 02 0000`): only an absent/empty field is unset.
|
||||
from pysim_simple_server.server import (_compose_install_params,
|
||||
_single_ef_value)
|
||||
self.assertEqual(_compose_install_params('', '', nv_quota=0),
|
||||
'C900EF04C8020000')
|
||||
self.assertEqual(_compose_install_params('', '', volatile_quota=0,
|
||||
nv_quota=0),
|
||||
'C900EF08C7020000C8020000')
|
||||
self.assertEqual(_compose_install_params('', '', nv_quota='0'),
|
||||
'C900EF04C8020000')
|
||||
self.assertEqual(_compose_install_params('', '', nv_quota=0.0),
|
||||
'C900EF04C8020000')
|
||||
# an absent/empty field is not composed
|
||||
self.assertEqual(_compose_install_params('', '', nv_quota='',
|
||||
volatile_quota=None), 'C900')
|
||||
# a truncated EF length is malformed, not an empty EF
|
||||
for bad in ('EF', 'EF81', 'EF80', 'EF8201'):
|
||||
with self.assertRaises(ValueError, msg=bad):
|
||||
_single_ef_value(bad)
|
||||
# an empty EF (EF 00) is legal
|
||||
self.assertEqual(_single_ef_value('EF00'), '')
|
||||
|
||||
def test_install_apdu_carries_the_composed_parameters(self):
|
||||
from pysim_simple_server.server import _cap_install_apdu
|
||||
# CA-form STK + quotas: `C9 00 EF{C7,C8,CA}` - one EF (the form the
|
||||
|
||||
@@ -222,6 +222,33 @@ class MigrationTests(unittest.TestCase):
|
||||
# idempotent: nothing left to attach
|
||||
self.assertEqual(srv.migrate_scripts_to_suites(scripts, suites), 0)
|
||||
|
||||
def test_an_invalid_script_is_still_listed_by_the_reconciliation(self):
|
||||
# The script store keeps an entry that no longer validates (a
|
||||
# tightened rule must not destroy it). Its suite_id write is refused
|
||||
# by the same validator, but the member list is authoritative: the
|
||||
# script must be listed, or it would be invisible in the PWA and
|
||||
# could never be fixed in the editor.
|
||||
from pysim_simple_server import server as srv
|
||||
from pysim_simple_server import test_scripts
|
||||
with tempfile.TemporaryDirectory() as tmp:
|
||||
path = pathlib.Path(tmp) / 's.json'
|
||||
step = {'type': 'action', 'kind': 'status', 'params': {'attempts': 1}}
|
||||
scripts = test_scripts.TestScriptStore(path) # permissive
|
||||
script = scripts.add({'name': 'stale', 'steps': [step]})
|
||||
|
||||
def validator(raw):
|
||||
raise ValueError('the rule tightened')
|
||||
|
||||
strict = test_scripts.TestScriptStore(path, validator=validator)
|
||||
suites = test_suites.TestSuiteStore(pathlib.Path(tmp) / 'u.json')
|
||||
self.assertEqual(srv.reconcile_scripts_to_suites(strict, suites), 1)
|
||||
imported = suites.find_by_name('Imported scripts')
|
||||
self.assertEqual([e['script_id'] for e in imported['scripts']],
|
||||
[script['id']])
|
||||
# the suite_id write could not go through - the listing is what
|
||||
# keeps the script visible and fixable
|
||||
self.assertIsNone(strict.get(script['id'])['suite_id'])
|
||||
|
||||
def test_the_reconciliation_adopts_listed_and_missing_suite_scripts(self):
|
||||
# The general invariant repair: a script whose suite_id points at a
|
||||
# missing suite (a suites import with mode replace) joins "Imported
|
||||
|
||||
@@ -119,6 +119,17 @@ class TestValidation(unittest.TestCase):
|
||||
T.normalise_script({'steps': [{'type': 'action', 'kind': 'proactive',
|
||||
'params': bad}]}, _resolver)
|
||||
|
||||
def test_the_proactive_action_refuses_a_data_check(self):
|
||||
# The proactive result's data is the drained-command list, not a
|
||||
# single response: a `data` check would be silently ignored, so the
|
||||
# engine refuses it (assert what was drained with `require`).
|
||||
with self.assertRaises(T.ScriptError) as cm:
|
||||
T.normalise_script({'steps': [
|
||||
{'type': 'action', 'kind': 'proactive',
|
||||
'check': {'data': 'AABB'}}]}, _resolver)
|
||||
self.assertIn('check.data is not used by the proactive action',
|
||||
str(cm.exception))
|
||||
|
||||
def test_integer_fields_accept_decimals_with_leading_zeros_and_hex(self):
|
||||
script = T.normalise_script({'steps': [
|
||||
{'type': 'action', 'kind': 'status',
|
||||
|
||||
Reference in New Issue
Block a user