Esempio n. 1
0
 def _get_possible_vals():
     with standard_config_patch:
         random_event_config = RandomEvent().config
     config_fqdn_vals = 'possible_domains'
     config_url_vals = 'possible_url'
     possible_fqdns = random_event_config.get(config_fqdn_vals)
     possible_urls = random_event_config.get(config_url_vals)
     for fqdn in possible_fqdns:
         yield param(val=fqdn, possible_vals=possible_fqdns).label('fqdn')
     for url in possible_urls:
         yield param(val=url, possible_vals=possible_urls).label('url')
Esempio n. 2
0
 def test_subs(self, val, possible_vals, label):
     """Test fqdn.sub and url.sub params."""
     sub = self._get_sub(val)
     # set category to 'flow', to prevent randomly choosing one of
     # the 'dip' categories
     params = {'category': 'flow', '{}.sub'.format(label): [sub]}
     with standard_config_patch:
         random_event = RandomEvent(params=params).event
     event_attr = random_event.get(label)
     self.assertIn(event_attr, possible_vals)
Esempio n. 3
0
 def test_method(params):
     output_params.update(params)
     with standard_config_patch:
         random_event = RandomEvent(params=output_params).event
     self.assertIn('address', random_event)
     address_attr = random_event.get('address')
     self.assertIsInstance(address_attr, MutableSequence)
     for address in address_attr:
         assert_method('asn', address)
         assert_method('cc', address)
Esempio n. 4
0
 def test_inside_zone(self):
     """Access zone: 'inside' - 'client' attribute: client_id."""
     clients = [self._CLIENT_ID, None]
     for client in clients:
         with standard_config_patch:
             random_event = RandomEvent(access_zone='inside',
                                        client_id=client).event
         self.assertIn('client', random_event)
         client_attr = random_event.get('client')
         self.assertIsInstance(client_attr, MutableSequence)
         self.assertEqual(len(client_attr), 1)
         self.assertEqual(client_attr[0], client)
Esempio n. 5
0
 def test_client_from_params(self, access_zone):
     """Test different access zones with 'client' in params."""
     params = {'client': ['test_client1', 'test_client2']}
     with standard_config_patch:
         random_event = RandomEvent(params=params,
                                    access_zone=access_zone,
                                    client_id=self._CLIENT_ID).event
     self.assertIn('client', random_event)
     client_attr = random_event.get('client')
     if access_zone == 'inside':
         self.assertEqual(client_attr[0], self._CLIENT_ID)
     else:
         # access zone is other than 'inside' - get 'client' from
         # params
         for client in client_attr:
             self.assertIn(client, params['client'])
Esempio n. 6
0
    def test_opt_primary(self):
        """
        Check the behavior if opt.primary is True.

        Some attributes, like 'url' and 'fqdn' and elements of
        the 'address' attribute ('asn', 'cc') should not be present
        in case of opt.primary param.
        """
        params = self._STANDARD_PARAMS
        with standard_config_patch:
            random_event = RandomEvent(params=params).event
        for attr in self._OPT_PRIMARY_DEPENDANT_ATTRS:
            self.assertNotIn(attr, random_event)
        address_attr = random_event.get('address')
        for address in address_attr:
            for element in self._OPT_PRIMARY_ADDRESS_DEPENDANT_ELEMENTS:
                self.assertNotIn(element, address)