Exemplo n.º 1
0
 def _ProcessCommandSource(self, args):
     action = standard.ExecuteCommand
     request = rdf_client_action.ExecuteRequest(
         cmd=args.base_source.attributes["cmd"],
         args=args.base_source.attributes["args"],
     )
     yield action, request
Exemplo n.º 2
0
    def testCmdArtifact(self):
        """Test the parsing of an Echo Command with a TestParser."""
        client_test_lib.Command("/bin/echo", args=["1"])

        processor = parser.Parser.GetClassesByArtifact(
            "TestEchoCmdArtifact")[0]()

        self.assertIsInstance(processor, TestEchoCmdParser)

        request = rdf_client_action.ExecuteRequest(cmd="/bin/echo", args=["1"])
        res = client_utils_common.Execute(request.cmd, request.args)
        (stdout, stderr, status, time_used) = res

        response = rdf_client_action.ExecuteResponse(request=request,
                                                     stdout=stdout,
                                                     stderr=stderr,
                                                     exit_status=status,
                                                     time_used=int(1e6 *
                                                                   time_used))

        path_type = rdf_paths.PathSpec.PathType.OS
        results = []
        for res in artifact_collector.ParseSingleResponse(
                processor, response, {}, path_type):
            results.append(res)

        self.assertEqual(len(results), 1)
        self.assertIsInstance(results[0], rdf_client.SoftwarePackage)
        self.assertEqual(results[0].description, "1\n")
Exemplo n.º 3
0
  def testExportsValueCorrectly(self):
    sample = rdf_client_action.ExecuteResponse(
        request=rdf_client_action.ExecuteRequest(
            cmd="some cmd",
            args=["-foo", "-bar"],
            time_limit=42,
        ),
        exit_status=-1,
        stdout=b"stdout",
        stderr=b"stderr",
        time_used=420,
    )

    converter = execute_response.ExecuteResponseConverter()
    converted = list(converter.Convert(self.metadata, sample))
    self.assertLen(converted, 1)
    c = converted[0]

    self.assertEqual(c.metadata, self.metadata)
    self.assertEqual(c.cmd, "some cmd")
    self.assertEqual(c.args, "-foo -bar")
    self.assertEqual(c.exit_status, -1)
    self.assertEqual(c.stdout, b"stdout")
    self.assertEqual(c.stderr, b"stderr")
    self.assertEqual(c.time_used_us, 420)
Exemplo n.º 4
0
 def _ProcessCommandSource(self, source):
   """Prepare a request for calling the execute command action."""
   action = standard.ExecuteCommandFromClient
   request = rdf_client_action.ExecuteRequest(
       cmd=source.base_source.attributes["cmd"],
       args=source.base_source.attributes["args"],
   )
   yield action, request