Repository: pydicom/pynetdicom
Pull request #373 (2019-07-13 02:40:20)

[MRG] Ignore invalid Move Destination AET
#### Tasks
 - [x] Unit tests added that reproduce issue or prove feature is working
 - [x] Fix or feature added
 - [x] Unit tests passing and coverage at 100% after adding fix/feature



Patch:
diff --git a/docs/changelog/v1.4.0.rst b/docs/changelog/v1.4.0.rst
index b3f2382da..aadc5705c 100644
--- a/docs/changelog/v1.4.0.rst
+++ b/docs/changelog/v1.4.0.rst
@@ -45,6 +45,9 @@ Enhancements
   contain no Transfer Syntax Sub-item (:issue:`361`)
 * ``ae_title`` and ``contexts`` keyword arguments added to
   ``AE.start_server()``
+* Invalid (0000,1030) *Move Originator Application Entity Title* values
+  received in C-STORE service requests are now logged and ignored rather than
+  raising an exception and aborting the association.
 
 
 Changes
diff --git a/pynetdicom/dimse_primitives.py b/pynetdicom/dimse_primitives.py
index dae8e2dea..6d96b4edc 100644
--- a/pynetdicom/dimse_primitives.py
+++ b/pynetdicom/dimse_primitives.py
@@ -356,15 +356,23 @@ class C_STORE(DIMSEPrimitive):
         ----------
         value : str or bytes
             The Move Originator AE Title as a string or bytes object. Cannot be
-            an empty string and will be truncated to 16 characters long
+            an empty string and will be truncated to 16 characters long.
+            Invalid values will be ignored.
         """
         if isinstance(value, str):
             value = codecs.encode(value, 'ascii')
 
         if value:
-            self._move_originator_application_entity_title = (
-                validate_ae_title(value)
-            )
+            try:
+                self._move_originator_application_entity_title = (
+                    validate_ae_title(value)
+                )
+            except ValueError as exc:
+                LOGGER.error(
+                    "C-STORE request primitive contains an invalid "
+                    "'Move Originator AE Title'"
+                )
+                self._move_originator_application_entity_title = None
         else:
             self._move_originator_application_entity_title = None
 
@@ -1988,13 +1996,13 @@ class N_CREATE(DIMSEPrimitive):
     +==========================================+=========+==========+
     | Message ID                               | M       | \-       |
     +------------------------------------------+---------+----------+
-    +------------------------------------------+---------+----------+
     | Message ID Being Responded To            | \-      | M        |
+    +------------------------------------------+---------+----------+
     | Affected SOP Class UID                   | M       | U(=)     |
     +------------------------------------------+---------+----------+
     | Affected SOP Instance UID                | U       | C        |
     +------------------------------------------+---------+----------+
-    | Affected SOP Instance UID                | U       | U        |
+    | Attribute List                           | U       | U        |
     +------------------------------------------+---------+----------+
     | Status                                   | \-      | M        |
     +------------------------------------------+---------+----------+


Test patch:
diff --git a/pynetdicom/tests/test_dimse_c.py b/pynetdicom/tests/test_dimse_c.py
index ab56e5908..678d7e280 100644
--- a/pynetdicom/tests/test_dimse_c.py
+++ b/pynetdicom/tests/test_dimse_c.py
@@ -93,6 +93,14 @@ class TestPrimitive_C_STORE(object):
         assert primitive.MoveOriginatorApplicationEntityTitle == b'UNITTEST_SCP    '
         primitive.MoveOriginatorApplicationEntityTitle = b'UNITTEST_SCP'
         assert primitive.MoveOriginatorApplicationEntityTitle == b'UNITTEST_SCP    '
+        primitive.MoveOriginatorApplicationEntityTitle = ''
+        assert primitive.MoveOriginatorApplicationEntityTitle is None
+        primitive.MoveOriginatorApplicationEntityTitle = b''
+        assert primitive.MoveOriginatorApplicationEntityTitle is None
+        primitive.MoveOriginatorApplicationEntityTitle = '         '
+        assert primitive.MoveOriginatorApplicationEntityTitle is None
+        primitive.MoveOriginatorApplicationEntityTitle = b'         '
+        assert primitive.MoveOriginatorApplicationEntityTitle is None
 
         primitive.MoveOriginatorMessageID = 15
         assert primitive.MoveOriginatorMessageID == 15
@@ -209,9 +217,8 @@ class TestPrimitive_C_STORE(object):
         primitive.MoveOriginatorApplicationEntityTitle = ''
         assert primitive.MoveOriginatorApplicationEntityTitle is None
 
-
-        with pytest.raises(ValueError):
-            primitive.MoveOriginatorApplicationEntityTitle = '    '
+        #with pytest.raises(ValueError):
+        #    primitive.MoveOriginatorApplicationEntityTitle = '    '
 
         # MoveOriginatorMessageID
         with pytest.raises(TypeError):