예제 #1
0
def test_yaml_paser():
    t = threatmodel.ThreatModel()
    t.threat_library = threatmodel.ThreatLibrary()
    p = parser.YamlFileParser(t)

    yaml_string = """
        key1:
            key11:
                x-threatspec: "@threat A string threat"
            key12:
                x-threatspec:
                    - "@threat Array threat 1"
                    - "@threat Array threat 2"
        key2:
            key21:
                key211:
                    "x-threatspec":
                        "@threat Extended threat 1":
                            description: Extended description 1
                            impact: high
    """

    data = yaml.load(yaml_string, Loader=yaml.SafeLoader)
    p.parse_data(data, {}, "path/to/file")

    assert len(t.threat_library.threats) == 4

    assert "#a_string_threat" in t.threat_library.threats
    assert t.threat_library.threats[
        "#a_string_threat"].name == "A string threat"

    assert "#extended_threat_1" in t.threat_library.threats
    assert t.threat_library.threats["#extended_threat_1"].custom[
        "impact"] == "high"
예제 #2
0
def test_strip():
    t = threatmodel.ThreatModel()
    t.threat_library = threatmodel.ThreatLibrary()
    p = parser.CommentParser(t)

    assert p.strip("* test ") == "test"
    assert p.strip(" * test ") == "test"
    assert p.strip("    * test ") == "test"
    assert p.strip("test  ") == "test"
    assert p.strip("  test") == "test"
    assert p.strip("  * test\n    attr: 42  ") == "test\n    attr: 42"
예제 #3
0
    def __init__(self):
        self.threat_library = threatmodel.ThreatLibrary()
        self.control_library = threatmodel.ControlLibrary()
        self.component_library = threatmodel.ComponentLibrary()

        self.threatmodel = threatmodel.ThreatModel()
        self.threatmodel.threat_library = self.threat_library
        self.threatmodel.control_library = self.control_library
        self.threatmodel.component_library = self.component_library

        self.threatmodel.run_id = uuid.uuid4().hex
        logger.debug("Setting run id to {}".format(self.threatmodel.run_id))

        self.config = config.Config()
        self.parser = None
        self.reporter = None

        self.loaded_source_paths = {}
        self.loaded_library_paths = {}
예제 #4
0
def test_threatmodel_library_parse_name_threat():
    t = threatmodel.ThreatLibrary()

    assert t.parse_name("A Threat") == ("A Threat", "#a_threat")