feat: Case Insensitive Email.address field (#5046)

* fix: address mypy quibble

* fix: use citext for Email.address

* test: confirm adding case-varied email fails
This commit is contained in:
Robert Sparks 2023-01-30 11:52:38 -06:00 committed by GitHub
parent 6de27154ed
commit a202cf4bf9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 45 additions and 2 deletions

View file

@ -381,6 +381,21 @@ class IetfAuthTests(TestCase):
self.assertEqual(len(updated_roles), 1)
self.assertEqual(updated_roles[0].email_id, new_email_address)
def test_email_case_insensitive_protection(self):
EmailFactory(address="TestAddress@example.net")
person = PersonFactory()
url = urlreverse(ietf.ietfauth.views.profile)
login_testing_unauthorized(self, person.user.username, url)
data = {
"name": person.name,
"plain": person.plain,
"ascii": person.ascii,
"active_emails": [e.address for e in person.email_set.filter(active=True)],
"new_email": "testaddress@example.net",
}
r = self.client.post(url, data)
self.assertContains(r, "Email address 'TestAddress@example.net' is already assigned", status_code=200)
def test_nomcom_dressing_on_profile(self):
url = urlreverse('ietf.ietfauth.views.profile')

View file

@ -0,0 +1,27 @@
# Generated by Django 2.2.28 on 2023-01-26 19:45
import django.contrib.postgres.fields.citext
from django.contrib.postgres.operations import CITextExtension
import django.core.validators
from django.db import migrations
class Migration(migrations.Migration):
dependencies = [
('person', '0029_use_timezone_now_for_person_models'),
]
operations = [
CITextExtension(),
migrations.AlterField(
model_name='email',
name='address',
field=django.contrib.postgres.fields.citext.CICharField(max_length=64, primary_key=True, serialize=False, validators=[django.core.validators.EmailValidator()]),
),
migrations.AlterField(
model_name='historicalemail',
name='address',
field=django.contrib.postgres.fields.citext.CICharField(db_index=True, max_length=64, validators=[django.core.validators.EmailValidator()]),
),
]

View file

@ -12,6 +12,7 @@ from urllib.parse import urljoin
from django.conf import settings
from django.contrib.auth.models import User
from django.contrib.postgres.fields import CICharField
from django.core.exceptions import ValidationError
from django.core.validators import validate_email
from django.db import models
@ -277,7 +278,7 @@ class Alias(models.Model):
class Email(models.Model):
history = HistoricalRecords()
address = models.CharField(max_length=64, primary_key=True, validators=[validate_email])
address = CICharField(max_length=64, primary_key=True, validators=[validate_email])
person = ForeignKey(Person, null=True)
time = models.DateTimeField(auto_now_add=True)
primary = models.BooleanField(default=False)

View file

@ -37,7 +37,7 @@ MIGRATION_MODULES = DisableMigrations()
DATABASES = {
'default': {
'HOST': 'db',
'PORT': 5432,
'PORT': '5432',
'NAME': 'test.db',
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'USER': 'django',