2020-01-28 09:13:03 +01:00
|
|
|
from flask import url_for
|
|
|
|
|
2021-10-12 14:36:47 +02:00
|
|
|
from app.db import Session
|
2022-04-15 16:59:44 +02:00
|
|
|
from app.email_utils import get_email_domain_part
|
2021-10-15 10:32:20 +02:00
|
|
|
from app.models import Mailbox
|
2022-04-18 11:55:14 +02:00
|
|
|
from tests.utils import login, random_domain
|
2020-01-28 09:13:03 +01:00
|
|
|
|
|
|
|
|
|
|
|
def test_add_domain_success(flask_client):
|
|
|
|
user = login(flask_client)
|
|
|
|
user.lifetime = True
|
2021-10-12 14:36:47 +02:00
|
|
|
Session.commit()
|
2020-01-28 09:13:03 +01:00
|
|
|
|
2022-04-18 11:55:14 +02:00
|
|
|
domain = random_domain()
|
2020-01-28 09:13:03 +01:00
|
|
|
r = flask_client.post(
|
|
|
|
url_for("dashboard.custom_domain"),
|
2022-04-18 11:55:14 +02:00
|
|
|
data={"form-name": "create", "domain": domain},
|
2020-01-28 09:13:03 +01:00
|
|
|
follow_redirects=True,
|
|
|
|
)
|
|
|
|
|
|
|
|
assert r.status_code == 200
|
2022-04-18 11:55:14 +02:00
|
|
|
assert f"New domain {domain} is created".encode() in r.data
|
2020-01-28 09:16:26 +01:00
|
|
|
|
|
|
|
|
|
|
|
def test_add_domain_same_as_user_email(flask_client):
|
|
|
|
"""cannot add domain if user personal email uses this domain"""
|
|
|
|
user = login(flask_client)
|
|
|
|
user.lifetime = True
|
2021-10-12 14:36:47 +02:00
|
|
|
Session.commit()
|
2020-01-28 09:16:26 +01:00
|
|
|
|
|
|
|
r = flask_client.post(
|
|
|
|
url_for("dashboard.custom_domain"),
|
2022-04-15 16:59:44 +02:00
|
|
|
data={"form-name": "create", "domain": get_email_domain_part(user.email)},
|
2020-01-28 09:16:26 +01:00
|
|
|
follow_redirects=True,
|
|
|
|
)
|
|
|
|
|
|
|
|
assert r.status_code == 200
|
|
|
|
assert (
|
|
|
|
b"You cannot add a domain that you are currently using for your personal email"
|
|
|
|
in r.data
|
|
|
|
)
|
2021-10-15 10:32:20 +02:00
|
|
|
|
|
|
|
|
|
|
|
def test_add_domain_used_in_mailbox(flask_client):
|
|
|
|
"""cannot add domain if it has been used in a verified mailbox"""
|
|
|
|
user = login(flask_client)
|
|
|
|
user.lifetime = True
|
|
|
|
Session.commit()
|
|
|
|
|
|
|
|
Mailbox.create(
|
|
|
|
user_id=user.id, email="mailbox@new-domain.com", verified=True, commit=True
|
|
|
|
)
|
|
|
|
|
|
|
|
r = flask_client.post(
|
|
|
|
url_for("dashboard.custom_domain"),
|
|
|
|
data={"form-name": "create", "domain": "new-domain.com"},
|
|
|
|
follow_redirects=True,
|
|
|
|
)
|
|
|
|
|
|
|
|
assert r.status_code == 200
|
|
|
|
assert b"new-domain.com already used in a SimpleLogin mailbox" in r.data
|