Skip to content

Commit

Permalink
makify now ensures correct ordering of all fields
Browse files Browse the repository at this point in the history
  • Loading branch information
SmithSamuelM committed Mar 18, 2024
1 parent 8521368 commit a20d33d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
12 changes: 9 additions & 3 deletions src/keri/core/serdering.py
Original file line number Diff line number Diff line change
Expand Up @@ -780,9 +780,15 @@ def makify(self, sad, *, version=None,
value = copy.copy(value) # copy iterable defaults
sad[label] = value

# Need to insert required fields in proper place because passed in sad
# may have missing require fields that appear before provided ones so
# can't simply append
sadold = sad
sad = {}
for label in oalls: # make sure all fields are in correct order
if label in sadold:
sad[label] = sadold[label]

for label in sadold: # copy extras if any
if label not in sad:
sad[label] = sadold[label]

if 't' in sad: # when packet type field then force ilk
sad['t'] = ilk # assign ilk
Expand Down
9 changes: 3 additions & 6 deletions tests/core/test_serdering.py
Original file line number Diff line number Diff line change
Expand Up @@ -606,13 +606,10 @@ def test_serder():
sad = serder.sad
sad["ri"] = ""

with pytest.raises(kering.SerializeError):
serder = Serder(makify=True, sad=sad) # make using sad

serder = Serder(makify=True, sad=sad) # make using sad fixes order

# extra field with strict
sad = serder.sad
assert 'ri' not in sad
sad["x"] = ""

with pytest.raises(kering.SerializeError):
Expand Down Expand Up @@ -659,8 +656,7 @@ def test_serder():
# out of order with extra
sad = serder.sad
sad["ri"] = ""
with pytest.raises(kering.SerializeError):
serder = Serder(makify=True, sad=sad) # make using sad
serder = Serder(makify=True, sad=sad) # makify fixes order with extra

# ToDo: create malicious raw values to test verify more thoroughly
# ToDo: create bad sad values to test makify more thoroughly
Expand Down Expand Up @@ -1313,6 +1309,7 @@ def test_serderkeri_dip():
assert serder.verify()

raw = serder.raw
sad = serder.sad
said = serder.said
size = serder.size
ilk = serder.ilk
Expand Down

0 comments on commit a20d33d

Please sign in to comment.