Add tests for required fields.
parent
ebf6513445
commit
31cebdd34a
|
@ -43,7 +43,13 @@ class Indicator:
|
|||
|
||||
self.created = created or now
|
||||
self.modified = modified or now
|
||||
|
||||
if not labels:
|
||||
raise ValueError("Missing required field for Indicator: 'labels'.")
|
||||
self.labels = labels
|
||||
|
||||
if not pattern:
|
||||
raise ValueError("Missing required field for Indicator: 'pattern'.")
|
||||
self.pattern = pattern
|
||||
self.valid_from = valid_from or now
|
||||
|
||||
|
|
|
@ -81,3 +81,16 @@ def test_indicator_id_must_start_with_indicator():
|
|||
indicator = stix2.Indicator(id='my-prefix--')
|
||||
|
||||
assert "Indicator id values must begin with 'indicator--'." in str(excinfo)
|
||||
|
||||
|
||||
def test_indicator_required_field_labels():
|
||||
with pytest.raises(ValueError) as excinfo:
|
||||
indicator = stix2.Indicator()
|
||||
assert "Missing required field for Indicator: 'labels'." in str(excinfo)
|
||||
|
||||
|
||||
def test_indicator_required_field_pattern():
|
||||
with pytest.raises(ValueError) as excinfo:
|
||||
# Label is checked first, so make sure that is provided
|
||||
indicator = stix2.Indicator(labels=['malicious-activity'])
|
||||
assert "Missing required field for Indicator: 'pattern'." in str(excinfo)
|
||||
|
|
Loading…
Reference in New Issue