This commit is contained in:
parent
b3ee67213d
commit
3180034ff8
@ -583,6 +583,26 @@ def email_can_be_used_as_mailbox(email_address: str) -> bool:
|
|||||||
LOG.d("MX Domain %s %s is invalid mailbox domain", mx_domain, domain)
|
LOG.d("MX Domain %s %s is invalid mailbox domain", mx_domain, domain)
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
existing_user = User.get_by(email=email_address)
|
||||||
|
if existing_user and existing_user.disabled:
|
||||||
|
LOG.d(
|
||||||
|
f"User {existing_user} is disabled. {email_address} cannot be used for other mailbox"
|
||||||
|
)
|
||||||
|
return False
|
||||||
|
|
||||||
|
for existing_user in (
|
||||||
|
User.query()
|
||||||
|
.join(Mailbox, User.id == Mailbox.user_id)
|
||||||
|
.filter(Mailbox.email == email_address)
|
||||||
|
.group_by(User.id)
|
||||||
|
.all()
|
||||||
|
):
|
||||||
|
if existing_user.disabled:
|
||||||
|
LOG.d(
|
||||||
|
f"User {existing_user} is disabled and has a mailbox with {email_address}. Id cannot be used for other mailbox"
|
||||||
|
)
|
||||||
|
return False
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
|
@ -49,11 +49,11 @@ def random_string(length=10, include_digits=False):
|
|||||||
|
|
||||||
def convert_to_id(s: str):
|
def convert_to_id(s: str):
|
||||||
"""convert a string to id-like: remove space, remove special accent"""
|
"""convert a string to id-like: remove space, remove special accent"""
|
||||||
s = s.replace(" ", "")
|
|
||||||
s = s.lower()
|
s = s.lower()
|
||||||
s = unidecode(s)
|
s = unidecode(s)
|
||||||
|
s = s.replace(" ", "")
|
||||||
|
|
||||||
return s
|
return s[:256]
|
||||||
|
|
||||||
|
|
||||||
_ALLOWED_CHARS = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_-."
|
_ALLOWED_CHARS = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_-."
|
||||||
|
@ -9,7 +9,7 @@
|
|||||||
<a href='https://simplelogin.io/' aria-label="SimpleLogin">
|
<a href='https://simplelogin.io/' aria-label="SimpleLogin">
|
||||||
<img src="/static/logo-white.svg"
|
<img src="/static/logo-white.svg"
|
||||||
height="30px"
|
height="30px"
|
||||||
class="mb-3"
|
class="mt-1 mb-3"
|
||||||
alt="SimpleLogin logo">
|
alt="SimpleLogin logo">
|
||||||
</a>
|
</a>
|
||||||
<!-- End Logo -->
|
<!-- End Logo -->
|
||||||
|
@ -49,10 +49,25 @@ from app.models import (
|
|||||||
VerpType,
|
VerpType,
|
||||||
AliasGeneratorEnum,
|
AliasGeneratorEnum,
|
||||||
SLDomain,
|
SLDomain,
|
||||||
|
Mailbox,
|
||||||
)
|
)
|
||||||
|
|
||||||
# flake8: noqa: E101, W191
|
# flake8: noqa: E101, W191
|
||||||
from tests.utils import login, load_eml_file, create_new_user, random_domain
|
from tests.utils import (
|
||||||
|
login,
|
||||||
|
load_eml_file,
|
||||||
|
create_new_user,
|
||||||
|
random_domain,
|
||||||
|
random_token,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def setup_module(module):
|
||||||
|
config.SKIP_MX_LOOKUP_ON_CHECK = True
|
||||||
|
|
||||||
|
|
||||||
|
def teardown_module(module):
|
||||||
|
config.SKIP_MX_LOOKUP_ON_CHECK = False
|
||||||
|
|
||||||
|
|
||||||
def test_get_email_domain_part():
|
def test_get_email_domain_part():
|
||||||
@ -68,10 +83,6 @@ def test_email_belongs_to_alias_domains():
|
|||||||
assert not can_create_directory_for_address("hey@d3.test")
|
assert not can_create_directory_for_address("hey@d3.test")
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.skipif(
|
|
||||||
"GITHUB_ACTIONS_TEST" in os.environ,
|
|
||||||
reason="this test requires DNS lookup that does not work on Github CI",
|
|
||||||
)
|
|
||||||
def test_can_be_used_as_personal_email(flask_client):
|
def test_can_be_used_as_personal_email(flask_client):
|
||||||
# default alias domain
|
# default alias domain
|
||||||
assert not email_can_be_used_as_mailbox("ab@sl.local")
|
assert not email_can_be_used_as_mailbox("ab@sl.local")
|
||||||
@ -94,6 +105,27 @@ def test_can_be_used_as_personal_email(flask_client):
|
|||||||
assert email_can_be_used_as_mailbox("abcd@gmail.com")
|
assert email_can_be_used_as_mailbox("abcd@gmail.com")
|
||||||
|
|
||||||
|
|
||||||
|
def test_disabled_user_prevents_email_from_being_used_as_mailbox():
|
||||||
|
email = f"user_{random_token(10)}@mailbox.test"
|
||||||
|
assert email_can_be_used_as_mailbox(email)
|
||||||
|
user = create_new_user(email)
|
||||||
|
user.disabled = True
|
||||||
|
Session.flush()
|
||||||
|
assert not email_can_be_used_as_mailbox(email)
|
||||||
|
|
||||||
|
|
||||||
|
def test_disabled_user_with_secondary_mailbox_prevents_email_from_being_used_as_mailbox():
|
||||||
|
email = f"user_{random_token(10)}@mailbox.test"
|
||||||
|
assert email_can_be_used_as_mailbox(email)
|
||||||
|
user = create_new_user()
|
||||||
|
Mailbox.create(user_id=user.id, email=email)
|
||||||
|
Session.flush()
|
||||||
|
assert email_can_be_used_as_mailbox(email)
|
||||||
|
user.disabled = True
|
||||||
|
Session.flush()
|
||||||
|
assert not email_can_be_used_as_mailbox(email)
|
||||||
|
|
||||||
|
|
||||||
def test_delete_header():
|
def test_delete_header():
|
||||||
msg = EmailMessage()
|
msg = EmailMessage()
|
||||||
assert msg._headers == []
|
assert msg._headers == []
|
||||||
|
Loading…
x
Reference in New Issue
Block a user