Example #1
0
    def test_tenant_dkim_settings(self, smtp):
        """ test setup where tenant config differs from global settings """

        with mock.patch("bluebottle.utils.email_backend.properties",
                        new=mock.Mock([])) as properties:
            properties.MAIL_CONFIG = {'HOST': 'tenanthost', 'PORT': 4242}

            properties.DKIM_SELECTOR = "key2"
            properties.DKIM_DOMAIN = "testserver"
            properties.DKIM_PRIVATE_KEY = DKIM_PRIVATE_KEY

            be = TenantAwareBackend()
            msg = EmailMultiAlternatives(subject="test", body="test",
                                         to=["*****@*****.**"])

            be.open()
            connection = be.connection
            be.send_messages([msg])

            to_bytes = lambda s: force_bytes(s, 'utf-8')

            def _plain_key(s):
                return b"".join([l for l in s.split(b'\n') if not l.startswith(b'---')])

            signed_msg = connection.sendmail.call_args[0][2]
            dkim_message = dkim.DKIM(message=to_bytes(signed_msg))
            dkim_check = dkim_message.verify(dnsfunc=lambda name: b"".join([b"v=DKIM1; p=", _plain_key(DKIM_PUBLIC_KEY)]))

            self.assertTrue(signed_msg.find("d=testserver") >= 0)
            self.assertTrue(signed_msg.find("s=key2") >= 0)
            self.assertTrue(dkim_check, "Email should be signed by tenant")
Example #2
0
    def test_tenant_dkim_settings(self, smtp):
        """ test setup where tenant config differs from global settings """

        with mock.patch("bluebottle.utils.email_backend.properties",
                        new=mock.Mock([])) as properties:
            properties.MAIL_CONFIG = {'HOST': 'tenanthost', 'PORT': 4242}

            properties.DKIM_SELECTOR = "key2"
            properties.DKIM_DOMAIN = "testserver"
            properties.DKIM_PRIVATE_KEY = DKIM_PRIVATE_KEY

            be = TenantAwareBackend()
            msg = EmailMultiAlternatives(subject="test",
                                         body="test",
                                         to=["*****@*****.**"])

            be.open()
            connection = be.connection
            be.send_messages([msg])

            to_bytes = lambda s: force_bytes(s, 'utf-8')

            def _plain_key(s):
                return b"".join(
                    [l for l in s.split(b'\n') if not l.startswith(b'---')])

            signed_msg = connection.sendmail.call_args[0][2]
            dkim_message = dkim.DKIM(message=to_bytes(signed_msg))
            dkim_check = dkim_message.verify(dnsfunc=lambda name: b"".join(
                [b"v=DKIM1; p=", _plain_key(DKIM_PUBLIC_KEY)]))

            self.assertTrue(signed_msg.find("d=testserver") >= 0)
            self.assertTrue(signed_msg.find("s=key2") >= 0)
            self.assertTrue(dkim_check, "Email should be signed by tenant")
Example #3
0
    def test_settings_config(self, smtp):
        """ Test simple / traditional case where config comes from settings """
        be = TenantAwareBackend()
        msg = EmailMultiAlternatives(subject="test", body="test", to=["*****@*****.**"])

        # open the connection explicitly so we can get the
        # connection reference. It will be cleared once closed
        # in send_messages
        be.open()
        connection = be.connection

        be.send_messages([msg])

        self.assertTrue(smtp.called)
        self.assertEquals(smtp.call_args[0], ("somehost", 1337))
        self.assertTrue(connection.sendmail.called)
Example #4
0
    def test_settings_config(self, smtp):
        """ Test simple / traditional case where config comes from settings """
        be = TenantAwareBackend()
        msg = EmailMultiAlternatives(subject="test",
                                     body="test",
                                     to=["*****@*****.**"])

        # open the connection explicitly so we can get the
        # connection reference. It will be cleared once closed
        # in send_messages
        be.open()
        connection = be.connection

        be.send_messages([msg])

        self.assertTrue(smtp.called)
        self.assertEquals(smtp.call_args[0], ('somehost', 1337))
        self.assertTrue(connection.sendmail.called)
Example #5
0
    def test_tenant_config(self, smtp):
        """ test setup where tenant config differs from global settings """

        with mock.patch("bluebottle.utils.email_backend.properties", new=mock.Mock([])) as properties:
            properties.MAIL_CONFIG = {"HOST": "tenanthost", "PORT": 4242}

            be = TenantAwareBackend()
            msg = EmailMultiAlternatives(subject="test", body="test", to=["*****@*****.**"])

            # open the connection explicitly so we can get the
            # connection reference. It will be cleared once closed
            # in send_messages
            be.open()
            connection = be.connection

            be.send_messages([msg])

            self.assertTrue(smtp.called)
            self.assertEquals(smtp.call_args[0], ("tenanthost", 4242))
            self.assertTrue(connection.sendmail.called)
Example #6
0
    def test_tenant_config(self, smtp):
        """ test setup where tenant config differs from global settings """

        with mock.patch("bluebottle.utils.email_backend.properties",
                        new=mock.Mock([])) as properties:
            properties.MAIL_CONFIG = {'HOST': 'tenanthost', 'PORT': 4242}

            be = TenantAwareBackend()
            msg = EmailMultiAlternatives(subject="test",
                                         body="test",
                                         to=["*****@*****.**"])

            # open the connection explicitly so we can get the
            # connection reference. It will be cleared once closed
            # in send_messages
            be.open()
            connection = be.connection

            be.send_messages([msg])

            self.assertTrue(smtp.called)
            self.assertEquals(smtp.call_args[0], ('tenanthost', 4242))
            self.assertTrue(connection.sendmail.called)