Ejemplo n.º 1
0
 def testPrecedence(self):
     query = "5 == 1 * 5 and Process/name is 'init'"
     expected = expression.Intersection(
         expression.Equivalence(
             expression.Literal(5),
             expression.Product(expression.Literal(1),
                                expression.Literal(5))),
         expression.Equivalence(expression.Binding("Process/name"),
                                expression.Literal("init")))
     self.assertQueryMatches(query, expected)
Ejemplo n.º 2
0
    def testLists(self):
        query = "'foo' in ('foo', 'bar') and 1 not in (5, 2, 3,17)"
        expected = expression.Intersection(
            expression.Membership(expression.Literal("foo"),
                                  expression.Literal(("foo", "bar"))),
            expression.Complement(
                expression.Membership(expression.Literal(1),
                                      expression.Literal((5, 2, 3, 17)))))

        self.assertQueryMatches(query, expected)
Ejemplo n.º 3
0
    def testLetSubexpr(self):
        query = ("Process/parent matches (Process/command is 'init' and "
                 "Process/pid is 1)")
        expected = expression.Let(
            expression.Binding("Process/parent"),
            expression.Intersection(
                expression.Equivalence(expression.Binding("Process/command"),
                                       expression.Literal("init")),
                expression.Equivalence(expression.Binding("Process/pid"),
                                       expression.Literal(1))))

        self.assertQueryMatches(query, expected)
Ejemplo n.º 4
0
    def render(self, renderer):
        renderer.table_header([("User", "user", "15"),
                               ("Session", "session", "15"),
                               ("Terminal vnode", "vnode", "30"),
                               ("Recovered input", "input", "75"),
                               ("Recovered output", "output", "75")])

        for terminal in self.session.entities.find("has component Terminal"):

            buffer_in = self.session.entities.find_first(
                expression.Intersection(
                    expression.Equivalence(
                        expression.Binding("Buffer/purpose"),
                        expression.Literal("terminal_input")),
                    expression.Equivalence(
                        expression.Binding("Buffer/context"),
                        expression.Literal(terminal.identity))))

            buffer_out = self.session.entities.find_first(
                expression.Intersection(
                    expression.Equivalence(
                        expression.Binding("Buffer/purpose"),
                        expression.Literal("terminal_output")),
                    expression.Equivalence(
                        expression.Binding("Buffer/context"),
                        expression.Literal(terminal.identity))))

            renderer.table_row(
                terminal["Terminal/session"]["Session/user"]["User/username"],
                terminal["Terminal/session"]["Session/sid"],
                terminal.get("Terminal/file", complete=True)["File/path"],
                repr(
                    self.SHORTENER.sub("<whitespace>",
                                       buffer_in["Buffer/contents"])),
                repr(
                    self.SHORTENER.sub("<whitespace>",
                                       buffer_out["Buffer/contents"])))
Ejemplo n.º 5
0
    def testBigQuery(self):
        query = ("(Process/pid is 1 and Process/command in ('init', 'initd')) "
                 "or any Process/children matches (Process/command not in "
                 "('launchd', 'foo'))")
        expected = expression.Union(
            expression.Intersection(
                expression.Equivalence(expression.Binding("Process/pid"),
                                       expression.Literal(1)),
                expression.Membership(expression.Binding("Process/command"),
                                      expression.Literal(("init", "initd")))),
            expression.LetAny(
                expression.Binding("Process/children"),
                expression.Complement(
                    expression.Membership(
                        expression.Binding("Process/command"),
                        expression.Literal(("launchd", "foo"))))))

        self.assertQueryMatches(query, expected)
Ejemplo n.º 6
0
    def as_query(self):
        """A query that'll match entities with this identity."""
        union = []
        for _, keys, vals in self.indices:
            if isinstance(keys, tuple):
                intersection = []
                for idx, key in enumerate(keys):
                    intersection.append(
                        expression.Equivalence(expression.Binding(key),
                                               expression.Literal(vals[idx])))

                union.append(expression.Intersection(*intersection))
            else:
                union.append(
                    expression.Equivalence(expression.Binding(keys),
                                           expression.Literal(vals)))

        if len(union) == 1:
            return union[0]

        return expression.Union(*union)