From a9a5f145aa68603d342497188de33cd90b81d08a Mon Sep 17 00:00:00 2001 From: Son NK Date: Fri, 21 Feb 2020 21:59:13 +0700 Subject: [PATCH] fix showing unverified mailbox when creating new alias --- app/dashboard/views/custom_alias.py | 2 +- server.py | 1 + tests/dashboard/test_custom_alias.py | 16 ++++++++++++++++ 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/app/dashboard/views/custom_alias.py b/app/dashboard/views/custom_alias.py index cbdceeea..e0f7e7da 100644 --- a/app/dashboard/views/custom_alias.py +++ b/app/dashboard/views/custom_alias.py @@ -44,7 +44,7 @@ def custom_alias(): ) mailboxes = [current_user.email] - for mailbox in Mailbox.query.filter_by(user_id=current_user.id): + for mailbox in Mailbox.query.filter_by(user_id=current_user.id, verified=True): mailboxes.append(mailbox.email) if request.method == "POST": diff --git a/server.py b/server.py index 498d4d24..eec9c0bb 100644 --- a/server.py +++ b/server.py @@ -186,6 +186,7 @@ def fake_data(): db.session.commit() Mailbox.create(user_id=user.id, email="ab@cd.ef", verified=True) + Mailbox.create(user_id=user.id, email="xy@zt.com", verified=False) db.session.commit() DeletedAlias.create(user_id=user.id, email="d1@ab.cd") diff --git a/tests/dashboard/test_custom_alias.py b/tests/dashboard/test_custom_alias.py index fdfc8a60..0f6631a5 100644 --- a/tests/dashboard/test_custom_alias.py +++ b/tests/dashboard/test_custom_alias.py @@ -2,6 +2,7 @@ from flask import url_for from app.config import EMAIL_DOMAIN from app.extensions import db +from app.models import Mailbox from app.utils import random_word from tests.utils import login @@ -24,3 +25,18 @@ def test_add_alias_success(flask_client): assert r.status_code == 200 assert f"Alias prefix.{word}@{EMAIL_DOMAIN} has been created" in str(r.data) + + +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() + + r = flask_client.get(url_for("dashboard.custom_alias"),) + + assert "m1@example.com" in str(r.data) + assert "m2@example.com" not in str(r.data)