Пример #1
0
    def test_get_tech_mitigation(self):
        """
        There are some techniques that do not have mitigations.
        We will test few and if at least one of the first 5 has mitigations we're ok,
        otherwise we probably need to check if there's an error.
        """
        techs = MitreAttackTechnique.get_all(self.mitre_conn)
        assert len(techs)
        try:
            count = 0
            for tech in techs:
                id = tech.id
                assert (id)
                mitigation = tech.get_mitigations(self.mitre_conn)

                count += 1

                if len(mitigation):
                    assert MitreAttackMitigation.get_by_name(
                        self.mitre_conn, mitigation[0].name)
                    break

                if count > MAXIMUM_N_TECHNIQUES_WITHOUT_MITIGATION:
                    assert False
        except Exception as e:
            assert (False)
Пример #2
0
 def test_mitigation_get_all(self):
     data_mocker = MitreQueryMocker()
     with patch(
             "fn_mitre_integration.lib.mitre_attack.TAXIICollectionSource.query",
             data_mocker.query):
         assert len(MitreAttackMitigation.get_all(
             self.mitre_attack)) == len(
                 MitreQueryMocker.MITIGATIONS[0]) + len(
                     MitreQueryMocker.MITIGATIONS[1]) + len(
                         MitreQueryMocker.MITIGATIONS[2])
Пример #3
0
 def test_deprecated_mitigation_states_so_in_description(self):
     """
     Gets tactics with name Impact, and checks that deprecation message was added.
     Deprecation flag was added to one of the mocked mitigations.
     """
     data_mocker = MitreQueryMocker()
     with patch(
             "fn_mitre_integration.lib.mitre_attack.TAXIICollectionSource.query",
             data_mocker.query):
         mitigations = MitreAttackMitigation.get_all(self.mitre_attack)
         assert any(
             x.description.startswith("Deprecated") for x in mitigations)
Пример #4
0
 def test_mitigation_doesnt_have_mardown_links(self):
     """
     Mocked Domain Generation Algorithms on purpose has added code tags to where they could appear.
     """
     data_mocker = MitreQueryMocker()
     with patch(
             "fn_mitre_integration.lib.mitre_attack.TAXIICollectionSource.query",
             data_mocker.query):
         mitigation = MitreAttackMitigation.get_all(self.mitre_attack)
         dict_reps = [s.dict_form() for s in mitigation]
         # check for every technique's representation that all the field don't have the tag
         assert all([(re.search("\[(.*?)\]\((.*?)\)", s_repr["description"])
                      is None) for s_repr in dict_reps])
Пример #5
0
 def test_mitigation_representation_doesnt_have_unsupported_tags(self):
     """
     Mocked Domain Generation Algorithms on purpose has added code tags to where they could appear.
     """
     data_mocker = MitreQueryMocker()
     with patch(
             "fn_mitre_integration.lib.mitre_attack.TAXIICollectionSource.query",
             data_mocker.query):
         mitigations = MitreAttackMitigation.get_all(self.mitre_attack)
         dict_reps = [mitigation.dict_form() for mitigation in mitigations]
         # check for every technique's representation that all the field don't have the tag
         assert all([("<code>" not in mitigation_repr[key]
                      for key in mitigation_repr)
                     for mitigation_repr in dict_reps])