def test_nyx_simple_config(self):
        self.thisHostMustNot(platform='windows')
        nyx = s_remcycle.Nyx(config=self.config)
        e_url = 'http://vertex.link/api/v4/geoloc/{someplace}/info?domore={domore}&apikey=8675309'
        self.eq(nyx.effective_url, e_url)
        self.eq(nyx.api_args, ['someplace'])
        self.eq(nyx.api_kwargs, {'domore': 0})

        # Ensure property is structured correctly and data from the property
        # cannot mutate the Nyx object
        desc = nyx.description()
        self.true(isinstance(desc, dict))
        self.true('doc' in desc)
        self.true('api_args' in desc)
        self.true(desc.get('api_args') == nyx.api_args)
        self.true(desc.get('api_args') is not nyx.api_args)
        self.true('api_optargs' in desc)
        self.true(desc.get('api_optargs') is not nyx.api_kwargs)
        # Overkill
        desc.get('api_optargs')['foo'] = '1'
        self.true('foo' not in nyx.api_kwargs)
        desc.get('api_optargs')['domore'] = '1'
        self.true(nyx.api_kwargs['domore'] == 0)

        with self.raises(BadConfValu) as cm:
            nyx = s_remcycle.Nyx(self.bad_config)
        self.eq(cm.exception.get('name'), 'req_body')
        self.eq(cm.exception.get('valu'), None)
        self.isin('Reserved api_arg used', cm.exception.get('mesg'))
Exemple #2
0
    def test_nyx_make_request(self):
        self.thisHostMustNot(platform='windows')
        nyx = s_remcycle.Nyx(config=self.config)
        e_url = 'http://vertex.link/api/v4/geoloc/{someplace}/info?domore={domore}&apikey=8675309'
        self.eq(nyx.effective_url, e_url)
        req = nyx.buildHttpRequest(api_args={'someplace': 'foobar'})
        e_url = 'http://vertex.link/api/v4/geoloc/foobar/info?domore=0&apikey=8675309'
        self.eq(req.url, e_url)
        self.eq(req.user_agent, self.config.get('http').get('user_agent'))

        req = nyx.buildHttpRequest(api_args={'someplace': 'duck', 'domore': 1})
        e_url = 'http://vertex.link/api/v4/geoloc/duck/info?domore=1&apikey=8675309'
        self.eq(req.url, e_url)
        self.eq(req.connect_timeout, None)  # Default value for the object itself
        self.eq(req.request_timeout, None)  # Default value for the object itself

        # Ensure that extra params don't make it through
        req = nyx.buildHttpRequest(api_args={'someplace': 'duck', 'domore': 1, 'beep': 1234})
        e_url = 'http://vertex.link/api/v4/geoloc/duck/info?domore=1&apikey=8675309'
        self.eq(req.url, e_url)

        # Ensure that values stamped in via HTTP get used
        conf = self.config.copy()
        conf['http']['request_timeout'] = 1000
        conf['http']['connect_timeout'] = 100
        nyx2 = s_remcycle.Nyx(config=conf)
        req = nyx2.buildHttpRequest(api_args={'someplace': 'duck', 'domore': 1})
        e_url = 'http://vertex.link/api/v4/geoloc/duck/info?domore=1&apikey=8675309'
        self.eq(req.url, e_url)
        self.eq(req.connect_timeout, 100)  # Default value for the object itself
        self.eq(req.request_timeout, 1000)  # Default value for the object itself
    def test_nyx_tornado_http_check(self):
        self.thisHostMustNot(platform='windows')
        nyx = s_remcycle.Nyx(config=self.config)

        good_dict = {
            'method': 'PUT',
            'user_agent': 'VertexWeb',
            'headers': {
                'X-Derry': 'FriendlyClowns',
                'CSRF-Token': '1234'
            },
            'request_timeout': 100,
            'connect_timeout': 20,
        }

        nyx.request_defaults = good_dict

        r = nyx.buildHttpRequest({'someplace': 'A house'})
        self.nn(r)

        bad_dict = {
            'method': 'PUT',
            'user-agent': 'Lynx',  # Typo / misspelling
        }

        nyx.request_defaults = bad_dict

        with self.raises(Exception) as cm:
            nyx.buildHttpRequest({'someplace': 'A house'})
        self.true('unexpected keyword argument' in str(cm.exception))
Exemple #4
0
 def test_nyx_quoted_values(self):
     self.thisHostMustNot(platform='windows')
     nyx = s_remcycle.Nyx(config=self.config)
     req = nyx.buildHttpRequest(api_args={'someplace': 'foo bar',
                                          'domore': '*****@*****.**'})
     e_url = 'http://vertex.link/api/v4/geoloc/foo+bar/info?domore=eeep%40foo.bar&apikey=8675309'
     self.eq(req.url, e_url)
Exemple #5
0
 def test_hypnos_make_body(self):
     self.thisHostMustNot(platform='windows')
     nyx = s_remcycle.Nyx(config=self.post_config)
     byts = json.dumps({'foo': 'bar', 'baz': [1, 2, 3]}).encode()
     req = nyx.buildHttpRequest(api_args={'someplace': 'Derry'})
     e_url = 'http://vertex.link/api/v4/geoloc/Derry/postendpoint'
     self.eq(req.method, 'POST')
     self.eq(req.url, e_url)
     self.eq(req.body, None)
     body_req = nyx.buildHttpRequest(api_args={'req_body': byts, 'someplace': 'Derry'})
     self.eq(body_req.url, e_url)
     self.eq(body_req.body, byts)
     # Ensure the req_body can be put onto a GET for badly shaped APIs
     put_nyx = s_remcycle.Nyx(config=self.config)
     put_req = nyx.buildHttpRequest(api_args={'someplace': 'foo bar',
                                              'domore': '*****@*****.**',
                                              'req_body': byts})
     self.eq(put_req.body, byts)