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

Skip unallowed common properties provided by ObjectFactory #606

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

SYNchroACK
Copy link

@SYNchroACK SYNchroACK commented Oct 13, 2024

Problem: the existing ObjectFactory when initialized with the default values like created_by_ref, does not handle properly the creation of SCOs, which does not have these default properties (created, created_by_ref, external_references) accordingly to the standard.

image

Test snippet.py:

from stix2.environment import ObjectFactory
from stix2.v21 import DomainName, Identity, Malware

identity = Identity(name="Test", description="Test")

factory = ObjectFactory(created_by_ref=identity.id)

malware = factory.create(Malware, name="dridex", is_family=True)
domain = factory.create(DomainName, value="test.com")

print("Malware: ", malware.name)
print("Domain: ", domain.value)

Without the changes proposed in this pull request:

$ python snippet.py 
Traceback (most recent call last):
  File "/openstix-python/src/stix2/snippet.py", line 9, in <module>
    domain = factory.create(DomainName, value="test.com")
  File "/openstix-python/src/stix2/stix2/environment.py", line 104, in create
    return cls(**properties)
  File "/openstix-python/src/stix2/stix2/v21/base.py", line 15, in __init__
    super(_Observable, self).__init__(**kwargs)
  File "/openstix-python/src/stix2/stix2/base.py", line 381, in __init__
    super(_Observable, self).__init__(**kwargs)
  File "/openstix-python/src/stix2/stix2/base.py", line 157, in __init__
    raise ExtraPropertiesError(cls, custom_kwargs)
stix2.exceptions.ExtraPropertiesError: Unexpected properties for DomainName: (created_by_ref).

With the changes proposed in this pull request:

$ python snippet.py 
Malware:  dridex
Domain:  test.com

@SYNchroACK SYNchroACK changed the title Multiple small/relevant issues Skip unallowed common properties provided by ObjectFactory Oct 15, 2024
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

Successfully merging this pull request may close these issues.

1 participant