Exemplo n.º 1
0
    def testChangingVersionDropdownChangesClientInformation(self):
        self.Open("/#/clients/%s" % self.client_id)

        # Check that the newest version is selected.
        self.WaitUntilContains(gui_test_lib.DateString(gui_test_lib.TIME_2),
                               self.GetText,
                               "css=.version-dropdown > option[selected]")
        self.WaitUntil(self.IsTextPresent, "Hostname T2")
        self.WaitUntil(self.IsTextPresent, "12GiB")

        self.Click("css=select.version-dropdown > option:contains(\"%s\")" %
                   gui_test_lib.DateString(gui_test_lib.TIME_1))
        self.WaitUntil(self.IsTextPresent, "Hostname T1")
        self.WaitUntil(self.IsTextPresent, "6.1.8000")
        self.WaitUntil(self.IsTextPresent, "8GiB")
        self.WaitUntil(self.IsTextPresent, "Newer Version available")

        # Also the details show the selected version.
        self.Click("css=label:contains('Full details')")
        self.WaitUntil(self.IsTextPresent, "Hostname T1")
        self.WaitUntil(self.IsTextPresent, "6.1.8000")
        self.WaitUntil(self.IsTextPresent, "8GiB")

        # Check that changing the version does not change the view, i.e. that
        # we are still in the full details view.
        self.Click("css=select.version-dropdown > option:contains(\"%s\")" %
                   gui_test_lib.DateString(gui_test_lib.TIME_0))
        self.WaitUntil(self.IsTextPresent, "Hostname T0")
        self.WaitUntil(self.IsTextPresent, "6.1.7000")
        self.WaitUntil(self.IsTextPresent, "4GiB")
Exemplo n.º 2
0
    def testTimelineShowsClosestFileVersionOnFileSelection(self):
        # Open VFS view for client 1 on a specific location.
        self.Open("/#c=C.0000000000000001&main=VirtualFileSystemView"
                  "&t=_fs-os-c-proc")

        # We have to wait until the "proc" node gets highlighted in the tree,
        # as the tree expansion may take time and happen in multiple steps.
        # On every expansion step, the view mode will be switched to "file list",
        # even if "timeline" mode was previously active.
        self.WaitUntil(self.IsElementPresent,
                       "css=a.jstree-clicked:contains('proc')")
        self.WaitUntilEqual(2, self.GetCssCount, "css=.file-list tbody tr")

        self.Click("css=.btn:contains('Timeline')")

        # The first item has the latest time, so the version dropdown should not
        # show a hint.
        self.Click(
            "css=grr-file-timeline table td:contains('changed.txt'):first")
        self.WaitUntilContains("changed.txt", self.GetText,
                               "css=div#main_bottomPane h1")
        self.WaitUntilContains(gui_test_lib.DateString(gui_test_lib.TIME_1),
                               self.GetText,
                               "css=.version-dropdown > option[selected]")

        # The last timeline item for changed.txt has a timestamp before
        # gui_test_lib.TIME_0, which is the first available file version.
        self.Click("css=grr-file-timeline table tr "
                   "td:contains('changed.txt'):last")
        self.WaitUntilContains("changed.txt", self.GetText,
                               "css=div#main_bottomPane h1")
        self.WaitUntilContains(gui_test_lib.DateString(gui_test_lib.TIME_0),
                               self.GetText,
                               "css=.version-dropdown > option[selected]")
        self.WaitUntilContains("Newer Version available.", self.GetText,
                               "css=grr-file-details")
Exemplo n.º 3
0
    def testSwitchingBetweenFileVersionsRefreshesDownloadTab(self):
        urn_a = rdfvalue.RDFURN("%s/fs/os/c/Downloads/a.txt" % self.client_id)
        path_info = rdf_objects.PathInfo.OS(
            components=["c", "Downloads", "a.txt"])

        # Test files are set up using self.CreateFileVersions call in test's
        # setUp method. Amend created file versions by adding different
        # hashes to versions corresponding to different times.
        # Note that a string passed to fd.Schema.HASH constructor will be
        # printed as a hexademical bytestring. Thus "111" will become "313131"
        # and "222" will become "323232".
        with test_lib.FakeTime(gui_test_lib.TIME_0):
            with aff4.FACTORY.Create(urn_a,
                                     aff4_type=aff4_grr.VFSFile,
                                     force_new_version=False,
                                     object_exists=True) as fd:
                fd.Set(fd.Schema.HASH(sha256="111"))

            if data_store.RelationalDBWriteEnabled():
                path_info.hash_entry.sha256 = b"111"
                data_store.REL_DB.WritePathInfos(self.client_id, [path_info])

        with test_lib.FakeTime(gui_test_lib.TIME_1):
            with aff4.FACTORY.Create(urn_a,
                                     aff4_type=aff4_grr.VFSFile,
                                     force_new_version=False,
                                     object_exists=True) as fd:
                fd.Set(fd.Schema.HASH(sha256="222"))

            if data_store.RelationalDBWriteEnabled():
                path_info.hash_entry.sha256 = b"222"
                data_store.REL_DB.WritePathInfos(self.client_id, [path_info])

        # Open a URL corresponding to a HEAD version of the file.
        self.Open("/#/clients/%s/vfs/fs/os/c/Downloads/a.txt?tab=download" %
                  self.client_id)
        # Make sure displayed hash value is correct.
        self.WaitUntil(self.IsElementPresent,
                       "css=tr:contains('Sha256') td:contains('323232')")

        # Select the previous file version.
        self.Click("css=select.version-dropdown > option:contains(\"%s\")" %
                   gui_test_lib.DateString(gui_test_lib.TIME_0))
        # Make sure displayed hash value gets updated.
        self.WaitUntil(self.IsElementPresent,
                       "css=tr:contains('Sha256') td:contains('313131')")
Exemplo n.º 4
0
    def testVersionDropDownChangesFileContentAndDownloads(self):
        """Test the fileview interface."""

        self.Open("/#/clients/%s" % self.client_id)

        # Go to Browse VFS.
        self.Click("css=a[grrtarget='client.vfs']")

        self.Click("css=#_fs i.jstree-icon")
        self.Click("css=#_fs-os i.jstree-icon")
        self.Click("css=#_fs-os-c i.jstree-icon")

        # Test file versioning.
        self.WaitUntil(self.IsElementPresent, "css=#_fs-os-c-Downloads")
        self.Click("link=Downloads")

        # Verify that we have the latest version in the table by default.
        self.assertTrue(
            gui_test_lib.DateString(gui_test_lib.TIME_2) in self.GetText(
                "css=tr:contains(\"a.txt\")"))

        # Click on the row.
        self.Click("css=tr:contains(\"a.txt\")")
        self.WaitUntilContains("a.txt", self.GetText,
                               "css=div#main_bottomPane h1")
        self.WaitUntilContains("HEAD", self.GetText,
                               "css=.version-dropdown > option[selected]")
        self.WaitUntilContains(gui_test_lib.DateString(gui_test_lib.TIME_2),
                               self.GetText,
                               "css=.version-dropdown > option:nth(1)")

        # Check the data in this file.
        self.Click("css=li[heading=TextView]")
        self.WaitUntilContains("Goodbye World", self.GetText,
                               "css=div.monospace pre")

        downloaded_files = []

        def FakeDownloadHandle(unused_self, args, token=None):
            _ = token  # Avoid unused variable linter warnings.
            aff4_path = args.client_id.ToClientURN().Add(args.file_path)
            age = args.timestamp or aff4.NEWEST_TIME
            downloaded_files.append((aff4_path, age))

            return api_call_handler_base.ApiBinaryStream(
                filename=aff4_path.Basename(), content_generator=xrange(42))

        with utils.Stubber(api_vfs.ApiGetFileBlobHandler, "Handle",
                           FakeDownloadHandle):
            # Try to download the file.
            self.Click("css=li[heading=Download]")

            self.WaitUntilContains(
                gui_test_lib.DateTimeString(gui_test_lib.TIME_2), self.GetText,
                "css=grr-file-download-view")
            self.Click("css=button:contains(\"Download\")")

            # Select the previous version.
            self.Click(
                "css=select.version-dropdown > option:contains(\"%s\")" %
                gui_test_lib.DateString(gui_test_lib.TIME_1))

            # Now we should have a different time.
            self.WaitUntilContains(
                gui_test_lib.DateTimeString(gui_test_lib.TIME_1), self.GetText,
                "css=grr-file-download-view")
            self.Click("css=button:contains(\"Download\")")

            self.WaitUntil(self.IsElementPresent, "css=li[heading=TextView]")

            # the FakeDownloadHandle method was actually called four times, since
            # a file download first sends a HEAD request to check user access.
            self.WaitUntil(lambda: len(downloaded_files) == 4)

        # Both files should be the same...
        self.assertEqual(downloaded_files[0][0],
                         u"aff4:/%s/fs/os/c/Downloads/a.txt" % self.client_id)
        self.assertEqual(downloaded_files[2][0],
                         u"aff4:/%s/fs/os/c/Downloads/a.txt" % self.client_id)
        # But from different times. The downloaded file timestamp is only accurate
        # to the nearest second. Also, the HEAD version of the file is downloaded
        # with age=NEWEST_TIME.
        self.assertEqual(downloaded_files[0][1], aff4.NEWEST_TIME)
        self.assertAlmostEqual(downloaded_files[2][1],
                               gui_test_lib.TIME_1,
                               delta=rdfvalue.Duration("1s"))

        self.Click("css=li[heading=TextView]")

        # Make sure the file content has changed. This version has "Hello World" in
        # it.
        self.WaitUntilContains("Hello World", self.GetText,
                               "css=div.monospace pre")