|
| 1 | +"""Unit tests for STIX-to-dataframe conversion helpers.""" |
| 2 | + |
| 3 | +import stix2 |
| 4 | + |
| 5 | +from mitreattack.attackToExcel import stixToDf |
| 6 | + |
| 7 | + |
| 8 | +def test_techniques_to_df_handles_missing_tactic_definition(monkeypatch): |
| 9 | + """TechniquesToDf should not fail when tactic shortnames are missing from x-mitre-tactic objects.""" |
| 10 | + monkeypatch.setattr(stixToDf, "relationshipsToDf", lambda src, relatedType: {}) |
| 11 | + monkeypatch.setattr(stixToDf, "_get_relationship_citations", lambda df, codex: [""] * len(df)) |
| 12 | + |
| 13 | + mem_store = stix2.MemoryStore( |
| 14 | + stix_data=[ |
| 15 | + { |
| 16 | + "type": "attack-pattern", |
| 17 | + "spec_version": "2.0", |
| 18 | + "id": "attack-pattern--11111111-1111-4111-8111-111111111111", |
| 19 | + "created": "2020-01-01T00:00:00.000Z", |
| 20 | + "modified": "2020-01-01T00:00:00.000Z", |
| 21 | + "name": "Test Technique", |
| 22 | + "description": "Test", |
| 23 | + "kill_chain_phases": [ |
| 24 | + { |
| 25 | + "kill_chain_name": "mitre-attack", |
| 26 | + "phase_name": "defense-evasion", |
| 27 | + } |
| 28 | + ], |
| 29 | + "external_references": [ |
| 30 | + { |
| 31 | + "source_name": "mitre-attack", |
| 32 | + "external_id": "T0001", |
| 33 | + "url": "https://example.com", |
| 34 | + } |
| 35 | + ], |
| 36 | + "x_mitre_domains": ["enterprise-attack"], |
| 37 | + } |
| 38 | + ] |
| 39 | + ) |
| 40 | + |
| 41 | + dataframes = stixToDf.techniquesToDf(mem_store, "enterprise-attack") |
| 42 | + techniques_df = dataframes["techniques"] |
| 43 | + |
| 44 | + assert len(techniques_df) == 1 |
| 45 | + assert techniques_df.iloc[0]["tactics"] == "Defense Evasion" |
0 commit comments