Beispiel #1
0
    def _test_cache_action_spoofing(self, models):

        self.assertIsNotNone(self._cache)
        self._cache.clear()

        policy = self._get_policy(blacklist_enable=False,
                                  domain_vrfy=True,
                                  mynetwork_vrfy=True,
                                  spoofing_enable=True,
                                  greylist_enable=False)

        protocol = {
            'instance': '123',
            'client_address': '2.2.2.2',
            'client_name': 'unknow',
            'sender': '*****@*****.**',
            'recipient': '*****@*****.**',
        }
        
        models.Domain(name="example.net").save()
        actions = policy.check_actions(protocol)
        self.assertEquals(actions[0], "554 5.7.1 spoofing [[email protected]] - %s#554" % constants.ERRORS_URL_BASE)
        
        self._drop_model(models.Domain)
        
        uid = utils.get_uid(protocol)
        cache_value = self._cache.get(uid)
        self.assertIsNotNone(cache_value)
        self.assertTrue(cache_value['is_spoofing'])
        self.assertEquals(cache_value['action'], "554 5.7.1 spoofing [[email protected]] - %s#554" % constants.ERRORS_URL_BASE)
Beispiel #2
0
    def _test_cache_action_whitelisted(self, models):
        
        self.assertIsNotNone(self._cache)
        self._cache.clear()
        
        protocol = {
            'instance': '123',
            'client_address': '2.2.2.2',
            'client_name': 'unknow',
            'sender': '*****@*****.**',
            'recipient': '*****@*****.**',
            'country': 'fr',
            'helo_name': "mx1.example.net",
        }

        policy = self._get_policy()
        
        models.WhiteList(field_name='client_address', value='2.2.2.2').save()
        actions = policy.check_actions(protocol)
        self.assertEquals(actions[0], "DUNNO whitelisted [2.2.2.2]")

        self._drop_model(models.WhiteList)
        
        uid = utils.get_uid(protocol)
        cache_value = self._cache.get(uid)
        self.assertIsNotNone(cache_value)
        self.assertTrue(cache_value['is_whitelist'])
        self.assertEquals(cache_value['action'], "DUNNO whitelisted [2.2.2.2]")
Beispiel #3
0
    def _test_cache_action_outgoing(self, models):

        self.assertIsNotNone(self._cache)
        self._cache.clear()

        policy = self._get_policy(blacklist_enable=False,
                                  domain_vrfy=True,
                                  mynetwork_vrfy=True,
                                  spoofing_enable=False,
                                  greylist_enable=False)

        protocol = {
            'instance': '123',
            'client_address': '1.1.1.1',
            'client_name': 'unknow',
            'sender': '*****@*****.**',
            'recipient': '*****@*****.**',
        }
        
        models.Mynetwork(value="1.1.1.1").save()
        actions = policy.check_actions(protocol)
        self.assertEquals(actions[0], "DUNNO outgoing bypass")

        self._drop_model(models.Mynetwork)
        
        uid = utils.get_uid(protocol)
        cache_value = self._cache.get(uid)
        self.assertIsNotNone(cache_value)
        self.assertTrue(cache_value['is_outgoing'])
        self.assertEquals(cache_value['action'], "DUNNO outgoing bypass")
Beispiel #4
0
    def _test_cache_action_blacklisted(self, models):
        
        self.assertIsNotNone(self._cache)
        self._cache.clear()
        
        protocol = {
            'instance': '123',
            'client_address': '1.1.1.1',
            'client_name': 'unknow',
            'sender': '*****@*****.**',
            'recipient': '*****@*****.**',
            'country': 'fr',
            'helo_name': "mx1.example.net",
        }

        policy = self._get_policy(blacklist_enable=True)
        
        models.BlackList(field_name='client_address', value='1.1.1.1').save()
        actions = policy.check_actions(protocol)
        self.assertEquals(actions[0], "554 5.7.1 blacklisted [1.1.1.1] - %s#554" % constants.ERRORS_URL_BASE)
        
        uid = utils.get_uid(protocol)
        cache_value = self._cache.get(uid)
        self.assertIsNotNone(cache_value)
        self.assertTrue(cache_value['is_blacklist'])
        self.assertEquals(cache_value['action'], "554 5.7.1 blacklisted [1.1.1.1] - %s#554" % constants.ERRORS_URL_BASE)
Beispiel #5
0
    def _test_cache_action_spoofing(self, models):

        self.assertIsNotNone(self._cache)
        self._cache.clear()

        policy = self._get_policy(blacklist_enable=False,
                                  domain_vrfy=True,
                                  mynetwork_vrfy=True,
                                  spoofing_enable=True,
                                  greylist_enable=False)

        protocol = {
            'instance': '123',
            'client_address': '2.2.2.2',
            'client_name': 'unknow',
            'sender': '*****@*****.**',
            'recipient': '*****@*****.**',
        }

        models.Domain(name="example.net").save()
        actions = policy.check_actions(protocol)
        self.assertEquals(
            actions[0], "554 5.7.1 spoofing [[email protected]] - %s#554" %
            constants.ERRORS_URL_BASE)

        self._drop_model(models.Domain)

        uid = utils.get_uid(protocol)
        cache_value = self._cache.get(uid)
        self.assertIsNotNone(cache_value)
        self.assertTrue(cache_value['is_spoofing'])
        self.assertEquals(
            cache_value['action'],
            "554 5.7.1 spoofing [[email protected]] - %s#554" %
            constants.ERRORS_URL_BASE)
Beispiel #6
0
    def _test_cache_action_outgoing(self, models):

        self.assertIsNotNone(self._cache)
        self._cache.clear()

        policy = self._get_policy(blacklist_enable=False,
                                  domain_vrfy=True,
                                  mynetwork_vrfy=True,
                                  spoofing_enable=False,
                                  greylist_enable=False)

        protocol = {
            'instance': '123',
            'client_address': '1.1.1.1',
            'client_name': 'unknow',
            'sender': '*****@*****.**',
            'recipient': '*****@*****.**',
        }

        models.Mynetwork(value="1.1.1.1").save()
        actions = policy.check_actions(protocol)
        self.assertEquals(actions[0], "DUNNO outgoing bypass")

        self._drop_model(models.Mynetwork)

        uid = utils.get_uid(protocol)
        cache_value = self._cache.get(uid)
        self.assertIsNotNone(cache_value)
        self.assertTrue(cache_value['is_outgoing'])
        self.assertEquals(cache_value['action'], "DUNNO outgoing bypass")
Beispiel #7
0
    def _test_cache_action_whitelisted(self, models):

        self.assertIsNotNone(self._cache)
        self._cache.clear()

        protocol = {
            'instance': '123',
            'client_address': '2.2.2.2',
            'client_name': 'unknow',
            'sender': '*****@*****.**',
            'recipient': '*****@*****.**',
            'country': 'fr',
            'helo_name': "mx1.example.net",
        }

        policy = self._get_policy()

        models.WhiteList(field_name='client_address', value='2.2.2.2').save()
        actions = policy.check_actions(protocol)
        self.assertEquals(actions[0], "DUNNO whitelisted [2.2.2.2]")

        self._drop_model(models.WhiteList)

        uid = utils.get_uid(protocol)
        cache_value = self._cache.get(uid)
        self.assertIsNotNone(cache_value)
        self.assertTrue(cache_value['is_whitelist'])
        self.assertEquals(cache_value['action'], "DUNNO whitelisted [2.2.2.2]")
Beispiel #8
0
    def _test_cache_action_blacklisted(self, models):

        self.assertIsNotNone(self._cache)
        self._cache.clear()

        protocol = {
            'instance': '123',
            'client_address': '1.1.1.1',
            'client_name': 'unknow',
            'sender': '*****@*****.**',
            'recipient': '*****@*****.**',
            'country': 'fr',
            'helo_name': "mx1.example.net",
        }

        policy = self._get_policy(blacklist_enable=True)

        models.BlackList(field_name='client_address', value='1.1.1.1').save()
        actions = policy.check_actions(protocol)
        self.assertEquals(
            actions[0], "554 5.7.1 blacklisted [1.1.1.1] - %s#554" %
            constants.ERRORS_URL_BASE)

        uid = utils.get_uid(protocol)
        cache_value = self._cache.get(uid)
        self.assertIsNotNone(cache_value)
        self.assertTrue(cache_value['is_blacklist'])
        self.assertEquals(
            cache_value['action'], "554 5.7.1 blacklisted [1.1.1.1] - %s#554" %
            constants.ERRORS_URL_BASE)