Beispiel #1
0
    def testFiltersResults(self):
        flow_id = flow_test_lib.StartFlow(
            filesystem.ListDirectory,
            creator=self.test_username,
            client_id=self.client_id,
            pathspec=rdf_paths.PathSpec.OS(path="/path"))

        with flow_test_lib.FlowResultMetadataOverride(
                filesystem.ListDirectory,
                rdf_flow_objects.FlowResultMetadata(
                    is_metadata_set=True,
                    num_results_per_type_tag=[
                        rdf_flow_objects.FlowResultCount(
                            type=rdf_client_fs.StatEntry.__name__, count=1)
                    ])):
            self.Open(f"/v2/clients/{self.client_id}")
            self.WaitUntil(self.IsElementPresent,
                           "css=.flow-title:contains('ListDirectory')")

            flow_test_lib.AddResultsToFlow(self.client_id, flow_id, [
                rdf_client_fs.StatEntry(pathspec=rdf_paths.PathSpec.OS(
                    path=f"file{i}")) for i in range(10)
            ])

            self.Click("css=result-accordion .title:contains('/path')")
            for i in range(10):
                self.WaitUntil(self.IsElementPresent,
                               f"css=td:contains('file{i}')")

            self.Type("css=.filter-input input", "file0")
            self.WaitUntil(self.IsElementPresent, "css=td:contains('file0')")
            # Selecting .path class here to avoid obtaining the file icon column.
            self.assertEqual(self.GetCssCount("css=td.path:contains('file')"),
                             1)
Beispiel #2
0
    def PersistState(self) -> None:
        """Persists flow state."""
        if hasattr(self.state, "_result_metadata"):
            result_metadata = self.state._result_metadata  # pylint: disable=protected-access
        else:
            result_metadata = rdf_flow_objects.FlowResultMetadata()
            result_metadata.is_metadata_set = True

        for r in result_metadata.num_results_per_type_tag:
            key = (r.type, r.tag)
            # This removes the item from _num_replies_per_type_tag if it's present in
            # result_metadata.
            count = self._num_replies_per_type_tag.pop(key, 0)
            r.count += count

        # Iterate over remaining items - i.e. items that were not present in
        # result_metadata.
        for (result_type,
             result_tag), count in self._num_replies_per_type_tag.items():
            result_metadata.num_results_per_type_tag.append(
                rdf_flow_objects.FlowResultCount(type=result_type,
                                                 tag=result_tag,
                                                 count=count))

        self.state._result_metadata = result_metadata  # pylint: disable=protected-access
        self._num_replies_per_type_tag = collections.Counter()
        self.rdf_flow.persistent_data = self.state
Beispiel #3
0
    def testDisplaysResults(self):
        flow_id = flow_test_lib.StartFlow(
            filesystem.ListDirectory,
            creator=self.test_username,
            client_id=self.client_id,
            pathspec=rdf_paths.PathSpec.OS(path="/path"))

        with flow_test_lib.FlowResultMetadataOverride(
                filesystem.ListDirectory,
                rdf_flow_objects.FlowResultMetadata(
                    is_metadata_set=True,
                    num_results_per_type_tag=[
                        rdf_flow_objects.FlowResultCount(
                            type=rdf_client_fs.StatEntry.__name__, count=1)
                    ])):
            self.Open(f"/v2/clients/{self.client_id}")
            self.WaitUntil(self.IsElementPresent,
                           "css=.flow-title:contains('ListDirectory')")

            flow_test_lib.AddResultsToFlow(self.client_id, flow_id, [
                rdf_client_fs.StatEntry(pathspec=rdf_paths.PathSpec.OS(
                    path=f"file{i}")) for i in range(10)
            ])

            self.Click("css=result-accordion .title:contains('/path')")
            for i in range(10):
                self.WaitUntil(self.IsElementPresent,
                               f"css=td:contains('file{i}')")
Beispiel #4
0
    def testPaginationSize(self):
        flow_id = flow_test_lib.StartFlow(
            filesystem.ListDirectory,
            creator=self.test_username,
            client_id=self.client_id,
            pathspec=rdf_paths.PathSpec.OS(path="/path"))

        with flow_test_lib.FlowResultMetadataOverride(
                filesystem.ListDirectory,
                rdf_flow_objects.FlowResultMetadata(
                    is_metadata_set=True,
                    num_results_per_type_tag=[
                        rdf_flow_objects.FlowResultCount(
                            type=rdf_client_fs.StatEntry.__name__, count=1)
                    ])):
            self.Open(f"/v2/clients/{self.client_id}")
            self.WaitUntil(self.IsElementPresent,
                           "css=.flow-title:contains('ListDirectory')")

            flow_test_lib.AddResultsToFlow(self.client_id, flow_id, [
                rdf_client_fs.StatEntry(pathspec=rdf_paths.PathSpec.OS(
                    path=f"file{i}")) for i in range(15)
            ])

            self.Click("css=result-accordion .title:contains('/path')")
            for i in range(10):
                self.WaitUntil(self.IsElementPresent,
                               f"css=td:contains('file{i}')")
            self.assertEqual(self.GetCssCount("css=td.path:contains('file')"),
                             10)

            # Select one paginator updates the other paginator as well as the
            # displayed rows.
            self.MatSelect("css=.bottom-paginator mat-select", "50")
            self.WaitUntilContains("50", self.GetText,
                                   "css=.top-paginator mat-select")
            self.WaitUntilContains("50", self.GetText,
                                   "css=.bottom-paginator mat-select")
            for i in range(15):
                self.WaitUntil(self.IsElementPresent,
                               f"css=td:contains('file{i}')")
            self.assertEqual(self.GetCssCount("css=td.path:contains('file')"),
                             15)

            self.MatSelect("css=.top-paginator mat-select", "10")
            self.WaitUntilContains("10", self.GetText,
                                   "css=.top-paginator mat-select")
            self.WaitUntilContains("10", self.GetText,
                                   "css=.bottom-paginator mat-select")
            for i in range(10):
                self.WaitUntil(self.IsElementPresent,
                               f"css=td:contains('file{i}')")
            self.assertEqual(self.GetCssCount("css=td.path:contains('file')"),
                             10)
Beispiel #5
0
  def testDisplaysDownloadButtonAndArgs(self):
    flow_args = rdf_read_low_level.ReadLowLevelArgs(
        path="/path", length="789", offset="987")

    flow_id = flow_test_lib.StartFlow(
        read_low_level.ReadLowLevel,
        creator=self.test_username,
        client_id=self.client_id,
        flow_args=flow_args)
    print("flow_id", flow_id)

    self.Open(f"/v2/clients/{self.client_id}")

    self.WaitUntil(self.IsElementPresent,
                   f"css=.flow-id span:contains('{flow_id}')")

    self.ScrollToBottom()
    self.WaitUntil(self.IsElementPresent,
                   "css=result-accordion .title:contains('/path')")
    self.WaitUntil(self.IsElementPresent,
                   "css=result-accordion .title:contains('789')")
    self.WaitUntil(self.IsElementPresent,
                   "css=result-accordion .title:contains('987')")

    self.WaitUntilNot(self.IsElementPresent,
                      "css=a[mat-stroked-button]:contains('Download')")
    flow_test_lib.MarkFlowAsFinished(client_id=self.client_id, flow_id=flow_id)
    with flow_test_lib.FlowResultMetadataOverride(
        read_low_level.ReadLowLevel,
        rdf_flow_objects.FlowResultMetadata(
            is_metadata_set=True,
            num_results_per_type_tag=[
                rdf_flow_objects.FlowResultCount(
                    type=rdf_read_low_level.ReadLowLevelFlowResult.__name__,
                    count=1)
            ])):
      self.WaitUntil(self.IsElementPresent,
                     "css=a[mat-stroked-button]:contains('Download')")

    self.WaitUntil(
        self.IsElementPresent,
        f"css=a[href='/api/v2/clients/{self.client_id}/vfs-blob/temp/"
        f"{self.client_id}_{flow_id}_path']")

    self.Click("css=result-accordion .title:contains('/path')")

    self.WaitUntil(self.IsElementPresent,
                   "css=result-accordion:contains('Path: /path')")
    self.WaitUntil(self.IsElementPresent,
                   "css=result-accordion:contains('Length: 789')")
    self.WaitUntil(self.IsElementPresent,
                   "css=result-accordion:contains('Offset: 987')")
Beispiel #6
0
    def testShowsDownloadButtonOnFlowCompletion(self):
        flow_args = webhistory.CollectBrowserHistoryArgs(
            browsers=[webhistory.CollectBrowserHistoryArgs.Browser.CHROME])
        flow_id = flow_test_lib.StartFlow(webhistory.CollectBrowserHistory,
                                          creator=self.test_username,
                                          client_id=self.client_id,
                                          flow_args=flow_args)

        with flow_test_lib.FlowProgressOverride(
                webhistory.CollectBrowserHistory,
                webhistory.CollectBrowserHistoryProgress(browsers=[
                    webhistory.BrowserProgress(
                        browser=webhistory.Browser.CHROME,
                        status=webhistory.BrowserProgress.Status.IN_PROGRESS,
                        num_collected_files=0,
                    ),
                ])):
            self.Open(f"/v2/clients/{self.client_id}")
            # Make sure that the flow panel is already displayed...
            self.WaitUntil(self.IsElementPresent,
                           "css=.flow-title:contains('Browser History')")
            # ...and then check for the presence of the 'Download all' button.
            self.WaitUntilNot(
                self.IsElementPresent,
                "css=a[mat-stroked-button]:contains('Download all')")

        flow_test_lib.MarkFlowAsFinished(self.client_id, flow_id)

        with flow_test_lib.FlowProgressOverride(
                webhistory.CollectBrowserHistory,
                webhistory.CollectBrowserHistoryProgress(browsers=[
                    webhistory.BrowserProgress(
                        browser=webhistory.Browser.CHROME,
                        status=webhistory.BrowserProgress.Status.IN_PROGRESS,
                        num_collected_files=1,
                    ),
                ])):
            with flow_test_lib.FlowResultMetadataOverride(
                    webhistory.CollectBrowserHistory,
                    rdf_flow_objects.FlowResultMetadata(
                        is_metadata_set=True,
                        num_results_per_type_tag=[
                            rdf_flow_objects.FlowResultCount(
                                type=webhistory.CollectBrowserHistoryResult.
                                __name__,
                                count=1)
                        ])):
                # The flow details view should get updated automatically.
                self.WaitUntil(
                    self.IsElementPresent,
                    "css=a[mat-stroked-button]:contains('Download')")
Beispiel #7
0
    def testPaginationNavigation(self):
        flow_id = flow_test_lib.StartFlow(
            filesystem.ListDirectory,
            creator=self.test_username,
            client_id=self.client_id,
            pathspec=rdf_paths.PathSpec.OS(path="/path"))

        with flow_test_lib.FlowResultMetadataOverride(
                filesystem.ListDirectory,
                rdf_flow_objects.FlowResultMetadata(
                    is_metadata_set=True,
                    num_results_per_type_tag=[
                        rdf_flow_objects.FlowResultCount(
                            type=rdf_client_fs.StatEntry.__name__, count=1)
                    ])):
            self.Open(f"/v2/clients/{self.client_id}")
            self.WaitUntil(self.IsElementPresent,
                           "css=.flow-title:contains('ListDirectory')")

            flow_test_lib.AddResultsToFlow(self.client_id, flow_id, [
                rdf_client_fs.StatEntry(pathspec=rdf_paths.PathSpec.OS(
                    path=f"file{i}")) for i in range(15)
            ])

            self.Click("css=result-accordion .title:contains('/path')")
            for i in range(10):
                self.WaitUntil(self.IsElementPresent,
                               f"css=td:contains('file{i}')")
            self.assertEqual(self.GetCssCount("css=td.path:contains('file')"),
                             10)

            # Navigation works in both top and bottom paginators.
            self.Click("css=.top-paginator .mat-paginator-navigation-last")
            for i in range(10, 15):
                self.WaitUntil(self.IsElementPresent,
                               f"css=td:contains('file{i}')")
            self.assertEqual(self.GetCssCount("css=td.path:contains('file')"),
                             5)

            self.ScrollToBottom()
            self.Click(
                "css=.bottom-paginator .mat-paginator-navigation-previous")
            for i in range(10):
                self.WaitUntil(self.IsElementPresent,
                               f"css=td:contains('file{i}')")
            self.assertEqual(self.GetCssCount("css=td.path:contains('file')"),
                             10)
Beispiel #8
0
    def testDownloadButtonFlowFinished(self):
        flow_args = rdf_file_finder.CollectFilesByKnownPathArgs(
            paths=["/file0"])
        flow_id = flow_test_lib.StartFlow(file.CollectFilesByKnownPath,
                                          creator=self.test_username,
                                          client_id=self.client_id,
                                          flow_args=flow_args)

        flow_test_lib.MarkFlowAsFinished(self.client_id, flow_id)

        with flow_test_lib.FlowResultMetadataOverride(
                file.CollectFilesByKnownPath,
                rdf_flow_objects.FlowResultMetadata(
                    is_metadata_set=True,
                    num_results_per_type_tag=[
                        rdf_flow_objects.FlowResultCount(
                            type=rdf_file_finder.CollectFilesByKnownPathResult.
                            __name__,
                            count=1)
                    ])):
            self.Open(f"/v2/clients/{self.client_id}")
            self.WaitUntil(self.IsElementPresent,
                           "css=a[mat-stroked-button]:contains('Download')")
Beispiel #9
0
    def testCorrectlyDisplaysDownloadButtonOnSuccess(self):
        flow_args = rdf_file_finder.CollectSingleFileArgs(path="/etc/hosts")
        flow_id = flow_test_lib.StartFlow(file.CollectSingleFile,
                                          creator=self.test_username,
                                          client_id=self.client_id,
                                          flow_args=flow_args)

        self.Open(f"/v2/clients/{self.client_id}")
        self.WaitUntil(
            self.IsElementPresent,
            "css=collect-single-file-details .requested-path:contains('/etc/hosts')"
        )
        self.WaitUntilNot(self.IsElementPresent,
                          "css=a[mat-stroked-button]:contains('Download')")

        flow_test_lib.MarkFlowAsFinished(self.client_id, flow_id)

        with flow_test_lib.FlowProgressOverride(
                file.CollectSingleFile,
                rdf_file_finder.CollectSingleFileProgress(
                    status=rdf_file_finder.CollectSingleFileProgress.Status.
                    COLLECTED,
                    result=self._GenSampleResult())):
            with flow_test_lib.FlowResultMetadataOverride(
                    file.CollectSingleFile,
                    rdf_flow_objects.FlowResultMetadata(
                        is_metadata_set=True,
                        num_results_per_type_tag=[
                            rdf_flow_objects.FlowResultCount(
                                type=rdf_file_finder.CollectSingleFileResult.
                                __name__,
                                count=1)
                        ])):
                self.WaitUntil(
                    self.IsElementPresent,
                    "css=a[mat-stroked-button]:contains('Download')")
Beispiel #10
0
 def GetResultMetadata(self) -> rdf_flow_objects.FlowResultMetadata:
     if hasattr(self.state, "_result_metadata"):
         return self.state._result_metadata.Copy()  # pylint: disable=protected-access
     else:
         return rdf_flow_objects.FlowResultMetadata()