2020-02-05 11:35:38 +01:00
|
|
|
from flask import url_for
|
|
|
|
|
|
|
|
from app.config import EMAIL_DOMAIN
|
2020-05-02 12:27:54 +02:00
|
|
|
from app.dashboard.views.custom_alias import signer, verify_prefix_suffix
|
2020-02-05 11:35:38 +01:00
|
|
|
from app.extensions import db
|
2020-05-02 12:27:54 +02:00
|
|
|
from app.models import Mailbox, CustomDomain
|
2020-02-05 11:35:38 +01:00
|
|
|
from app.utils import random_word
|
|
|
|
from tests.utils import login
|
|
|
|
|
|
|
|
|
|
|
|
def test_add_alias_success(flask_client):
|
2020-02-10 17:30:04 +01:00
|
|
|
user = login(flask_client)
|
2020-02-05 11:35:38 +01:00
|
|
|
db.session.commit()
|
|
|
|
|
|
|
|
word = random_word()
|
2020-05-02 12:15:03 +02:00
|
|
|
suffix = f".{word}@{EMAIL_DOMAIN}"
|
|
|
|
suffix = signer.sign(suffix).decode()
|
2020-02-05 11:35:38 +01:00
|
|
|
|
|
|
|
r = flask_client.post(
|
|
|
|
url_for("dashboard.custom_alias"),
|
2020-05-02 12:15:03 +02:00
|
|
|
data={"prefix": "prefix", "suffix": suffix, "mailbox": user.email,},
|
2020-02-05 11:35:38 +01:00
|
|
|
follow_redirects=True,
|
|
|
|
)
|
|
|
|
|
|
|
|
assert r.status_code == 200
|
|
|
|
assert f"Alias prefix.{word}@{EMAIL_DOMAIN} has been created" in str(r.data)
|
2020-02-21 15:59:13 +01:00
|
|
|
|
|
|
|
|
|
|
|
def test_not_show_unverified_mailbox(flask_client):
|
|
|
|
"""make sure user unverified mailbox is not shown to user"""
|
|
|
|
user = login(flask_client)
|
|
|
|
db.session.commit()
|
|
|
|
|
|
|
|
Mailbox.create(user_id=user.id, email="m1@example.com", verified=True)
|
|
|
|
Mailbox.create(user_id=user.id, email="m2@example.com", verified=False)
|
|
|
|
db.session.commit()
|
|
|
|
|
2020-03-05 11:00:58 +01:00
|
|
|
r = flask_client.get(url_for("dashboard.custom_alias"))
|
2020-02-21 15:59:13 +01:00
|
|
|
|
|
|
|
assert "m1@example.com" in str(r.data)
|
|
|
|
assert "m2@example.com" not in str(r.data)
|
2020-05-02 12:27:54 +02:00
|
|
|
|
|
|
|
|
|
|
|
def test_verify_prefix_suffix(flask_client):
|
|
|
|
user = login(flask_client)
|
|
|
|
db.session.commit()
|
|
|
|
|
|
|
|
CustomDomain.create(user_id=user.id, domain="test.com", verified=True)
|
|
|
|
|
|
|
|
assert verify_prefix_suffix(user, "prefix", "@test.com")
|
|
|
|
assert not verify_prefix_suffix(user, "prefix", "@abcd.com")
|
|
|
|
|
|
|
|
word = random_word()
|
|
|
|
suffix = f".{word}@{EMAIL_DOMAIN}"
|
|
|
|
assert verify_prefix_suffix(user, "prefix", suffix)
|