Skip to content

Commit

Permalink
fix: Handle empty lists in TAXII status responses
Browse files Browse the repository at this point in the history
These elements of the response are optional, so we should accept
situations when they aren't provided at all. This change simply checks
if the iterable `successes`, `pendings` and `failures` are truthy prior
to verifying that their lengths match the associated `*_count`
attribute. As such, we now accept status responses which return empty
lists for these elements as well as responses which omit them entirely.

Change-Id: I0ff802b9722c536144403a33e399c73fd29bdc61
  • Loading branch information
maybe-sybr committed Aug 27, 2020
1 parent 355b9a3 commit 0bdf84e
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
6 changes: 3 additions & 3 deletions taxii2client/v20/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,19 +172,19 @@ def _validate_status(self):
msg = "No 'pending_count' in Status for request '{}'"
raise ValidationError(msg.format(self.url))

if len(self.successes) != self.success_count:
if self.successes and len(self.successes) != self.success_count:
msg = "Found successes={}, but success_count={} in status '{}'"
raise ValidationError(msg.format(self.successes,
self.success_count,
self.id))

if len(self.pendings) != self.pending_count:
if self.pendings and len(self.pendings) != self.pending_count:
msg = "Found pendings={}, but pending_count={} in status '{}'"
raise ValidationError(msg.format(self.pendings,
self.pending_count,
self.id))

if len(self.failures) != self.failure_count:
if self.failures and len(self.failures) != self.failure_count:
msg = "Found failures={}, but failure_count={} in status '{}'"
raise ValidationError(msg.format(self.failures,
self.failure_count,
Expand Down
6 changes: 3 additions & 3 deletions taxii2client/v21/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,19 +135,19 @@ def _validate_status(self):
msg = "No 'pending_count' in Status for request '{}'"
raise ValidationError(msg.format(self.url))

if len(self.successes) != self.success_count:
if self.successes and len(self.successes) != self.success_count:
msg = "Found successes={}, but success_count={} in status '{}'"
raise ValidationError(msg.format(self.successes,
self.success_count,
self.id))

if len(self.pendings) != self.pending_count:
if self.pendings and len(self.pendings) != self.pending_count:
msg = "Found pendings={}, but pending_count={} in status '{}'"
raise ValidationError(msg.format(self.pendings,
self.pending_count,
self.id))

if len(self.failures) != self.failure_count:
if self.failures and len(self.failures) != self.failure_count:
msg = "Found failures={}, but failure_count={} in status '{}'"
raise ValidationError(msg.format(self.failures,
self.failure_count,
Expand Down

0 comments on commit 0bdf84e

Please sign in to comment.