Skip to content

Commit

Permalink
fix(verifier): do not access out-of-bounds index of calls list (#45)
Browse files Browse the repository at this point in the history
  • Loading branch information
mcous authored Jul 21, 2021
1 parent b57b111 commit 15389ad
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
3 changes: 2 additions & 1 deletion decoy/verifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ def verify(
else:
for i, call in enumerate(calls):
calls_subset = calls[i : i + len(rehearsals)]
if all(r == calls_subset[j] for j, r in enumerate(rehearsals)):

if calls_subset == rehearsals:
return None

raise VerifyError(
Expand Down
24 changes: 24 additions & 0 deletions tests/test_verifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,17 @@ class VerifySpec(NamedTuple):
SpyCall(spy_id=202, spy_name="spy_202", args=("oh no",), kwargs={}),
],
),
VerifySpec(
rehearsals=[
VerifyRehearsal(spy_id=101, spy_name="spy_101", args=(1, 2, 3), kwargs={}),
VerifyRehearsal(spy_id=101, spy_name="spy_101", args=(4, 5, 6), kwargs={}),
VerifyRehearsal(spy_id=202, spy_name="spy_202", args=(7, 8, 9), kwargs={}),
],
calls=[
SpyCall(spy_id=101, spy_name="spy_101", args=(1, 2, 3), kwargs={}),
SpyCall(spy_id=101, spy_name="spy_101", args=(4, 5, 6), kwargs={}),
],
),
VerifySpec(
rehearsals=[
VerifyRehearsal(spy_id=101, spy_name="spy_101", args=(1, 2, 3), kwargs={}),
Expand Down Expand Up @@ -76,6 +87,19 @@ class VerifySpec(NamedTuple):
SpyCall(spy_id=202, spy_name="spy_202", args=(7, 8, 9), kwargs={}),
],
),
VerifySpec(
rehearsals=[
VerifyRehearsal(spy_id=101, spy_name="spy_101", args=(1, 2, 3), kwargs={}),
VerifyRehearsal(spy_id=101, spy_name="spy_101", args=(4, 5, 6), kwargs={}),
VerifyRehearsal(spy_id=202, spy_name="spy_202", args=(7, 8, 9), kwargs={}),
],
calls=[
SpyCall(spy_id=101, spy_name="spy_101", args=(0, 0, 0), kwargs={}),
SpyCall(spy_id=101, spy_name="spy_101", args=(1, 2, 3), kwargs={}),
SpyCall(spy_id=101, spy_name="spy_101", args=(4, 5, 6), kwargs={}),
SpyCall(spy_id=202, spy_name="spy_202", args=(7, 8, 9), kwargs={}),
],
),
VerifySpec(
rehearsals=[
VerifyRehearsal(spy_id=101, spy_name="spy_101", args=(1, 2, 3), kwargs={}),
Expand Down

0 comments on commit 15389ad

Please sign in to comment.