Exemple #1
0
    def test_is_email_blacklisted_with_not_blacklisted_host(self):
        """
        Test that checking a non blacklisted email correctly returns False.
        """

        self.assertFalse(
            is_email_blacklisted(f"a@{self.not_blacklisted_host}"))
Exemple #2
0
    def get(self, request, *args, **kwargs):
        context = {"results": []}
        Row = namedtuple("Row", ["kind", "value", "result"])
        email_query = self.request.GET.getlist("email")
        for email in email_query:
            result = "NO"
            if is_email_blacklisted(email):
                result = "YES"
            row = Row("email", email, result)
            context["results"].append(row)
        host_query = self.request.GET.getlist("email_host")
        for host in host_query:
            result = "NO"
            if is_email_host_blacklisted(host):
                result = "YES"
            row = Row("email_host", host, result)
            context["results"].append(row)
        ip_query = self.request.GET.getlist("ip")
        for ip in ip_query:
            result = "NO"
            if is_ip_blacklisted(ip):
                result = "YES"
            row = Row("ip", ip, result)
            context["results"].append(row)

        return HttpResponse(self.template.render(context, request))
Exemple #3
0
    def test_is_email_blacklisted_with_lower_case_blacklisted_email_and_lower_case_query(
            self):
        """
        Test that checking a blacklisted email correctly returns True.
        """

        self.assertTrue(is_email_blacklisted(
            self.lower_case_blacklisted_email))
Exemple #4
0
    def test_is_email_blacklisted_with_lower_case_blacklisted_host_and_lower_case_query(
            self):
        """
        Test that checking a blacklisted email correctly returns True,
        even if only the email host is in our database.
        """

        self.assertTrue(
            is_email_blacklisted(f"a@{self.lower_case_blacklisted_host}"))
Exemple #5
0
    def test_is_email_blacklisted_with_lower_case_blacklisted_email_and_upper_case_query(
            self):
        """
        Test that checking a blacklisted email correctly returns True,
        even if the query is in upper-case and the email is saved with lower case
        in our database.
        """

        self.assertTrue(
            is_email_blacklisted(self.lower_case_blacklisted_email.upper()))
Exemple #6
0
 def get(self, request, format=None):
     result_list = []
     email_query = request.GET.getlist("email")
     for email in email_query:
         result = is_email_blacklisted(email)
         response = {"kind": "email", "value": email, "result": result}
         result_list.append(response)
     host_query = self.request.GET.getlist("email_host")
     for host in host_query:
         result = is_email_host_blacklisted(host)
         response = {"kind": "email_host", "value": host, "result": result}
         result_list.append(response)
     ip_query = self.request.GET.getlist("ip")
     for ip in ip_query:
         result = is_ip_blacklisted(ip)
         response = {"kind": "ip", "value": ip, "result": result}
         result_list.append(response)
     return Response(result_list)