Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parsing StatusMessage XML with StatusMessage gives a different result to the original #230

Closed
danielsamuels opened this issue Oct 17, 2018 · 2 comments

Comments

@danielsamuels
Copy link
Contributor

If you provide a list of acceptable destinations in the status detail of a StatusMessage object, then transform the StatusMessage to XML and re-parse it, the value of status.status_detail will be structured differently in the parsed object.

Here's a very straight-forward reproduction case:

import libtaxii.messages_11 as tm11
from libtaxii.constants import *

status_message = tm11.StatusMessage(
    message_id=tm11.generate_message_id(),
    in_response_to='0',
    status_type=ST_DESTINATION_COLLECTION_ERROR,
    status_detail={
        SD_ACCEPTABLE_DESTINATION: [
            'foo',
            'bar',
            'baz',
        ]
    }
)

print status_message.status_detail
# {'ACCEPTABLE_DESTINATION': ['foo', 'bar', 'baz']}

xml = status_message.to_xml()
"""
<taxii_11:Status_Message xmlns:taxii="http://taxii.mitre.org/messages/taxii_xml_binding-1" xmlns:taxii_11="http://taxii.mitre.org/messages/taxii_xml_binding-1.1" xmlns:tdq="http://taxii.mitre.org/query/taxii_default_query-1" message_id="4183586003553703942" in_response_to="0" status_type="DESTINATION_COLLECTION_ERROR">
    <taxii_11:Status_Detail>
        <taxii_11:Detail name="ACCEPTABLE_DESTINATION">foo</taxii_11:Detail>
        <taxii_11:Detail name="ACCEPTABLE_DESTINATION">bar</taxii_11:Detail>
        <taxii_11:Detail name="ACCEPTABLE_DESTINATION">baz</taxii_11:Detail>
    </taxii_11:Status_Detail>
</taxii_11:Status_Message>
"""

print tm11.StatusMessage.from_xml(xml).status_detail
# {'ACCEPTABLE_DESTINATION': [['foo', 'bar'], 'baz']}

If you specify only two destinations then the output is as expected:

{'ACCEPTABLE_DESTINATION': ['foo', 'bar']}

However, as you add more and more destinations they become nested deeper and deeper:

{'ACCEPTABLE_DESTINATION': [[[[['foo', 'bar'], 'baz'], 'x'], 'y'], 'z']}

The XML appears to be well-formed, so I imagine there's an issue in the .from_xml() method.

danielsamuels added a commit to danielsamuels/libtaxii that referenced this issue Oct 17, 2018
@danielsamuels
Copy link
Contributor Author

@gtback I've opened PR #231 to fix this issue as well as add a test for the bug. Would you be able to take a look please?

@emmanvg emmanvg added this to the libtaxii 1.1.112 milestone Nov 26, 2018
@emmanvg
Copy link
Contributor

emmanvg commented Nov 26, 2018

@danielsamuels sorry for getting back to you so late. I will take a look at this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants