コード例 #1
0
                "disable_logging": False,
            },
            options_only={
                "logger_path": logger_path,
                "logger_mode": test_mode,
                "verbose": True,
            })
        info_path = os.path.join(logger_path, "osqueryd.INFO")
        self.assertTrue(daemon.isAlive())

        def info_exists():
            return os.path.exists(info_path)

        # Wait for the daemon to flush to GLOG.
        test_base.expectTrue(info_exists)

        # Both log files should exist and have the given mode.
        for fname in ['osqueryd.INFO', 'osqueryd.results.log']:
            pth = os.path.join(logger_path, fname)
            self.assertTrue(os.path.exists(pth))

            rpath = os.path.realpath(info_path)
            mode = os.stat(rpath).st_mode & 0777
            self.assertEqual(mode, test_mode)

        daemon.kill()


if __name__ == '__main__':
    test_base.Tester().run()
コード例 #2
0
        client = test_base.EXClient(daemon.options["extensions_socket"])
        test_base.expectTrue(client.try_open)
        self.assertTrue(client.open())
        em = client.getEM()

        # Every query from the pack(s) is added to the packs table.
        def get_packs():
            result = em.query("select * from osquery_packs")
            return len(result.response) == 2

        # Allow the daemon some lag to parse the pack content.
        test_base.expectTrue(get_packs)
        result = em.query("select * from osquery_packs")
        self.assertEqual(len(result.response), 2)

        # Only the applicable queries are added to the schedule.
        # There will be len(pack_queries) - 1 since "simple_test2" is bound
        # to an unknown/non-existing platform.
        result = em.query("select * from osquery_schedule")
        self.assertEqual(len(result.response), 1)
        daemon.kill()


if __name__ == '__main__':
    module = test_base.Tester()

    # Find and import the thrift-generated python interface
    test_base.loadThriftFromBuild(test_base.ARGS.build)

    module.run()
コード例 #3
0
    def test_3_module_prevent_create(self):
        '''Test a failed module create (we interrupt the static construction).
        This test uses a special environment variable checked in the example
        module built as part of the default SDK build.
        '''
        self.osqueryi = test_base.OsqueryWrapper(self.binary,
                                                 {"modules_autoload": self.modules_loader.path}, {"TESTFAIL1": "1"})
        result = self.osqueryi.run_query(
            'SELECT * from time;')
        # Make sure the environment variable did not introduce any unexpected
        # crashes with the unit or integration tests.
        self.assertEqual(len(result), 1)
        # The environment variable should have prevented the module load.
        self.assertRaises(test_base.OsqueryException,
                          self.osqueryi.run_query, 'SELECT * from example;')

    def test_4_module_prevent_initialize(self):
        '''Test a failed module initialize (we interrupt the registry call).
        '''
        self.osqueryi = test_base.OsqueryWrapper(self.binary,
                                                 {"modules_autoload": self.modules_loader.path}, {"TESTFAIL2": "1"})
        # The environment variable should have prevented the module load.
        self.assertRaises(test_base.OsqueryException,
                          self.osqueryi.run_query, 'SELECT * from example;')


if __name__ == "__main__":
    test_base.assertPermissions()
    module = test_base.Tester().run()