示例#1
0
    async def test_csvtool_cli(self):

        with self.getTestDir() as dirn:

            logpath = s_common.genpath(dirn, 'csvtest.log')

            csvpath = s_common.genpath(dirn, 'csvtest.csv')
            with s_common.genfile(csvpath) as fd:
                fd.write(csvfile)

            stormpath = s_common.genpath(dirn, 'csvtest.storm')
            with s_common.genfile(stormpath) as fd:
                fd.write(csvstorm)

            argv = [
                '--csv-header', '--debug', '--cli', '--test', '--logfile',
                logpath, stormpath, csvpath
            ]
            outp = self.getTestOutp()

            cmdg = s_t_utils.CmdGenerator([
                'storm --hide-props inet:fqdn',
                EOFError(),
            ])

            with self.withCliPromptMockExtendOutp(outp):
                with self.withTestCmdr(cmdg):
                    await s_csvtool.main(argv, outp=outp)

            outp.expect('inet:fqdn=google.com')
            outp.expect('2 nodes')
示例#2
0
    async def test_csvtool_cli(self):
        with self.getTestDir() as dirn:

            logpath = s_common.genpath(dirn, 'csvtest.log')

            csvpath = s_common.genpath(dirn, 'csvtest.csv')
            with s_common.genfile(csvpath) as fd:
                fd.write(csvfile)

            stormpath = s_common.genpath(dirn, 'csvtest.storm')
            with s_common.genfile(stormpath) as fd:
                fd.write(csvstorm)

            argv = [
                '--csv-header', '--debug', '--cli', '--test', '--logfile',
                logpath, stormpath, csvpath
            ]
            outp = self.getTestOutp()

            cmdg = s_t_utils.CmdGenerator(['storm --hide-props inet:fqdn'],
                                          on_end=EOFError)
            with mock.patch('synapse.lib.cli.get_input', cmdg):
                await s_coro.executor(s_csvtool.main, argv, outp=outp)

            outp.expect('inet:fqdn=google.com')
            outp.expect('2 nodes (9 created)')
示例#3
0
    async def test_syningest_remote(self):

        async with self.getTestCore() as core:

            guid = s_common.guid()
            seen = s_common.now()
            gestdef = self.getIngestDef(guid, seen)

            with self.getTestDir() as dirn:

                # Test yaml support here
                gestfp = s_common.genpath(dirn, 'gest.yaml')
                s_common.yamlsave(gestdef, gestfp)
                argv = ['--cortex', core.getLocalUrl(),
                        '--debug',
                        '--modules', 'synapse.tests.utils.TestModule',
                        gestfp]

                outp = self.getTestOutp()
                cmdg = s_t_utils.CmdGenerator(['storm test:pivcomp -> *', EOFError()])
                with self.withCliPromptMockExtendOutp(outp):
                    with self.withTestCmdr(cmdg):
                        self.eq(await s_feed.main(argv, outp=outp), 0)
                self.true(outp.expect('test:str=haha', throw=False))
                self.true(outp.expect('test:pivtarg=hehe', throw=False))
示例#4
0
            def testmain():

                pconf = {'user': '******', 'passwd': 'root'}
                with self.getTestProxy(dmon, 'core', **pconf) as core:
                    # Setup user permissions
                    core.addAuthRole('creator')
                    core.addAuthRule('creator', (True, ('node:add', )))
                    core.addAuthRule('creator', (True, ('prop:set', )))
                    core.addAuthRule('creator', (True, ('tag:add', )))
                    core.addUserRole('root', 'creator')

                host, port = dmon.addr
                curl = f'tcp://*****:*****@{host}:{port}/core'

                guid = s_common.guid()
                seen = s_common.now()
                gestdef = self.getIngestDef(guid, seen)

                with self.getTestDir() as dirn:

                    # Test yaml support here
                    gestfp = s_common.genpath(dirn, 'gest.yaml')
                    s_common.yamlsave(gestdef, gestfp)
                    argv = [
                        '--cortex', curl, '--debug', '--modules',
                        'synapse.tests.utils.TestModule', gestfp
                    ]

                    outp = self.getTestOutp()
                    cmdg = s_t_utils.CmdGenerator(['storm pivcomp -> *'],
                                                  on_end=EOFError)
                    with mock.patch('synapse.lib.cli.get_input', cmdg):
                        self.eq(s_feed.main(argv, outp=outp), 0)
                    self.true(outp.expect('teststr=haha', throw=False))
                    self.true(outp.expect('pivtarg=hehe', throw=False))
示例#5
0
 async def test_cli_cmd_loop_eof(self):
     outp = self.getTestOutp()
     cmdg = s_t_utils.CmdGenerator(['help', EOFError()])
     async with await s_cli.Cli.anit(None, outp) as cli:
         cli.prompt = cmdg
         await cli.runCmdLoop()
         self.eq(cli.isfini, True)
     self.false(outp.expect('o/', throw=False))
示例#6
0
 async def test_cli_cmd_loop_bad_input(self):
     outp = self.getTestOutp()
     cmdg = s_t_utils.CmdGenerator([1234, EOFError()])
     async with await s_cli.Cli.anit(None, outp) as cli:
         cli.prompt = cmdg
         await cli.runCmdLoop()
         self.eq(cli.isfini, True)
     self.true(outp.expect("AttributeError: 'int' object has no attribute 'strip'", throw=False))
示例#7
0
 def test_cli_cmd_loop_eof(self):
     outp = self.getTestOutp()
     cmdg = s_t_utils.CmdGenerator(['help'], on_end=EOFError)
     with mock.patch('synapse.lib.cli.get_input', cmdg):
         with s_cli.Cli(None, outp) as cli:
             cli.runCmdLoop()
             self.eq(cli.isfini, True)
     self.false(outp.expect('o/', throw=False))
示例#8
0
    def test_cli_cmd_loop_quit(self):
        outp = self.getTestOutp()
        cmdg = s_t_utils.CmdGenerator(['help', 'quit'])

        with mock.patch('synapse.lib.cli.get_input', cmdg):
            with s_cli.Cli(None, outp) as cli:
                cli.runCmdLoop()
                self.eq(cli.isfini, True)
        self.true(outp.expect('o/'))
示例#9
0
    async def test_cli_cmd_loop_quit(self):
        outp = self.getTestOutp()
        cmdg = s_t_utils.CmdGenerator(['help', 'quit'])

        async with await s_cli.Cli.anit(None, outp) as cli:
            cli.prompt = cmdg
            await cli.runCmdLoop()
            self.eq(cli.isfini, True)

        self.true(outp.expect('o/'))
示例#10
0
    async def test_cmdg_end_exception(self):
        cmdg = s_t_utils.CmdGenerator(['foo', 'bar', EOFError()])
        self.eq(await cmdg(), 'foo')
        self.eq(await cmdg(), 'bar')

        with self.raises(EOFError):
            await cmdg()

        with self.raises(Exception) as cm:
            await cmdg()
            self.assertIn('No further actions', str(cm.exception))
示例#11
0
 def test_cli_cmd_loop_bad_input(self):
     outp = self.getTestOutp()
     cmdg = s_t_utils.CmdGenerator([1234], on_end=EOFError)
     with mock.patch('synapse.lib.cli.get_input', cmdg):
         with s_cli.Cli(None, outp) as cli:
             cli.runCmdLoop()
             self.eq(cli.isfini, True)
     self.true(
         outp.expect(
             "AttributeError: 'int' object has no attribute 'strip'",
             throw=False))
示例#12
0
 def test_cli_cmd_loop(self):
     outp = self.getTestOutp()
     cmdg = s_t_utils.CmdGenerator(
         ['help', 'locs', '', '    ', 'throwzero', 'throwkeyboard', 'quit'])
     with mock.patch('synapse.lib.cli.get_input', cmdg):
         with s_cli.Cli(None, outp) as cli:
             cli.addCmdClass(TstThrowCmd)
             cli.addCmdClass(TstThrowKeyboard)
             cli.runCmdLoop()
             self.true(outp.expect('o/'))
             self.true(outp.expect('{}'))
             self.true(outp.expect('ZeroDivisionError'))
             self.true(outp.expect('Cmd cancelled'))
             self.true(cli.isfini)
示例#13
0
    def test_cli_cmd_loop_keyint(self):
        outp = self.getTestOutp()
        cmdg = s_t_utils.CmdGenerator(['help'], on_end=KeyboardInterrupt)

        data = {'count': 0}

        def _onGetInput(mesg):
            data['count'] = data['count'] + 1
            if data['count'] > 2:
                cmdg.addCmd('quit')

        with mock.patch('synapse.lib.cli.get_input', cmdg):
            with s_cli.Cli(None, outp) as cli:
                cli.on('cli:getinput', _onGetInput)
                cli.runCmdLoop()
                self.eq(cli.isfini, True)

        self.true(outp.expect('<ctrl-c>'))
示例#14
0
    async def test_cli_cmd_loop(self):

        outp = self.getTestOutp()
        cmdg = s_t_utils.CmdGenerator(['help', 'locs', '', '    ', 'throwzero', 'throwkeyboard', 'quit'])

        async with await s_cli.Cli.anit(None, outp) as cli:

            cli.prompt = cmdg

            cli.addCmdClass(TstThrowCmd)
            cli.addCmdClass(TstThrowKeyboard)

            await cli.runCmdLoop()

            self.true(outp.expect('o/'))
            self.true(outp.expect('"syn:local:version"'))
            self.true(outp.expect(f'"{s_version.verstring}"'))
            self.true(outp.expect('ZeroDivisionError'))
            self.true(outp.expect('Cmd cancelled'))
            self.true(cli.isfini)
示例#15
0
    def test_syningest_local(self):

        with self.getTestDir() as dirn:

            guid = s_common.guid()
            seen = s_common.now()
            gestdef = self.getIngestDef(guid, seen)
            gestfp = s_common.genpath(dirn, 'gest.json')
            s_common.jssave(gestdef, gestfp)
            argv = [
                '--test', '--debug', '--modules',
                'synapse.tests.utils.TestModule', gestfp
            ]

            outp = self.getTestOutp()
            cmdg = s_t_utils.CmdGenerator(['storm pivcomp -> *'],
                                          on_end=EOFError)
            with mock.patch('synapse.lib.cli.get_input', cmdg):
                self.eq(s_feed.main(argv, outp=outp), 0)
            self.true(outp.expect('teststr=haha', throw=False))
            self.true(outp.expect('pivtarg=hehe', throw=False))
示例#16
0
 async def test_cmdg_simple_sequence(self):
     cmdg = s_t_utils.CmdGenerator(['foo', 'bar'])
     self.eq(await cmdg(), 'foo')
     self.eq(await cmdg(), 'bar')
     with self.raises(Exception):
         await cmdg()