cti-python-stix2/stix2/test/v20/test_kill_chain_phases.py

62 lines
1.6 KiB
Python
Raw Permalink Normal View History

2017-02-24 19:51:21 +01:00
"""Tests for stix.ExternalReference"""
import pytest
import stix2
LMCO_RECON = """{
"kill_chain_name": "lockheed-martin-cyber-kill-chain",
"phase_name": "reconnaissance"
}"""
def test_lockheed_martin_cyber_kill_chain():
recon = stix2.v20.KillChainPhase(
2017-02-24 19:51:21 +01:00
kill_chain_name="lockheed-martin-cyber-kill-chain",
phase_name="reconnaissance",
)
assert str(recon) == LMCO_RECON
FOO_PRE_ATTACK = """{
"kill_chain_name": "foo",
"phase_name": "pre-attack"
}"""
def test_kill_chain_example():
preattack = stix2.v20.KillChainPhase(
2017-02-24 19:51:21 +01:00
kill_chain_name="foo",
phase_name="pre-attack",
)
assert str(preattack) == FOO_PRE_ATTACK
def test_kill_chain_required_properties():
2017-02-24 19:51:21 +01:00
with pytest.raises(stix2.exceptions.MissingPropertiesError) as excinfo:
stix2.v20.KillChainPhase()
2017-02-24 19:51:21 +01:00
assert excinfo.value.cls == stix2.v20.KillChainPhase
assert excinfo.value.properties == ["kill_chain_name", "phase_name"]
2017-02-24 19:51:21 +01:00
def test_kill_chain_required_property_chain_name():
2017-02-24 19:51:21 +01:00
with pytest.raises(stix2.exceptions.MissingPropertiesError) as excinfo:
stix2.v20.KillChainPhase(phase_name="weaponization")
2017-02-24 19:51:21 +01:00
assert excinfo.value.cls == stix2.v20.KillChainPhase
assert excinfo.value.properties == ["kill_chain_name"]
2017-02-24 19:51:21 +01:00
def test_kill_chain_required_property_phase_name():
2017-02-24 19:51:21 +01:00
with pytest.raises(stix2.exceptions.MissingPropertiesError) as excinfo:
stix2.v20.KillChainPhase(kill_chain_name="lockheed-martin-cyber-kill-chain")
2017-02-24 19:51:21 +01:00
assert excinfo.value.cls == stix2.v20.KillChainPhase
assert excinfo.value.properties == ["phase_name"]