From 80b0af91e554ec8302bde4132ebbf26e134225f3 Mon Sep 17 00:00:00 2001 From: Son Date: Wed, 29 Dec 2021 10:23:29 +0100 Subject: [PATCH] allow user to create alias with domain that has ownership verified (and might not have MX verified) --- app/models.py | 2 +- tests/api/test_new_custom_alias.py | 8 ++++++-- tests/api/test_new_random_alias.py | 4 +++- tests/dashboard/test_custom_alias.py | 16 ++++++++++------ 4 files changed, 20 insertions(+), 10 deletions(-) diff --git a/app/models.py b/app/models.py index ae9a2877..1d9f5bd0 100644 --- a/app/models.py +++ b/app/models.py @@ -694,7 +694,7 @@ class User(Base, ModelMixin, UserMixin, PasswordOracle): return sub def verified_custom_domains(self) -> List["CustomDomain"]: - return CustomDomain.filter_by(user_id=self.id, verified=True).all() + return CustomDomain.filter_by(user_id=self.id, ownership_verified=True).all() def mailboxes(self) -> List["Mailbox"]: """list of mailbox that user own""" diff --git a/tests/api/test_new_custom_alias.py b/tests/api/test_new_custom_alias.py index 9254857b..2f0a3064 100644 --- a/tests/api/test_new_custom_alias.py +++ b/tests/api/test_new_custom_alias.py @@ -126,7 +126,9 @@ def test_custom_domain_alias(flask_client): user = login(flask_client) # create a custom domain - CustomDomain.create(user_id=user.id, domain="ab.cd", verified=True, commit=True) + CustomDomain.create( + user_id=user.id, domain="ab.cd", ownership_verified=True, commit=True + ) signed_suffix = signer.sign("@ab.cd").decode() @@ -210,7 +212,9 @@ def test_cannot_create_alias_in_trash(flask_client): user = login(flask_client) # create a custom domain - CustomDomain.create(user_id=user.id, domain="ab.cd", verified=True, commit=True) + CustomDomain.create( + user_id=user.id, domain="ab.cd", ownership_verified=True, commit=True + ) signed_suffix = signer.sign("@ab.cd").decode() diff --git a/tests/api/test_new_random_alias.py b/tests/api/test_new_random_alias.py index 0b0abf1d..e5e7b1ba 100644 --- a/tests/api/test_new_random_alias.py +++ b/tests/api/test_new_random_alias.py @@ -40,7 +40,9 @@ def test_with_hostname(flask_client): def test_with_custom_domain(flask_client): user = login(flask_client) - CustomDomain.create(user_id=user.id, domain="ab.cd", verified=True, commit=True) + CustomDomain.create( + user_id=user.id, domain="ab.cd", ownership_verified=True, commit=True + ) r = flask_client.post( url_for("api.new_random_alias", hostname="www.test.com"), diff --git a/tests/dashboard/test_custom_alias.py b/tests/dashboard/test_custom_alias.py index 8099415a..9777c96b 100644 --- a/tests/dashboard/test_custom_alias.py +++ b/tests/dashboard/test_custom_alias.py @@ -101,7 +101,7 @@ def test_verify_prefix_suffix(flask_client): user = login(flask_client) Session.commit() - CustomDomain.create(user_id=user.id, domain="test.com", verified=True) + CustomDomain.create(user_id=user.id, domain="test.com", ownership_verified=True) assert verify_prefix_suffix(user, "prefix", "@test.com") assert not verify_prefix_suffix(user, "prefix", "@abcd.com") @@ -114,7 +114,7 @@ def test_verify_prefix_suffix(flask_client): def test_available_suffixes(flask_client): user = login(flask_client) - CustomDomain.create(user_id=user.id, domain="test.com", verified=True) + CustomDomain.create(user_id=user.id, domain="test.com", ownership_verified=True) assert len(get_available_suffixes(user)) > 0 @@ -129,7 +129,9 @@ def test_available_suffixes_default_domain(flask_client): user = login(flask_client) sl_domain = SLDomain.first() - CustomDomain.create(user_id=user.id, domain="test.com", verified=True, commit=True) + CustomDomain.create( + user_id=user.id, domain="test.com", ownership_verified=True, commit=True + ) user.default_alias_public_domain_id = sl_domain.id @@ -146,9 +148,11 @@ def test_available_suffixes_default_domain(flask_client): def test_available_suffixes_random_prefix_generation(flask_client): user = login(flask_client) - CustomDomain.create(user_id=user.id, domain="test.com", verified=True, commit=True) + CustomDomain.create( + user_id=user.id, domain="test.com", ownership_verified=True, commit=True + ) cd2 = CustomDomain.create( - user_id=user.id, domain="test2.com", verified=True, commit=True + user_id=user.id, domain="test2.com", ownership_verified=True, commit=True ) user.default_alias_custom_domain_id = cd2.id @@ -255,7 +259,7 @@ def test_add_alias_in_custom_domain_trash(flask_client): user = login(flask_client) custom_domain = CustomDomain.create( - user_id=user.id, domain="ab.cd", verified=True, commit=True + user_id=user.id, domain="ab.cd", ownership_verified=True, commit=True ) # delete a custom-domain alias: alias should go the DomainDeletedAlias