示例#1
0
    def testParse(self):
        filt = filters.ItemFilter()

        one = rdfvalue.Config(test1="1", test2=[2, 3])
        foo = rdfvalue.Config(test1="foo", test2=["bar", "baz"])
        fs = rdfvalue.Filesystem(device="/dev/sda1", mount_point="/root")
        objs = [one, foo, fs]

        results = filt.Parse(objs, "test1 is '1'")
        self.assertEqual(1, len(results))
        self.assertEqual("test1", results[0].k)
        self.assertEqual("1", results[0].v)

        results = filt.Parse(objs, "test1 is '2'")
        self.assertFalse(results)

        results = filt.Parse(objs, "test2 contains 3")
        self.assertEqual(1, len(results))
        self.assertEqual("test2", results[0].k)
        self.assertEqual([2, 3], results[0].v)

        results = filt.Parse(objs, "test1 is '1' or test1 contains 'foo'")
        self.assertEqual(2, len(results))
        self.assertEqual("test1", results[0].k)
        self.assertEqual("1", results[0].v)
        self.assertEqual("test1", results[1].k)
        self.assertEqual("foo", results[1].v)

        results = filt.Parse(objs, "mount_point is '/root'")
        self.assertEqual(1, len(results))
        self.assertEqual("mount_point", results[0].k)
        self.assertEqual("/root", results[0].v)
示例#2
0
 def Parse(self, unused_stat, file_obj, unused_knowledge_base):
     self.ParseEntries(file_obj.read())
     for entry in self.entries:
         if not entry:
             continue
         result = rdfvalue.Filesystem()
         result.device = entry[0]
         result.mount_point = entry[1]
         result.type = entry[2]
         options = KeyValueParser(term=",").ParseToOrderedDict(entry[3])
         # Keys without values get assigned [] by default. Because these keys are
         # actually true, if declared, change any [] values to True.
         for k, v in options.iteritems():
             options[k] = v or [True]
         result.options = rdfvalue.AttributedDict(**options)
         yield result
示例#3
0
    def testParse(self):
        filt = filters.ItemFilter()

        cfg = rdfvalue.Config(test1="1", test2=[2, 3])

        result = list(filt.Parse(cfg, "test1 is '1'"))
        self.assertEqual(1, len(result))
        self.assertEqual("test1", result[0].k)
        self.assertEqual("1", result[0].v)

        result = list(filt.Parse(cfg, "test1 is '2'"))
        self.assertFalse(result)

        result = list(filt.Parse(cfg, "test2 contains 3"))
        self.assertEqual(1, len(result))
        self.assertEqual("test2", result[0].k)
        self.assertEqual([2, 3], result[0].v)

        # Ensure this works on other RDF types, not just Configs.
        cfg = rdfvalue.Filesystem(device="/dev/sda1", mount_point="/root")
        result = list(filt.Parse(cfg, "mount_point is '/root'"))
        self.assertEqual(1, len(result))
        self.assertEqual("mount_point", result[0].k)
        self.assertEqual("/root", result[0].v)
示例#4
0
 def EnumerateFilesystems(self, _):
     self.response_count += 1
     return [
         rdfvalue.Filesystem(device="/dev/sda", mount_point="/mnt/data")
     ]