Exemple #1
0
    def testHandlerUsesKnowledgeBase(self, db: abstract_db.Database):
        token = _CreateToken(db)
        client_id = db_test_utils.InitializeClient(db)

        snapshot = rdf_objects.ClientSnapshot()
        snapshot.client_id = client_id
        snapshot.knowledge_base.users = [rdf_client.User(homedir="/home/foo")]
        db.WriteClientSnapshot(snapshot)

        handler = flow_plugin.ApiExplainGlobExpressionHandler()
        args = flow_plugin.ApiExplainGlobExpressionArgs(
            example_count=2,
            client_id=client_id,
            glob_expression="%%users.homedir%%/foo")
        results = handler.Handle(args, token=token)
        self.assertEqual(list(results.components), [
            rdf_paths.GlobComponentExplanation(
                glob_expression="%%users.homedir%%", examples=["/home/foo"]),
            rdf_paths.GlobComponentExplanation(glob_expression="/foo",
                                               examples=[]),
        ])
 def Run(self):
   client_id = self.SetupClient(0)
   self.Check(
       "ExplainGlobExpression",
       args=flow_plugin.ApiExplainGlobExpressionArgs(
           client_id=client_id, glob_expression="/foo/*"))