示例#1
0
    def testRendersSampleCollectionWithTotalCountParameter(self):
        data = self.renderer.RenderObject(
            self.fd,
            rdfvalue.ApiRDFValueCollectionRendererArgs(count=2,
                                                       with_total_count=True))

        self.assertEqual(len(data["items"]), 2)
        self.assertEqual(data["total_count"], 10)
示例#2
0
  def Render(self, args, token=None):
    errors_collection = aff4.FACTORY.Create(
        HUNTS_ROOT_PATH.Add(args.hunt_id).Add("errors"),
        aff4_type="RDFValueCollection", mode="r", token=token)

    return api_aff4_object_renderers.RenderAFF4Object(
        errors_collection,
        [rdfvalue.ApiRDFValueCollectionRendererArgs(
            offset=args.offset, count=args.count, with_total_count=True,
            items_type_info="WITH_TYPES_AND_METADATA")])
示例#3
0
    def testRendersSampleCollectionWithFilter(self):
        data = self.renderer.RenderObject(
            self.fd,
            rdfvalue.ApiRDFValueCollectionRendererArgs(filter="/var/os/tmp-9"))

        self.assertEqual(len(data["items"]), 1)
        self.assertEqual(data["items"][0], {
            "path": "/var/os/tmp-9",
            "pathtype": "OS"
        })
示例#4
0
    def testRendersSampleCollection(self):
        data = self.renderer.RenderObject(
            self.fd, rdfvalue.ApiRDFValueCollectionRendererArgs())

        self.assertEqual(data["offset"], 0)
        self.assertEqual(data["count"], 10)

        self.assertEqual(len(data["items"]), 10)
        for i in range(10):
            self.assertEqual(data["items"][i], {
                "path": "/var/os/tmp-%d" % i,
                "pathtype": "OS"
            })
示例#5
0
    def testRendersSampleCollectionWithFilterAndOffsetAndCount(self):
        data = self.renderer.RenderObject(
            self.fd,
            rdfvalue.ApiRDFValueCollectionRendererArgs(offset=2,
                                                       count=2,
                                                       filter="/var/os/tmp"))

        self.assertEqual(len(data["items"]), 2)
        self.assertEqual(data["items"][0], {
            "path": "/var/os/tmp-2",
            "pathtype": "OS"
        })
        self.assertEqual(data["items"][1], {
            "path": "/var/os/tmp-3",
            "pathtype": "OS"
        })
示例#6
0
    def testRendersSampleCollectionWithOffsetParameter(self):
        data = self.renderer.RenderObject(
            self.fd, rdfvalue.ApiRDFValueCollectionRendererArgs(offset=8))

        self.assertEqual(data["offset"], 8)
        self.assertEqual(data["count"], 2)

        self.assertEqual(len(data["items"]), 2)
        self.assertEqual(data["items"][0], {
            "path": "/var/os/tmp-8",
            "pathtype": "OS"
        })
        self.assertEqual(data["items"][1], {
            "path": "/var/os/tmp-9",
            "pathtype": "OS"
        })
示例#7
0
    def Render(self, args, token=None):
        # TODO(user): handle cases when hunt doesn't exists.
        # TODO(user): Use hunt's logs_collection_urn to open errors collection.
        errors_collection = aff4.FACTORY.Create(HUNTS_ROOT_PATH.Add(
            args.hunt_id).Add("ErrorClients"),
                                                aff4_type="RDFValueCollection",
                                                mode="r",
                                                token=token)

        return api_aff4_object_renderers.RenderAFF4Object(
            errors_collection, [
                rdfvalue.ApiRDFValueCollectionRendererArgs(
                    offset=args.offset,
                    count=args.count,
                    with_total_count=True,
                    items_type_info="WITH_TYPES_AND_METADATA")
            ])
    def testAdditionalArgumentsAreParsedCorrectly(self):
        additional_args = api_call_renderers.FillAdditionalArgsFromRequest(
            {
                "AFF4Object.limit_lists": "10",
                "RDFValueCollection.with_total_count": "1"
            }, {
                "AFF4Object": rdfvalue.ApiAFF4ObjectRendererArgs,
                "RDFValueCollection":
                rdfvalue.ApiRDFValueCollectionRendererArgs
            })
        additional_args = sorted(additional_args, key=lambda x: x.name)

        self.assertListEqual([x.name for x in additional_args],
                             ["AFF4Object", "RDFValueCollection"])
        self.assertListEqual(
            [x.type for x in additional_args],
            ["ApiAFF4ObjectRendererArgs", "ApiRDFValueCollectionRendererArgs"])
        self.assertListEqual([x.args for x in additional_args], [
            rdfvalue.ApiAFF4ObjectRendererArgs(limit_lists=10),
            rdfvalue.ApiRDFValueCollectionRendererArgs(with_total_count=True)
        ])