From bd21de4a5875ce15c193ee5d6bbd6b3bc92dd743 Mon Sep 17 00:00:00 2001 From: maybe-sybr <58414429+maybe-sybr@users.noreply.github.com> Date: Wed, 15 Jul 2020 11:42:24 +1000 Subject: [PATCH] fix: Handle empty lists in TAXII status responses These elements of the response are optional, so we should handle situations when they aren't provided at all. Change-Id: I0ff802b9722c536144403a33e399c73fd29bdc61 --- taxii2client/v21/__init__.py | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/taxii2client/v21/__init__.py b/taxii2client/v21/__init__.py index b95c1dd..a283bf5 100644 --- a/taxii2client/v21/__init__.py +++ b/taxii2client/v21/__init__.py @@ -99,9 +99,9 @@ def _populate_fields(self, id=None, status=None, total_count=None, self.success_count = success_count # required self.failure_count = failure_count # required self.pending_count = pending_count # required - self.successes = successes or [] # optional - self.failures = failures or [] # optional - self.pendings = pendings or [] # optional + self.successes = successes or None # optional + self.failures = failures or None # optional + self.pendings = pendings or None # optional # Anything not captured by the optional arguments is treated as custom self._custom_properties = kwargs @@ -135,19 +135,28 @@ 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 is not None 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 is not None 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 is not None and + len(self.failures) != self.failure_count + ): msg = "Found failures={}, but failure_count={} in status '{}'" raise ValidationError(msg.format(self.failures, self.failure_count,