Exemplo n.º 1
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)
Exemplo n.º 2
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)
Exemplo n.º 3
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')
Exemplo 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)
Exemplo 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'])
Exemplo n.º 6
0
    def test_params(self, category, label):
        """
        Check if params are included in the event.

        Two cases: 1st - category in 'dip categories', 2nd case
        - category not in 'dip categories'.
        """
        params = {}
        params.update(category)
        params.update(self._STANDARD_PARAMS)
        params.update(self._SPECIAL_PARAMS)
        with standard_config_patch:
            instance = RandomEvent(params=params)
        random_event = instance.event
        for param, values in self._STANDARD_PARAMS.iteritems():
            if ((label == 'non_dip_categories' and param in ['dip', 'proto'])
                    or
                (label == 'dip_categories' and param in ['url', 'fqdn'])):
                self.assertNotIn(param, random_event)
            else:
                self.assertIn(param, random_event)
                event_attr = random_event.get(param)
                if isinstance(event_attr, MutableSequence):
                    self.assertEqual(values, event_attr)
                else:
                    self.assertIn(param, random_event)
                    event_attr = random_event.get(param)
                    if isinstance(event_attr, MutableSequence):
                        self.assertEqual(values, event_attr)
                    else:
                        self.assertIn(random_event.get(param), values)
            self._check_time_attribute(random_event.get('time'))
            if 'modified' in random_event:
                self._compare_modified_attribute(random_event.get('time'),
                                                 random_event.get('modified'))
Exemplo n.º 7
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)
Exemplo n.º 8
0
 def _generate_result_dicts(self,
                            params,
                            data_spec,
                            access_zone_conditions,
                            res_limits,
                            item_number_limit,
                            access_zone,
                            client_id=None):
     opt_limit = 0
     opt_limit_vals = params.get('opt.limit')
     if opt_limit_vals:
         opt_limit = opt_limit_vals[0]
     if 0 < opt_limit < self.max_num_of_events:
         num_of_events = opt_limit
     elif 0 < item_number_limit < self.max_num_of_events:
         num_of_events = item_number_limit
     else:
         num_of_events = self.max_num_of_events
     return RandomEvent.generate_multiple_event_data(
         num_of_events,
         settings=self.settings,
         access_zone=access_zone,
         client_id=client_id,
         params=params)
Exemplo n.º 9
0
 def setUp(self, mocked_config):
     event_instance = RandomEvent()
     self.event = event_instance.event
     config = event_instance.config
     self.required_attrs = config['required_attributes']
Exemplo n.º 10
0
 def test_generate_multiple_event_data(self, num):
     """Test RandomEvent.generate_multiple_event_data() method."""
     with standard_config_patch:
         events = list(RandomEvent.generate_multiple_event_data(num))
     self.assertEqual(len(events), num)