コード例 #1
0
ファイル: vfs_test_lib.py プロジェクト: tanner-g/grr
 def _NormalizeCaseForPath(self, path, vfs_type):
     """Handle casing differences for different filesystems."""
     # Special handling for case sensitivity of registry keys.
     # This mimicks the behavior of the operating system.
     if self.supported_pathtype == rdf_paths.PathSpec.PathType.REGISTRY:
         self.path = self.path.replace("\\", "/")
         parts = path.split("/")
         if vfs_type == aff4_grr.VFSFile:
             # If its a file, the last component is a value which is case sensitive.
             lower_parts = [x.lower() for x in parts[0:-1]]
             lower_parts.append(parts[-1])
             path = utils.Join(*lower_parts)
         else:
             path = utils.Join(*[x.lower() for x in parts])
     return path
コード例 #2
0
ファイル: basic_test.py プロジェクト: ytisf/grr
    def testRDFURN(self):
        """Test RDFURN handling."""
        # Make a url object
        str_url = "aff4:/hunts/W:AAAAAAAA/Results"
        url = rdfvalue.RDFURN(str_url, age=1)
        self.assertEqual(url.age, 1)
        self.assertEqual(url.Path(), "/hunts/W:AAAAAAAA/Results")
        self.assertEqual(str(url), str_url)
        self.assertEqual(url.scheme, "aff4")

        # Test the Add() function
        url = url.Add("some", age=2).Add("path", age=3)
        self.assertEqual(url.age, 3)
        self.assertEqual(url.Path(), "/hunts/W:AAAAAAAA/Results/some/path")
        self.assertEqual(str(url), utils.Join(str_url, "some", "path"))

        # Test that we can handle urns with a '?' and do not interpret them as
        # a delimiter between url and parameter list.
        str_url = "aff4:/C.0000000000000000/fs/os/c/regex.*?]&[+{}--"
        url = rdfvalue.RDFURN(str_url, age=1)
        self.assertEqual(url.Path(), str_url[5:])

        # Some more special characters...
        for path in ["aff4:/test/?#asd", "aff4:/test/#asd", "aff4:/test/?#"]:
            self.assertEqual(path, str(rdfvalue.RDFURN(path)))
コード例 #3
0
 def OpenKey(self, key, sub_key):
   res = "%s/%s" % (key.value, sub_key.replace("\\", "/"))
   res = res.rstrip("/")
   parts = res.split("/")
   for cache_key in [
       utils.Join(*[p.lower() for p in parts[:-1]] + parts[-1:]), res.lower()
   ]:
     if not cache_key.startswith("/"):
       cache_key = "/" + cache_key
     if cache_key in self.cache[self.prefix]:
       return FakeKeyHandle(cache_key)
   raise IOError()
コード例 #4
0
ファイル: standard_test.py プロジェクト: switters72/grr
  def testExecuteBinary(self):
    """Test the basic ExecuteBinaryCommand action."""
    signed_blob = rdf_crypto.SignedBlob()
    signed_blob.Sign(open("/bin/ls", "rb").read(), self.signing_key)

    writefile = utils.Join(self.temp_dir, "binexecute", "ablob")
    os.makedirs(os.path.dirname(writefile))
    request = rdf_client.ExecuteBinaryRequest(
        executable=signed_blob, args=[__file__], write_path=writefile)

    result = self.RunAction(standard.ExecuteBinaryCommand, request)[0]

    self.assertTrue(result.time_used > 0)
    self.assertTrue(__file__ in result.stdout)