Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions stix2/test/v21/test_properties.py
Original file line number Diff line number Diff line change
Expand Up @@ -491,6 +491,7 @@ def test_extension_property_valid():
{
'windows-pebinary-ext': {
'pe_type': 'exe',
'machine_hex': '014c',
},
}, False,
)
Expand All @@ -504,6 +505,7 @@ def test_extension_property_valid():
{
'windows-pebinary-ext': {
'pe_type': 'exe',
'machine_hex': '014c',
},
}, True,
)
Expand Down Expand Up @@ -549,6 +551,7 @@ def test_extension_property_invalid3():
{
'windows-pebinary-ext': {
'pe_type': 'exe',
'machine_hex': '014c',
'abc': 123,
},
},
Expand All @@ -559,6 +562,7 @@ def test_extension_property_invalid3():
{
'windows-pebinary-ext': {
'pe_type': 'exe',
'machine_hex': '014c',
'abc': 123,
},
}, True,
Expand All @@ -576,6 +580,31 @@ def test_extension_at_least_one_property_constraint():
stix2.v21.TCPExt()


@pytest.mark.parametrize(
"extra_properties", [
{},
{"x_custom": "value"},
],
)
def test_windows_pe_binary_ext_requires_another_defined_property(extra_properties):
with pytest.raises(AtLeastOnePropertyError) as excinfo:
stix2.v21.WindowsPEBinaryExt(
pe_type="exe", allow_custom=True, **extra_properties
)

assert excinfo.value.cls == stix2.v21.WindowsPEBinaryExt


def test_file_rejects_windows_pe_binary_ext_with_only_pe_type():
with pytest.raises(stix2.exceptions.InvalidValueError) as excinfo:
stix2.v21.File(
name="example.exe",
extensions={"windows-pebinary-ext": {"pe_type": "exe"}},
)

assert isinstance(excinfo.value.__cause__, AtLeastOnePropertyError)


def test_marking_property_error():
mark_prop = MarkingProperty()

Expand Down
4 changes: 4 additions & 0 deletions stix2/v21/observables.py
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,10 @@ class WindowsPEBinaryExt(_Extension):
('sections', ListProperty(EmbeddedObjectProperty(type=WindowsPESection))),
])

def _check_object_constraints(self):
super(WindowsPEBinaryExt, self)._check_object_constraints()
self._check_at_least_one_property(self._properties.keys() - {'pe_type'})


class File(_Observable):
"""For more detailed information on this object's properties, see
Expand Down