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():
|
2018-07-05 21:23:25 +02:00
|
|
|
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"
|
|
|
|
}"""
|
|
|
|
|
|
|
|
|
2017-02-24 20:07:54 +01:00
|
|
|
def test_kill_chain_example():
|
2018-07-05 21:23:25 +02:00
|
|
|
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
|
|
|
|
|
|
|
|
|
2017-05-16 18:27:30 +02:00
|
|
|
def test_kill_chain_required_properties():
|
2017-02-24 19:51:21 +01:00
|
|
|
|
2017-05-19 19:51:59 +02:00
|
|
|
with pytest.raises(stix2.exceptions.MissingPropertiesError) as excinfo:
|
2018-07-05 21:23:25 +02:00
|
|
|
stix2.v20.KillChainPhase()
|
2017-02-24 19:51:21 +01:00
|
|
|
|
2018-07-05 21:23:25 +02:00
|
|
|
assert excinfo.value.cls == stix2.v20.KillChainPhase
|
2017-05-16 18:27:30 +02:00
|
|
|
assert excinfo.value.properties == ["kill_chain_name", "phase_name"]
|
2017-02-24 19:51:21 +01:00
|
|
|
|
|
|
|
|
2017-05-16 18:27:30 +02:00
|
|
|
def test_kill_chain_required_property_chain_name():
|
2017-02-24 19:51:21 +01:00
|
|
|
|
2017-05-19 19:51:59 +02:00
|
|
|
with pytest.raises(stix2.exceptions.MissingPropertiesError) as excinfo:
|
2018-07-05 21:23:25 +02:00
|
|
|
stix2.v20.KillChainPhase(phase_name="weaponization")
|
2017-02-24 19:51:21 +01:00
|
|
|
|
2018-07-05 21:23:25 +02:00
|
|
|
assert excinfo.value.cls == stix2.v20.KillChainPhase
|
2017-05-16 18:27:30 +02:00
|
|
|
assert excinfo.value.properties == ["kill_chain_name"]
|
2017-02-24 19:51:21 +01:00
|
|
|
|
|
|
|
|
2017-05-16 18:27:30 +02:00
|
|
|
def test_kill_chain_required_property_phase_name():
|
2017-02-24 19:51:21 +01:00
|
|
|
|
2017-05-19 19:51:59 +02:00
|
|
|
with pytest.raises(stix2.exceptions.MissingPropertiesError) as excinfo:
|
2018-07-05 21:23:25 +02:00
|
|
|
stix2.v20.KillChainPhase(kill_chain_name="lockheed-martin-cyber-kill-chain")
|
2017-02-24 19:51:21 +01:00
|
|
|
|
2018-07-05 21:23:25 +02:00
|
|
|
assert excinfo.value.cls == stix2.v20.KillChainPhase
|
2017-05-16 18:27:30 +02:00
|
|
|
assert excinfo.value.properties == ["phase_name"]
|