Пример #1
0
class DefaultNmapExporterTest(unittest.TestCase):
    @patch("app.logging.legionLog.log")
    def setUp(self, legionLog) -> None:
        from app.tools.nmap.DefaultNmapExporter import DefaultNmapExporter
        self.mockShell = MagicMock()
        self.log = legionLog
        self.nmapExporter = DefaultNmapExporter(self.mockShell)

    @patch("subprocess.Popen")
    def test_exportOutputToHtml_WhenProvidedFileNameAndOutputFolder_ExportsOutputSuccessfully(
            self, processOpen):
        exportCommand = f"xsltproc -o some-file.html nmap.xsl some-file.xml"
        self.nmapExporter.exportOutputToHtml("some-file", "some-folder/")
        processOpen.assert_called_once_with(exportCommand, shell=True)
        self.mockShell.move.assert_called_once_with("some-file.html",
                                                    "some-folder/")

    @patch("subprocess.Popen")
    def test_exportOutputToHtml_WhenExportFailsDueToProcessError_DoesNotMoveAnyFilesToOutputFolder(
            self, processOpen):
        exportCommand = f"xsltproc -o some-bad-file.html nmap.xsl some-bad-file.xml"
        processOpen.side_effect = Exception("something went wrong")
        self.nmapExporter.exportOutputToHtml("some-bad-file", "some-folder/")
        processOpen.assert_called_once_with(exportCommand, shell=True)
        self.mockShell.move.assert_not_called()
        self.log.error.assert_called()
Пример #2
0
 def setUp(self, legionLog) -> None:
     from app.tools.nmap.DefaultNmapExporter import DefaultNmapExporter
     self.mockShell = MagicMock()
     self.log = legionLog
     self.nmapExporter = DefaultNmapExporter(self.mockShell)
Пример #3
0
    except IOError:
        startupLog.error(
            "The legion.qss file is missing. Your installation seems to be corrupted. "
            + "Try downloading the latest version.")
        exit(0)

    MainWindow.setStyleSheet(qss_file)

    shell = DefaultShell()

    dbLog = getDbLogger()
    appLogger = getAppLogger()

    repositoryFactory = RepositoryFactory(dbLog)
    projectManager = ProjectManager(shell, repositoryFactory, appLogger)
    nmapExporter = DefaultNmapExporter(shell, appLogger)
    toolCoordinator = ToolCoordinator(shell, nmapExporter)
    # Model prep (logic, db and models)
    logic = Logic(shell, projectManager, toolCoordinator)

    startupLog.info("Creating temporary project at application start...")
    logic.createNewTemporaryProject()

    viewState = ViewState()
    view = View(viewState, ui, MainWindow, shell)  # View prep (gui)
    controller = Controller(
        view, logic)  # Controller prep (communication between model and view)
    view.qss = qss_file

    myFilter = MyEventFilter(view, MainWindow)  # to capture events
    app.installEventFilter(myFilter)
Пример #4
0
    try:
        qss_file = open('./ui/legion.qss').read()
    except IOError:
        log.info(
            "The legion.qss file is missing. Your installation seems to be corrupted. "
            + "Try downloading the latest version.")
        exit(0)

    MainWindow.setStyleSheet(qss_file)

    shell = DefaultShell()

    repositoryFactory = RepositoryFactory(log)
    projectManager = ProjectManager(shell, repositoryFactory, log)
    nmapExporter = DefaultNmapExporter(shell)
    toolCoordinator = ToolCoordinator(shell, nmapExporter)
    # Model prep (logic, db and models)
    logic = Logic(shell, projectManager, toolCoordinator)

    log.info("Creating temporary project at application start...")
    logic.createNewTemporaryProject()

    viewState = ViewState()
    view = View(viewState, ui, MainWindow, shell)  # View prep (gui)
    controller = Controller(
        view, logic)  # Controller prep (communication between model and view)
    view.qss = qss_file

    myFilter = MyEventFilter(view, MainWindow)  # to capture events
    app.installEventFilter(myFilter)