예제 #1
0
    def test_hypnos_automatic_ingest(self):
        # Ensure that a configuration object with a ingest definition is automatically parsed.
        self.thisHostMustNot(platform='windows')
        self.skipIfNoInternet()
        gconf = get_fake_ipify_ingest_global_config(port=self.port)
        # testserver = Foo()
        with s_remcycle.Hypnos(opts={s_remcycle.MIN_WORKER_THREADS: 1},
                               ioloop=self.io_loop) as hypo_obj:
            hypo_obj.addWebConfig(config=gconf)

            self.true('fakeipify:jsonip' in hypo_obj._syn_funcs)
            self.true('fakeipify:jsonip:ipv4' in hypo_obj.web_core._syn_funcs)

            data = {}

            def ondone(job_tufo):
                _jid, jobd = job_tufo
                _data = jobd.get('task')[2].get('resp', {}).get('data')
                _bytez = _data.read()
                _d = json.loads(_bytez.decode())
                data[_jid] = _d.get('ret').get('ip')

            jid = hypo_obj.fireWebApi(name='fakeipify:jsonip', ondone=ondone)
            hypo_obj.web_boss.wait(jid)

            tufos = hypo_obj.web_core.getTufosByProp('inet:ipv4')
            self.eq(len(tufos), 1)
            # Validate the IP of the tufo is the same we got from ipify
            self.nn(data[jid])
            self.eq(s_inet.ipv4str(tufos[0][1].get('inet:ipv4')), data[jid])
예제 #2
0
    def test_hypnos_with_telepath(self):
        # Setup the Hypnos object using telepath, then get the proxy object and
        # issue the fireWebApi calls via telepath, validate that they worked
        # against ingested tufo in the hypnos cortex. Use daemon to handle
        # telepath proxying.
        self.thisHostMustNot(platform='windows')
        gconf = get_fake_ipify_ingest_global_config(port=self.port)
        dconf = {
            'vars': {
                'hopts': {
                    s_remcycle.MIN_WORKER_THREADS: 1,
                },
                'hioloop': self.io_loop,
                'cortex_url': 'ram://'
            },
            'ctors': [
                [
                    'core',
                    'ctor://synapse.cortex.openurl(cortex_url)'
                ],
                [
                    'hypnos',
                    'ctor://synapse.lib.remcycle.Hypnos(core=core, ioloop=hioloop,opts=hopts)'
                ]
            ],
            'share': [
                [
                    'hypnos',
                    {}
                ],
                [
                    'core',
                    {}
                ]
            ],
            'listen': [
                'tcp://127.0.0.1:50001'
            ]
        }

        dmon = s_daemon.Daemon()
        dmon.loadDmonConf(dconf)

        hypnos_proxy = s_telepath.openurl('tcp://127.0.0.1:50001/hypnos')
        core_proxy = s_telepath.openurl('tcp://127.0.0.1:50001/core')
        # Lets do a remote config load!
        hypnos_proxy.addWebConfig(config=gconf)

        description = hypnos_proxy.getWebDescription()
        self.true('fakeipify' in description)
        # Fire the web api
        jid = hypnos_proxy.fireWebApi(name='fakeipify:jsonip')
        self.nn(jid)
        hypnos_proxy.webJobWait(jid)
        tufos = core_proxy.getTufosByProp('inet:ipv4')
        self.eq(len(tufos), 1)
        ip = s_inet.ipv4str(tufos[0][1].get('inet:ipv4'))
        self.true(len(ip) >= 7)
예제 #3
0
    def test_hypnos_manual_ingest_via_eventbus(self):
        # This is a manual setup of the core / ingest type of action.
        self.thisHostMustNot(platform='windows')
        self.skipIfNoInternet()

        core = s_cortex.openurl('ram://')

        gconf = get_fake_ipify_global_config(port=self.port)
        # testserver = Foo()
        with s_remcycle.Hypnos(opts={s_remcycle.MIN_WORKER_THREADS: 1},
                               ioloop=self.io_loop) as hypo_obj:
            hypo_obj.addWebConfig(config=gconf)

            data = {}

            ingest_def = {
                "ingest": {
                    "forms": [["inet:ipv4", {
                        "var": "ip"
                    }]],
                    "vars": [["ip", {
                        "path": "ret/ip"
                    }]]
                }
            }

            name = 'fakeipify:jsonip'
            core_name = ':'.join([name, 'ingest'])

            gest = s_ingest.Ingest(info=ingest_def)

            s_ingest.register_ingest(core=core, gest=gest, evtname=core_name)

            def glue(event):
                evtname, event_args = event
                kwargs = event_args.get('kwargs')
                resp = kwargs.get('resp')
                data = resp.get('data')
                core.fire(core_name, data=data)

            def ondone(job_tufo):
                _jid, jobd = job_tufo
                _data = jobd.get('task')[2].get('resp', {}).get('data', {})
                ip = _data.get('ret', {}).get('ip', '')
                data[_jid] = ip

            hypo_obj.on(name=name, func=glue)

            jid = hypo_obj.fireWebApi(name=name, ondone=ondone)
            hypo_obj.web_boss.wait(jid)

            tufos = core.getTufosByProp('inet:ipv4')
            self.eq(len(tufos), 1)
            # Validate the IP of the tufo is the same we got from ipify
            self.eq(s_inet.ipv4str(tufos[0][1].get('inet:ipv4')), data[jid])

        core.fini()