コード例 #1
0
    def test_aggregate():
        """Test aggregate layer exports (agg configurations are present in each layer)"""
        if os.path.isdir("agg_tests"):
            shutil.rmtree("agg_tests")

        os.mkdir("agg_tests")
        listing = [
            testing_data.agg_layer_1, testing_data.agg_layer_2,
            testing_data.agg_layer_3, testing_data.agg_layer_5,
            testing_data.agg_layer_6, testing_data.agg_layer_7
        ]
        for lay in listing:
            test_layer = Layer()
            test_layer.from_str(lay)

            exporter = ToExcel(domain=test_layer.layer.domain,
                               source='taxii',
                               resource=None)
            exporter.to_xlsx(
                layerInit=test_layer,
                filepath=f"agg_tests/layer-{test_layer.layer.name}.xlsx")

            exp = ToSvg(domain=test_layer.layer.domain,
                        source='taxii',
                        resource=None)
            exp.to_svg(test_layer,
                       filepath=f"agg_tests/layer-{test_layer.layer.name}.svg")

            assert os.path.isfile(
                f"agg_tests/layer-{test_layer.layer.name}.xlsx")
            assert os.path.isfile(
                f"agg_tests/layer-{test_layer.layer.name}.svg")

        shutil.rmtree("agg_tests")
コード例 #2
0
 def test_config_load():
     """Test loading a svg config"""
     lay = Layer(testing_data.example_layer_v3_all)
     exp = ToSvg(domain=lay.layer.domain)
     exp.config.load_from_file("resources/demo.json")
     exp.config.__str__()
     exp.to_svg(lay)
     os.remove('example.svg')
コード例 #3
0
    def test_colormap_export():
        """Test exporting a layer with a gradiant of scores"""
        if os.path.isfile("layer.xlsx"):
            os.remove("layer.xlsx")
        if os.path.isfile("layer.svg"):
            os.remove("layer.svg")

        lay = Layer()
        lay.from_file('resources/heatmap_example.json')
        xlsx_exporter = ToExcel(domain=lay.layer.domain)
        xlsx_exporter.to_xlsx(lay, filepath="layer.xlsx")
        svg_exporter = ToSvg(domain=lay.layer.domain)
        svg_exporter.to_svg(lay, filepath="layer.svg")
        assert os.path.isfile("layer.xlsx")
        assert os.path.isfile("layer.svg")
        os.remove('layer.xlsx')
        os.remove('layer.svg')
コード例 #4
0
    def test_depreciated_tactics_export():
        """Test exporting a layer with depreciated tactics"""
        if os.path.isfile("test.xlsx"):
            os.remove("test.xlsx")
        if os.path.isfile("test.svg"):
            os.remove("test.svg")

        lay = Layer(testing_data.example_layer_v3_longer)
        t = ToExcel(domain=lay.layer.domain)
        t2 = ToSvg(domain=lay.layer.domain)
        t.to_xlsx(lay, "test.xlsx")
        t2.to_svg(lay, "test.svg")
        assert os.path.isfile("test.xlsx")
        assert os.path.isfile("test.svg")
        os.remove("test.xlsx")
        os.remove("test.svg")
コード例 #5
0
    def test_export_svg():
        """Test SVG Export capabilities from CLI"""
        if os.path.isfile('test_export_svg.svg'):
            os.remove('test_export_svg.svg')
        if os.path.isfile('demo_file.json'):
            os.remove('demo_file.json')

        layer = Layer()
        layer.from_dict(layer_template)
        layer.to_file('demo_file.json')
        LEC_main(
            ['demo_file.json', '-m', 'svg', '--output', 'test_export_svg.svg'])
        os.remove('demo_file.json')
        assert os.path.isfile('test_export_svg.svg')
        os.remove('test_export_svg.svg')
コード例 #6
0
    def test_export_excel():
        """Test excel export capabilities from CLI"""
        if os.path.isfile('test_export_excel.xlsx'):
            os.remove('test_export_excel.xlsx')
        if os.path.isfile('demo_file.json'):
            os.remove('demo_file.json')

        layer = Layer()
        layer.from_dict(layer_template)
        layer.to_file('demo_file.json')
        LEC_main([
            'demo_file.json', '-m', 'excel', '--output',
            'test_export_excel.xlsx'
        ])
        os.remove('demo_file.json')
        assert os.path.isfile('test_export_excel.xlsx')
        os.remove('test_export_excel.xlsx')
コード例 #7
0
    def test_upgrades():
        """Test layer version auto-upgrade functionality"""
        lay = Layer()
        lay2 = Layer()
        lay3 = Layer()
        lay.from_dict(testing_data.example_layer_v3_dict)
        lay2.from_dict(testing_data.example_layer_v42_dict)
        lay3.from_dict(testing_data.example_layer_v43_dict)

        out1 = lay.to_dict()
        out2 = lay2.to_dict()
        out3 = lay3.to_dict()

        assert all([(out3[x] == out1[x], x) for x in out3 if x not in [
            'versions', 'techniques', 'metadata', 'gradient',
            'selectSubtechniquesWithParent', 'layout'
        ]])
        assert all([
            out3[x] == out2[x] for x in out3
            if x not in ['versions', 'techniques', 'metadata']
        ])
        assert all(
            ['4.3' == x['versions']['layer'] for x in [out1, out2, out3]])
コード例 #8
0
 def get_layers_by_name(test_layers):
     layers_dict['Endgame'] = Layer()
     layers_dict['Endgame'].from_str(test_layers[0])
     layers_dict['Red2'] = Layer()
     layers_dict['Red2'].from_str(test_layers[1])
     return layers_dict
コード例 #9
0
from mitreattack.navlayers import SVGConfig, ToExcel, ToSvg, Layer
from resources.testing_data import example_layer_v3_all as data_layer

import os
import shutil

source = "taxii"
resource = None

l1 = Layer()
l1.from_str(data_layer)


class TestMass:
    def test_dimensions(self):
        """Test SVG export: dimensions"""
        if os.path.isdir('mass'):
            shutil.rmtree('mass')

        index = 0
        os.mkdir('mass')
        os.mkdir('mass/output')
        for width in [8.5, 11]:
            for height in [8.5, 11]:
                for headerHeight in [1, 2]:
                    for unit in ["in", "cm"]:
                        c = SVGConfig(width=width,
                                      height=height,
                                      headerHeight=headerHeight,
                                      unit=unit)
                        l1.layer.description = f"{width}x{height}{unit}; header={headerHeight}"