Esempio n. 1
0
    def test_no_exception_raised_when_sender_auth_succeeds_on_route(self):
        class RouteImpl(Route):
            def route(self, route=r'bcoe@.*', sender_auth=GmailSPFAuth):
                self.called = True

        route = RouteImpl()
        route._initialize(peer_ip='209.85.213.46')
        route._route(message_data=self.valid_dkim_eml)
        self.assertTrue(route.called)
Esempio n. 2
0
 def process_message(self, peer, mailfrom, rcpttos, message_data):
     for RouteClass in self.routes:
         try:
             route = RouteClass()
             route._initialize(peer_ip=peer[0])
             route._route(message_data)
         except RoutingException, re:
             self.logger.warn( re )
         except Exception, e:
             self.logger.error( e )
Esempio n. 3
0
    def test_no_exception_raised_when_sender_auth_succeeds_on_route(self):
        class RouteImpl(Route):
            def route(self, route=r'ben@.*', sender_auth=GmailSPFAuth):
                self.called = True

        route = RouteImpl()
        route._initialize(peer_ip='209.85.213.46')
        route._route(
            message_data=self.valid_dkim_eml
        )
        self.assertTrue(route.called)
Esempio n. 4
0
    def test_route_decorator_can_be_used_rather_than_kwarg_to_specify_sender_auth(
            self):
        class RouteImpl(Route):
            @route('bcoe@.*', sender_auth=GmailSPFAuth)
            def route(self):
                self.called = True

        route = RouteImpl()
        route._initialize(peer_ip='209.85.213.46')
        route._route(message_data=self.invalid_dkim_eml)
        self.assertTrue(route.called)
Esempio n. 5
0
    def test_if_list_of_sender_authentication_approaches_is_provided_route_called_if_any_pass(self):
        class RouteImpl(Route):
            def route(self, route=r'bcoe@.*', sender_auth=[DKIMAuth, GmailSPFAuth]):
                self.called = True

        route = RouteImpl()
        route._initialize(peer_ip='209.85.213.46')
        route._route(
            message_data=self.invalid_dkim_eml
        )
        self.assertTrue(route.called)
Esempio n. 6
0
    def test_route_decorator_can_be_used_rather_than_kwarg_to_specify_sender_auth(self):
        class RouteImpl(Route):
            @route('bcoe@.*', sender_auth=GmailSPFAuth)
            def route(self):
                self.called = True

        route = RouteImpl()
        route._initialize(peer_ip='209.85.213.46')
        route._route(
            message_data=self.invalid_dkim_eml
        )
        self.assertTrue(route.called)
Esempio n. 7
0
    def test_named_groups_stored_as_instance_variables_on_route(self):
        class RouteImpl(Route):
            def route(self, route=r'(?P<user>[^-]*)-(?P<folder>.*)@.*'):
                self.called = True

        message = 'To: Benjamin <*****@*****.**>\nFrom: [email protected]'
        route = RouteImpl()
        route._initialize()
        route._route(message_data=message)
        self.assertEqual(route.user, 'bencoe')
        self.assertEqual(route.folder, 'awesome-folder')
        self.assertEqual(route.called, True)
Esempio n. 8
0
    def test_named_groups_stored_as_instance_variables_on_route(self):
        class RouteImpl(Route):

            def route(self, route=r'(?P<user>[^-]*)-(?P<folder>.*)@.*'):
                self.called = True

        message =  'To: Benjamin <*****@*****.**>\nFrom: [email protected]'
        route = RouteImpl()
        route._initialize()
        route._route(message_data=message)
        self.assertEqual(route.user, 'bencoe')
        self.assertEqual(route.folder, 'awesome-folder')
        self.assertEqual(route.called, True)
Esempio n. 9
0
    def test_a_routing_exception_should_be_raised_if_the_route_is_not_found(
            self):
        class RouteImpl(Route):
            pass

        message = 'To: Benjamin <*****@*****.**>, [email protected], Eric <*****@*****.**>\nFrom: Ben Coe <*****@*****.**>'
        route = RouteImpl()
        route._initialize()
        try:
            route._route(message_data=message)
            self.assertTrue(False)
        except RoutingException, re:
            self.assertTrue('*****@*****.**' in str(re))
            self.assertTrue(True)
Esempio n. 10
0
    def test_exception_raised_when_sender_auth_fails_on_route(self):
        class RouteImpl(Route):
            def route(self, route=r'bcoe@.*', sender_auth=DKIMAuth):
                self.called = True

        route = RouteImpl()
        route._initialize()
        route.called = False
        try:
            route._route(message_data=self.invalid_dkim_eml)
            self.assertTrue(False)
        except SenderAuthException:
            self.assertTrue(True)
        self.assertFalse(route.called)
Esempio n. 11
0
    def test_a_routing_exception_should_be_raised_if_the_route_is_not_found(self):
        class RouteImpl(Route):
            pass

        message =  'To: Benjamin <*****@*****.**>, [email protected], Eric <*****@*****.**>\nFrom: Ben Coe <*****@*****.**>'
        route = RouteImpl()
        route._initialize()
        try:
            route._route(
                message_data=message
            )
            self.assertTrue(False)
        except RoutingException, re:
            self.assertTrue('*****@*****.**' in str(re))
            self.assertTrue(True)
Esempio n. 12
0
    def test_calling_route_with_a_matching_regex_results_in_the_appropriate_route_being_invoked(
            self):
        class RouteImpl(Route):
            def route1(self, route=r'*****@*****.**'):
                self.bar = 'bar'

            def route2(self, route=r'*****@*****.**'):
                self.bar = 'foo'

        message = 'To: Benjamin <*****@*****.**>, [email protected], Eric <*****@*****.**>\nFrom: Ben Coe <*****@*****.**>'

        route = RouteImpl()
        route._initialize()
        route._route(message_data=message)
        self.assertEqual('bar', route.bar)
Esempio n. 13
0
    def test_exception_raised_when_sender_auth_fails_on_route(self):
        class RouteImpl(Route):
            def route(self, route=r'bcoe@.*', sender_auth=DKIMAuth):
                self.called = True

        route = RouteImpl()
        route._initialize()
        route.called = False
        try:
            route._route(
                message_data=self.invalid_dkim_eml
            )
            self.assertTrue(False)
        except SenderAuthException:
            self.assertTrue(True)
        self.assertFalse(route.called)
Esempio n. 14
0
    def test_instance_variables_populated_based_on_email_message(self):
        class RouteImpl(Route):
            def route(self, route=r'*****@*****.**'):
                self.called = True

        message = 'To: a <*****@*****.**>, [email protected]\nFrom: [email protected]\nCC: d <*****@*****.**>, [email protected]\nBCC: [email protected]'
        route = RouteImpl()
        route._initialize()
        route._route(message_data=message)
        self.assertTrue(route.message)
        self.assertEqual(route.tos[0].email, '*****@*****.**')
        self.assertEqual(route.tos[1].email, '*****@*****.**')
        self.assertEqual(route.mailfrom.email, '*****@*****.**')
        self.assertEqual(route.ccs[0].email, '*****@*****.**')
        self.assertEqual(route.ccs[1].email, '*****@*****.**')
        self.assertEqual(route.bccs[0].email, '*****@*****.**')
Esempio n. 15
0
    def test_instance_variables_populated_based_on_email_message(self):
        class RouteImpl(Route):

            def route(self, route=r'*****@*****.**'):
                self.called = True

        message =  'To: a <*****@*****.**>, [email protected]\nFrom: [email protected]\nCC: d <*****@*****.**>, [email protected]\nBCC: [email protected]'
        route = RouteImpl()
        route._initialize()
        route._route(message_data=message)
        self.assertTrue(route.message)
        self.assertEqual(route.tos[0].email, '*****@*****.**')
        self.assertEqual(route.tos[1].email, '*****@*****.**')
        self.assertEqual(route.mailfrom.email, '*****@*****.**')
        self.assertEqual(route.ccs[0].email, '*****@*****.**')
        self.assertEqual(route.ccs[1].email, '*****@*****.**')
        self.assertEqual(route.bccs[0].email, '*****@*****.**')
Esempio n. 16
0
    def test_if_list_of_sender_authentication_approaches_is_provided_exception_raised_if_all_fail(self):
        class RouteImpl(Route):
            def route(self, route=r'bcoe@.*', sender_auth=[DKIMAuth, GmailSPFAuth]):
                self.called = True

        route = RouteImpl()
        route._initialize()
        route.called = False

        try:
            route._route(
                message_data=self.invalid_dkim_eml
            )
            self.assertTrue(False)
        except SenderAuthException:
            self.assertTrue(True)
        self.assertFalse(route.called)
Esempio n. 17
0
    def test_calling_route_with_a_matching_regex_results_in_the_appropriate_route_being_invoked(self):

        class RouteImpl(Route):

            def route1(self, route=r'*****@*****.**'):
                self.bar = 'bar'

            def route2(self, route=r'*****@*****.**'):
                self.bar = 'foo'

        message =  'To: Benjamin <*****@*****.**>, [email protected], Eric <*****@*****.**>\nFrom: Ben Coe <*****@*****.**>'

        route = RouteImpl()
        route._initialize()
        route._route(
            message_data=message
        )
        self.assertEqual('bar', route.bar)