mirror of
https://github.com/simple-login/app.git
synced 2024-11-16 00:48:32 +01:00
when a custom domain is default and has random_prefix_generation enabled, use the random_prefix as the first choice
This commit is contained in:
parent
3179d70df1
commit
2b4dc3cdcc
2 changed files with 34 additions and 6 deletions
|
@ -52,18 +52,25 @@ def get_available_suffixes(user: User) -> [SuffixInfo]:
|
|||
# put custom domain first
|
||||
# for each user domain, generate both the domain and a random suffix version
|
||||
for custom_domain in user_custom_domains:
|
||||
suffix = "@" + custom_domain.domain
|
||||
if custom_domain.random_prefix_generation:
|
||||
suffix = "." + random_word() + "@" + custom_domain.domain
|
||||
suffix_info = SuffixInfo(True, suffix, signer.sign(suffix).decode(), False)
|
||||
|
||||
# put the default domain to top
|
||||
if user.default_alias_custom_domain_id == custom_domain.id:
|
||||
suffixes.insert(0, suffix_info)
|
||||
else:
|
||||
suffixes.append(suffix_info)
|
||||
|
||||
if custom_domain.random_prefix_generation:
|
||||
suffix = "." + random_word() + "@" + custom_domain.domain
|
||||
suffix = "@" + custom_domain.domain
|
||||
suffix_info = SuffixInfo(True, suffix, signer.sign(suffix).decode(), False)
|
||||
|
||||
# put the default domain to top
|
||||
# only if random_prefix_generation isn't enabled
|
||||
if (
|
||||
user.default_alias_custom_domain_id == custom_domain.id
|
||||
and not custom_domain.random_prefix_generation
|
||||
):
|
||||
suffixes.insert(0, suffix_info)
|
||||
else:
|
||||
suffixes.append(suffix_info)
|
||||
|
||||
# then SimpleLogin domain
|
||||
|
|
|
@ -135,6 +135,27 @@ def test_available_suffixes_default_domain(flask_client):
|
|||
assert first_suffix.suffix == "@test.com"
|
||||
|
||||
|
||||
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)
|
||||
cd2 = CustomDomain.create(
|
||||
user_id=user.id, domain="test2.com", verified=True, commit=True
|
||||
)
|
||||
|
||||
user.default_alias_custom_domain_id = cd2.id
|
||||
|
||||
# first suffix is test2.com
|
||||
first_suffix = get_available_suffixes(user)[0]
|
||||
assert first_suffix.suffix == "@test2.com"
|
||||
|
||||
cd2.random_prefix_generation = True
|
||||
# e.g. .meo@test2.com
|
||||
first_suffix = get_available_suffixes(user)[0]
|
||||
assert first_suffix.suffix.endswith("@test2.com")
|
||||
assert first_suffix.suffix.startswith(".")
|
||||
|
||||
|
||||
def test_add_already_existed_alias(flask_client):
|
||||
user = login(flask_client)
|
||||
db.session.commit()
|
||||
|
|
Loading…
Reference in a new issue