Browse Source

spot obviously spammy gmail email.

Rafał Pitoń 10 years ago
parent
commit
c312d8f92a
2 changed files with 19 additions and 2 deletions
  1. 13 2
      misago/users/tests/test_validators.py
  2. 6 0
      misago/users/validators.py

+ 13 - 2
misago/users/tests/test_validators.py

@@ -1,6 +1,6 @@
 #-*- coding: utf-8 -*-
 #-*- coding: utf-8 -*-
 from django.contrib.auth import get_user_model
 from django.contrib.auth import get_user_model
-from django.core.exceptions import ValidationError
+from django.core.exceptions import PermissionDenied, ValidationError
 from django.test import TestCase
 from django.test import TestCase
 
 
 from misago.conf import settings
 from misago.conf import settings
@@ -14,7 +14,8 @@ from misago.users.validators import (validate_email,
                                      validate_username_available,
                                      validate_username_available,
                                      validate_username_banned,
                                      validate_username_banned,
                                      validate_username_content,
                                      validate_username_content,
-                                     validate_username_length)
+                                     validate_username_length,
+                                     validate_gmail_email)
 
 
 
 
 class ValidateEmailAvailableTests(TestCase):
 class ValidateEmailAvailableTests(TestCase):
@@ -142,3 +143,13 @@ class ValidateUsernameLengthTests(TestCase):
             validate_username_length('a' * (settings.username_length_min - 1))
             validate_username_length('a' * (settings.username_length_min - 1))
         with self.assertRaises(ValidationError):
         with self.assertRaises(ValidationError):
             validate_username_length('a' * (settings.username_length_max + 1))
             validate_username_length('a' * (settings.username_length_max + 1))
+
+
+class ValidateGmailEmailTests(TestCase):
+    def test_validate_gmail_email(self):
+        """validate_gmail_email spots spammy gmail address"""
+        validate_gmail_email('', '', 'the.bob.boberson@gmail.com')
+        validate_gmail_email('', '', 'the.bob.boberson@hotmail.com')
+
+        with self.assertRaises(PermissionDenied):
+            validate_gmail_email('', '', 'the.b.o.b.b.ob.e.r.son@gmail.com')

+ 6 - 0
misago/users/validators.py

@@ -142,6 +142,12 @@ def _real_validate_with_sfs(ip, email):
         pass # todo: log those somewhere
         pass # todo: log those somewhere
 
 
 
 
+def validate_gmail_email(ip, username, email):
+    username, domain = email.split('@')
+    if domain == 'gmail.com' and username.count('.') > 6:
+        raise PermissionDenied()
+
+
 """
 """
 Registration validation
 Registration validation
 """
 """