Fix: If the default domain is hidden do not return it (#1761)

Co-authored-by: Adrià Casajús <adria.casajus@proton.ch>
This commit is contained in:
Adrià Casajús 2023-05-31 17:59:49 +02:00 committed by GitHub
parent ff33392398
commit 9d9e5fcab6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 25 additions and 1 deletions

View file

@ -170,7 +170,7 @@ def get_alias_suffixes(
if not default_domain_found:
sl_domain = SLDomain.get(user.default_alias_public_domain_id)
if sl_domain:
if sl_domain and not sl_domain.hidden:
prefix = (
""
if config.DISABLE_ALIAS_SUFFIX

View file

@ -60,6 +60,30 @@ def test_get_default_domain_even_if_is_not_allowed():
assert suffixes[0].domain == default_domain.domain
def test_get_default_domain_hidden():
user = create_new_user()
PartnerUser.create(
partner_id=get_proton_partner().id,
user_id=user.id,
external_user_id=random_token(10),
flush=True,
)
user.trial_end = None
default_domain = SLDomain.filter_by(
hidden=True, partner_id=None, premium_only=False
).first()
user.default_alias_public_domain_id = default_domain.id
Session.flush()
options = AliasOptions(
show_sl_domains=False, show_partner_domains=get_proton_partner()
)
suffixes = get_alias_suffixes(user, alias_options=options)
for suffix in suffixes:
domain = SLDomain.get_by(domain=suffix.domain)
assert not domain.hidden
assert suffixes[0].domain != default_domain.domain
def test_suffixes_are_valid():
user = create_new_user()
PartnerUser.create(