Exemplo n.º 1
0
 def testConverterIsCorrectlyFound(self):
   dummy_value = DummyRDFValue("result")
   result = list(export.ConvertValues(rdfvalue.ExportedMetadata(),
                                      [dummy_value]))
   self.assertEqual(len(result), 1)
   self.assertTrue(isinstance(result[0], rdfvalue.RDFString))
   self.assertEqual(result[0], "result")
Exemplo n.º 2
0
  def testConvertsHuntCollectionWithValuesWithMultipleConverters(self):
    fd = aff4.FACTORY.Create("aff4:/testcoll", "RDFValueCollection",
                             token=self.token)

    msg = rdfvalue.GrrMessage(payload=DummyRDFValue3("some1"))
    msg.source = rdfvalue.ClientURN("C.0000000000000000")
    fd.Add(msg)
    test_lib.ClientFixture(msg.source, token=self.token)

    msg = rdfvalue.GrrMessage(payload=DummyRDFValue3("some2"))
    msg.source = rdfvalue.ClientURN("C.0000000000000001")
    fd.Add(msg)
    test_lib.ClientFixture(msg.source, token=self.token)

    fd.Close()

    fd = aff4.FACTORY.Open("aff4:/testcoll", aff4_type="RDFValueCollection",
                           token=self.token)

    results = export.ConvertValues(rdfvalue.ExportedMetadata(), [fd],
                                   token=self.token)
    results = sorted(results, key=str)

    self.assertEqual(len(results), 4)
    self.assertEqual([str(v) for v in results
                      if isinstance(v, rdfvalue.DummyRDFValue)],
                     ["some1A", "some2A"])
    self.assertEqual([str(v) for v in results
                      if isinstance(v, rdfvalue.DummyRDFValue2)],
                     ["some1B", "some2B"])
Exemplo n.º 3
0
  def testConvertsHuntCollectionWithValuesWithSingleConverter(self):
    fd = aff4.FACTORY.Create("aff4:/testcoll", "RDFValueCollection",
                             token=self.token)

    msg = rdfvalue.GrrMessage(payload=DummyRDFValue("some"))
    msg.source = rdfvalue.ClientURN("C.0000000000000000")
    fd.Add(msg)
    test_lib.ClientFixture(msg.source, token=self.token)

    msg = rdfvalue.GrrMessage(payload=DummyRDFValue("some2"))
    msg.source = rdfvalue.ClientURN("C.0000000000000001")
    fd.Add(msg)
    test_lib.ClientFixture(msg.source, token=self.token)

    fd.Close()

    fd = aff4.FACTORY.Open("aff4:/testcoll", aff4_type="RDFValueCollection",
                           token=self.token)

    results = export.ConvertValues(rdfvalue.ExportedMetadata(), [fd],
                                   token=self.token)
    results = sorted(str(v) for v in results)

    self.assertEqual(len(results), 2)
    self.assertEqual(results[0], "some")
    self.assertEqual(results[1], "some2")
Exemplo n.º 4
0
 def testConvertsSingleValueWithMultipleAssociatedConverters(self):
   dummy_value = DummyRDFValue3("some")
   result = list(export.ConvertValues(rdfvalue.ExportedMetadata(),
                                      [dummy_value]))
   self.assertEqual(len(result), 2)
   self.assertTrue((isinstance(result[0], rdfvalue.DummyRDFValue) and
                    isinstance(result[1], rdfvalue.DummyRDFValue2)) or
                   (isinstance(result[0], rdfvalue.DummyRDFValue2) and
                    isinstance(result[1], rdfvalue.DummyRDFValue)))
   self.assertTrue((result[0] == rdfvalue.DummyRDFValue("someA") and
                    result[1] == rdfvalue.DummyRDFValue2("someB")) or
                   (result[0] == rdfvalue.DummyRDFValue2("someB") and
                    result[1] == rdfvalue.DummyRDFValue("someA")))
Exemplo n.º 5
0
    def ProcessResponses(self, responses):
        default_metadata = rdfvalue.ExportedMetadata(
            source_urn=self.state.collection_urn)

        if self.state.args.convert_values:
            # This is thread-safe - we just convert the values.
            converted_responses = export.ConvertValues(
                default_metadata,
                responses,
                token=self.state.token,
                options=self.state.args.export_options)
        else:
            converted_responses = responses

        # This is not thread-safe, therefore WriteValueToCSVFile is synchronized.
        self.WriteValuesToCSVFile(converted_responses)
Exemplo n.º 6
0
  def ProcessResponses(self, responses):
    default_metadata = export.ExportedMetadata(
        annotations=u",".join(self.args.export_options.annotations),
        source_urn=self.state.source_urn)

    if self.args.convert_values:
      # This is thread-safe - we just convert the values.
      converted_responses = export.ConvertValues(
          default_metadata,
          responses,
          token=self.token,
          options=self.args.export_options)
    else:
      converted_responses = responses

    # This is not thread-safe, therefore WriteValueToJSONFile is synchronized.
    self.WriteValuesToJSONFile(converted_responses)
Exemplo n.º 7
0
 def testRaisesWhenNoConverterFound(self):
   dummy_value = DummyRDFValue2("some")
   result_gen = export.ConvertValues(rdfvalue.ExportedMetadata(),
                                     [dummy_value])
   self.assertRaises(export.NoConverterFound, list, result_gen)