Ejemplo n.º 1
0
    def test_storm_query_log(self):
        with self.getRamCore() as core:
            # Setup logging to an io.StringIO object
            stream = io.StringIO()
            handler = logging.StreamHandler(stream)
            storm_logger = logging.getLogger('synapse.lib.storm')

            try:
                storm_logger.addHandler(handler)
                core.eval('#HAHA')
            finally:
                storm_logger.removeHandler(handler)

            stream.seek(0)
            mesgs = stream.read()
            self.eq('', mesgs.strip())

            core.setConfOpt('storm:query:log:en', 1)
            core.setConfOpt('storm:query:log:level', logging.WARNING)

            try:
                storm_logger.addHandler(handler)
                core.eval('#HAHA')
            finally:
                storm_logger.removeHandler(handler)

            stream.seek(0)
            mesgs = stream.read()

            e = 'Executing storm query [#HAHA] as [{}]'.format(s_auth.whoami())
            self.eq(e, mesgs.strip())
Ejemplo n.º 2
0
    def spliced(self, act, **info):
        '''
        Fire a splice event from the transaction.

        Args:
            act (str): Splice action.
            **info: Event values.

        Returns:
            None
        '''
        # Splice events only matter for StoreXacts which have a Cortex
        if not self.core:
            return

        form = info.get('form')

        pdef = self.core.getPropDef(form)
        if pdef is not None and pdef[1].get('local'):
            return

        info['act'] = act
        info['time'] = self.tick
        info['user'] = s_auth.whoami()

        self.fire('splice', **info)
Ejemplo n.º 3
0
 def ask(self, text, data=(), timeout=None):
     '''
     Run a storm query and return the query result dict.
     user= stdin=
     '''
     if self.querylog:
         user = s_auth.whoami()
         logger.log(self.queryloglevel, 'Executing storm query [%s] as [%s]', text, user)
     opers = self.parse(text)
     return self.run(opers, data=data, timeout=timeout)
Ejemplo n.º 4
0
    def _stormOperSudo(self, query, oper):

        core = self.getStormCore()
        if core.auth is None:
            return

        name = query.user
        if name is None:
            name = s_auth.whoami()

        user = core.auth.users.get(name)
        if user is None:
            raise s_exc.NoSuchUser(user=name)

        if not user.admin:
            raise s_exc.AuthDeny(mesg='sudo() user is not admin',
                                 user=name)

        query.elev = True
Ejemplo n.º 5
0
 def test_auth_runas(self):
     self.eq(s_auth.whoami(), 'root@localhost')
     with s_auth.runas('*****@*****.**'):
         self.eq(s_auth.whoami(), '*****@*****.**')
     self.eq(s_auth.whoami(), 'root@localhost')