4.65.1
Some checks failed
Build-Release-Image / Build-Image (linux/arm64) (push) Successful in 20m30s
Build-Release-Image / Build-Image (linux/amd64) (push) Has been cancelled
Build-Release-Image / Merge-Images (push) Has been cancelled
Build-Release-Image / Create-Release (push) Has been cancelled
Build-Release-Image / Notify (push) Has been cancelled
Some checks failed
Build-Release-Image / Build-Image (linux/arm64) (push) Successful in 20m30s
Build-Release-Image / Build-Image (linux/amd64) (push) Has been cancelled
Build-Release-Image / Merge-Images (push) Has been cancelled
Build-Release-Image / Create-Release (push) Has been cancelled
Build-Release-Image / Notify (push) Has been cancelled
This commit is contained in:
@ -59,11 +59,17 @@ def test_set_mailboxes_for_alias_mailbox_success():
|
||||
assert db_alias is not None
|
||||
assert db_alias.mailbox_id == mb1.id
|
||||
|
||||
alias_mailboxes = AliasMailbox.filter_by(alias_id=alias.id).all()
|
||||
alias_mailboxes = (
|
||||
AliasMailbox.filter_by(alias_id=alias.id).order_by(AliasMailbox.id.asc()).all()
|
||||
)
|
||||
assert len(alias_mailboxes) == 1
|
||||
assert alias_mailboxes[0].mailbox_id == mb2.id
|
||||
|
||||
audit_logs = AliasAuditLog.filter_by(alias_id=alias.id).all()
|
||||
audit_logs = (
|
||||
AliasAuditLog.filter_by(alias_id=alias.id)
|
||||
.order_by(AliasAuditLog.id.asc())
|
||||
.all()
|
||||
)
|
||||
assert len(audit_logs) == 2
|
||||
assert audit_logs[0].action == AliasAuditLogAction.CreateAlias.value
|
||||
assert audit_logs[1].action == AliasAuditLogAction.ChangedMailboxes.value
|
||||
|
@ -6,6 +6,7 @@ from app.coupon_utils import (
|
||||
CouponUserCannotRedeemError,
|
||||
redeem_lifetime_coupon,
|
||||
)
|
||||
from app.db import Session
|
||||
from app.models import (
|
||||
Coupon,
|
||||
Subscription,
|
||||
@ -14,8 +15,11 @@ from app.models import (
|
||||
CoinbaseSubscription,
|
||||
LifetimeCoupon,
|
||||
User,
|
||||
PartnerSubscription,
|
||||
PartnerUser,
|
||||
)
|
||||
from tests.utils import create_new_user, random_string
|
||||
from app.proton.utils import get_proton_partner
|
||||
from tests.utils import create_new_user, random_string, random_email
|
||||
|
||||
|
||||
def test_use_coupon():
|
||||
@ -157,3 +161,55 @@ def test_used_lifetime_coupon():
|
||||
user = User.get(user.id)
|
||||
assert not user.lifetime
|
||||
assert not user.paid_lifetime
|
||||
|
||||
|
||||
def test_used_lifetime_coupon_with_lifetime_user():
|
||||
user = create_new_user()
|
||||
user.lifetime = True
|
||||
code = random_string(10)
|
||||
LifetimeCoupon.create(code=code, nb_used=10, paid=True)
|
||||
coupon = redeem_lifetime_coupon(code, user)
|
||||
assert coupon is None
|
||||
|
||||
|
||||
def test_used_lifetime_coupon_with_lifetime_partner():
|
||||
email = random_email()
|
||||
user = User.create(email=email)
|
||||
pu = PartnerUser.create(
|
||||
user_id=user.id,
|
||||
partner_id=get_proton_partner().id,
|
||||
partner_email=email,
|
||||
external_user_id=random_string(10),
|
||||
flush=True,
|
||||
)
|
||||
PartnerSubscription.create(
|
||||
partner_user_id=pu.id, end_at=arrow.utcnow().shift(years=10), lifetime=True
|
||||
)
|
||||
Session.flush()
|
||||
code = random_string(10)
|
||||
LifetimeCoupon.create(code=code, nb_used=10, paid=True)
|
||||
coupon = redeem_lifetime_coupon(code, user)
|
||||
assert coupon is None
|
||||
|
||||
|
||||
def test_used_lifetime_coupon_with_partner_sub():
|
||||
email = random_email()
|
||||
user = User.create(email=email)
|
||||
pu = PartnerUser.create(
|
||||
user_id=user.id,
|
||||
partner_id=get_proton_partner().id,
|
||||
partner_email=email,
|
||||
external_user_id=random_string(10),
|
||||
flush=True,
|
||||
)
|
||||
PartnerSubscription.create(
|
||||
partner_user_id=pu.id, end_at=arrow.utcnow().shift(years=10)
|
||||
)
|
||||
Session.flush()
|
||||
code = random_string(10)
|
||||
LifetimeCoupon.create(code=code, nb_used=10, paid=True)
|
||||
coupon = redeem_lifetime_coupon(code, user)
|
||||
assert coupon
|
||||
user = User.get(user.id)
|
||||
assert user.lifetime
|
||||
assert user.paid_lifetime
|
||||
|
@ -13,8 +13,8 @@ from app.custom_domain_utils import (
|
||||
)
|
||||
from app.db import Session
|
||||
from app.models import User, CustomDomain, Mailbox, DomainMailbox
|
||||
from tests.utils import get_proton_partner, random_email
|
||||
from tests.utils import create_new_user, random_string, random_domain
|
||||
from tests.utils import get_proton_partner, random_email
|
||||
|
||||
user: Optional[User] = None
|
||||
|
||||
@ -195,7 +195,11 @@ def test_set_custom_domain_mailboxes_success():
|
||||
assert res.success is True
|
||||
assert res.reason is None
|
||||
|
||||
domain_mailboxes = DomainMailbox.filter_by(domain_id=domain.id).all()
|
||||
domain_mailboxes = (
|
||||
DomainMailbox.filter_by(domain_id=domain.id)
|
||||
.order_by(DomainMailbox.mailbox_id.asc())
|
||||
.all()
|
||||
)
|
||||
assert len(domain_mailboxes) == 2
|
||||
assert domain_mailboxes[0].domain_id == domain.id
|
||||
assert domain_mailboxes[0].mailbox_id == user.default_mailbox_id
|
||||
@ -219,7 +223,11 @@ def test_set_custom_domain_mailboxes_set_twice():
|
||||
assert res.success is True
|
||||
assert res.reason is None
|
||||
|
||||
domain_mailboxes = DomainMailbox.filter_by(domain_id=domain.id).all()
|
||||
domain_mailboxes = (
|
||||
DomainMailbox.filter_by(domain_id=domain.id)
|
||||
.order_by(DomainMailbox.mailbox_id.asc())
|
||||
.all()
|
||||
)
|
||||
assert len(domain_mailboxes) == 2
|
||||
assert domain_mailboxes[0].domain_id == domain.id
|
||||
assert domain_mailboxes[0].mailbox_id == user.default_mailbox_id
|
||||
|
@ -4,8 +4,8 @@ from app import config
|
||||
from app.constants import DMARC_RECORD
|
||||
from app.custom_domain_validation import CustomDomainValidation
|
||||
from app.db import Session
|
||||
from app.dns_utils import InMemoryDNSClient
|
||||
from app.models import CustomDomain, User
|
||||
from app.dns_utils import InMemoryDNSClient, MxRecord
|
||||
from app.proton.utils import get_proton_partner
|
||||
from app.utils import random_string
|
||||
from tests.utils import create_new_user, random_domain
|
||||
@ -33,9 +33,12 @@ def test_custom_domain_validation_get_dkim_records():
|
||||
records = validator.get_dkim_records(custom_domain)
|
||||
|
||||
assert len(records) == 3
|
||||
assert records["dkim02._domainkey"] == f"dkim02._domainkey.{domain}"
|
||||
assert records["dkim03._domainkey"] == f"dkim03._domainkey.{domain}"
|
||||
assert records["dkim._domainkey"] == f"dkim._domainkey.{domain}"
|
||||
assert records["dkim02._domainkey"].recommended == f"dkim02._domainkey.{domain}"
|
||||
assert records["dkim02._domainkey"].allowed == [f"dkim02._domainkey.{domain}"]
|
||||
assert records["dkim03._domainkey"].recommended == f"dkim03._domainkey.{domain}"
|
||||
assert records["dkim03._domainkey"].allowed == [f"dkim03._domainkey.{domain}"]
|
||||
assert records["dkim._domainkey"].recommended == f"dkim._domainkey.{domain}"
|
||||
assert records["dkim._domainkey"].allowed == [f"dkim._domainkey.{domain}"]
|
||||
|
||||
|
||||
def test_custom_domain_validation_get_dkim_records_for_partner():
|
||||
@ -53,9 +56,25 @@ def test_custom_domain_validation_get_dkim_records_for_partner():
|
||||
records = validator.get_dkim_records(custom_domain)
|
||||
|
||||
assert len(records) == 3
|
||||
assert records["dkim02._domainkey"] == f"dkim02._domainkey.{dkim_domain}"
|
||||
assert records["dkim03._domainkey"] == f"dkim03._domainkey.{dkim_domain}"
|
||||
assert records["dkim._domainkey"] == f"dkim._domainkey.{dkim_domain}"
|
||||
assert (
|
||||
records["dkim02._domainkey"].recommended == f"dkim02._domainkey.{dkim_domain}"
|
||||
)
|
||||
assert records["dkim02._domainkey"].allowed == [
|
||||
f"dkim02._domainkey.{dkim_domain}",
|
||||
f"dkim02._domainkey.{domain}",
|
||||
]
|
||||
assert (
|
||||
records["dkim03._domainkey"].recommended == f"dkim03._domainkey.{dkim_domain}"
|
||||
)
|
||||
assert records["dkim03._domainkey"].allowed == [
|
||||
f"dkim03._domainkey.{dkim_domain}",
|
||||
f"dkim03._domainkey.{domain}",
|
||||
]
|
||||
assert records["dkim._domainkey"].recommended == f"dkim._domainkey.{dkim_domain}"
|
||||
assert records["dkim._domainkey"].allowed == [
|
||||
f"dkim._domainkey.{dkim_domain}",
|
||||
f"dkim._domainkey.{domain}",
|
||||
]
|
||||
|
||||
|
||||
# get_expected_mx_records
|
||||
@ -75,8 +94,8 @@ def test_custom_domain_validation_get_expected_mx_records_regular_domain():
|
||||
assert len(records) == len(config.EMAIL_SERVERS_WITH_PRIORITY)
|
||||
for i in range(len(config.EMAIL_SERVERS_WITH_PRIORITY)):
|
||||
config_record = config.EMAIL_SERVERS_WITH_PRIORITY[i]
|
||||
assert records[i].priority == config_record[0]
|
||||
assert records[i].domain == config_record[1]
|
||||
assert records[config_record[0]].recommended == config_record[1]
|
||||
assert records[config_record[0]].allowed == [config_record[1]]
|
||||
|
||||
|
||||
def test_custom_domain_validation_get_expected_mx_records_domain_from_partner():
|
||||
@ -89,14 +108,15 @@ def test_custom_domain_validation_get_expected_mx_records_domain_from_partner():
|
||||
|
||||
dkim_domain = random_domain()
|
||||
validator = CustomDomainValidation(dkim_domain)
|
||||
records = validator.get_expected_mx_records(custom_domain)
|
||||
expected_records = validator.get_expected_mx_records(custom_domain)
|
||||
# As the domain is a partner_domain but there is no custom config for partner, default records
|
||||
# should be used
|
||||
assert len(records) == len(config.EMAIL_SERVERS_WITH_PRIORITY)
|
||||
assert len(expected_records) == len(config.EMAIL_SERVERS_WITH_PRIORITY)
|
||||
for i in range(len(config.EMAIL_SERVERS_WITH_PRIORITY)):
|
||||
config_record = config.EMAIL_SERVERS_WITH_PRIORITY[i]
|
||||
assert records[i].priority == config_record[0]
|
||||
assert records[i].domain == config_record[1]
|
||||
expected = expected_records[config_record[0]]
|
||||
assert expected.recommended == config_record[1]
|
||||
assert expected.allowed == [config_record[1]]
|
||||
|
||||
|
||||
def test_custom_domain_validation_get_expected_mx_records_domain_from_partner_with_custom_config():
|
||||
@ -112,15 +132,21 @@ def test_custom_domain_validation_get_expected_mx_records_domain_from_partner_wi
|
||||
validator = CustomDomainValidation(
|
||||
dkim_domain, partner_domains={partner_id: expected_mx_domain}
|
||||
)
|
||||
records = validator.get_expected_mx_records(custom_domain)
|
||||
expected_records = validator.get_expected_mx_records(custom_domain)
|
||||
# As the domain is a partner_domain and there is a custom config for partner, partner records
|
||||
# should be used
|
||||
assert len(records) == 2
|
||||
assert len(expected_records) == 2
|
||||
sl_domains = config.EMAIL_SERVERS_WITH_PRIORITY
|
||||
|
||||
assert records[0].priority == 10
|
||||
assert records[0].domain == f"mx1.{expected_mx_domain}."
|
||||
assert records[1].priority == 20
|
||||
assert records[1].domain == f"mx2.{expected_mx_domain}."
|
||||
assert expected_records[10].recommended == f"mx1.{expected_mx_domain}."
|
||||
expected = [f"mx1.{expected_mx_domain}."]
|
||||
expected.extend([sl_dom[1] for sl_dom in sl_domains if sl_dom[0] == 10])
|
||||
assert expected_records[10].allowed == expected
|
||||
|
||||
assert expected_records[20].recommended == f"mx2.{expected_mx_domain}."
|
||||
expected = [f"mx2.{expected_mx_domain}."]
|
||||
expected.extend([sl_dom[1] for sl_dom in sl_domains if sl_dom[0] == 20])
|
||||
assert expected_records[20].allowed == expected
|
||||
|
||||
|
||||
# get_expected_spf_records
|
||||
@ -309,7 +335,7 @@ def test_custom_domain_validation_validate_ownership_success():
|
||||
domain = create_custom_domain(random_domain())
|
||||
|
||||
dns_client.set_txt_record(
|
||||
domain.domain, [validator.get_ownership_verification_record(domain)]
|
||||
domain.domain, validator.get_ownership_verification_record(domain).allowed
|
||||
)
|
||||
res = validator.validate_domain_ownership(domain)
|
||||
|
||||
@ -336,7 +362,7 @@ def test_custom_domain_validation_validate_ownership_from_partner_success():
|
||||
Session.commit()
|
||||
|
||||
dns_client.set_txt_record(
|
||||
domain.domain, [validator.get_ownership_verification_record(domain)]
|
||||
domain.domain, validator.get_ownership_verification_record(domain).allowed
|
||||
)
|
||||
res = validator.validate_domain_ownership(domain)
|
||||
|
||||
@ -370,7 +396,7 @@ def test_custom_domain_validation_validate_mx_records_wrong_records_failure():
|
||||
|
||||
wrong_record_1 = random_string()
|
||||
wrong_record_2 = random_string()
|
||||
wrong_records = [MxRecord(10, wrong_record_1), MxRecord(20, wrong_record_2)]
|
||||
wrong_records = {10: [wrong_record_1], 20: [wrong_record_2]}
|
||||
dns_client.set_mx_records(domain.domain, wrong_records)
|
||||
res = validator.validate_mx_records(domain)
|
||||
|
||||
@ -387,7 +413,12 @@ def test_custom_domain_validation_validate_mx_records_success():
|
||||
|
||||
domain = create_custom_domain(random_domain())
|
||||
|
||||
dns_client.set_mx_records(domain.domain, validator.get_expected_mx_records(domain))
|
||||
mx_records_by_prio = validator.get_expected_mx_records(domain)
|
||||
dns_records = {
|
||||
priority: mx_records_by_prio[priority].allowed
|
||||
for priority in mx_records_by_prio
|
||||
}
|
||||
dns_client.set_mx_records(domain.domain, dns_records)
|
||||
res = validator.validate_mx_records(domain)
|
||||
|
||||
assert res.success is True
|
||||
@ -485,16 +516,19 @@ def test_custom_domain_validation_validate_spf_cleans_verification_record():
|
||||
domain.partner_id = proton_partner_id
|
||||
Session.commit()
|
||||
|
||||
wrong_record = random_string()
|
||||
dns_client.set_txt_record(
|
||||
hostname=domain.domain,
|
||||
txt_list=[wrong_record, validator.get_ownership_verification_record(domain)],
|
||||
)
|
||||
res = validator.validate_spf_records(domain)
|
||||
ownership_records = validator.get_ownership_verification_record(domain)
|
||||
|
||||
assert res.success is False
|
||||
assert len(res.errors) == 1
|
||||
assert res.errors[0] == wrong_record
|
||||
for ownership_record in ownership_records.allowed:
|
||||
wrong_record = random_string()
|
||||
dns_client.set_txt_record(
|
||||
hostname=domain.domain,
|
||||
txt_list=[wrong_record, ownership_record],
|
||||
)
|
||||
res = validator.validate_spf_records(domain)
|
||||
|
||||
assert res.success is False
|
||||
assert len(res.errors) == 1
|
||||
assert res.errors[0] == wrong_record
|
||||
|
||||
|
||||
# validate_dmarc_records
|
||||
|
@ -1,9 +1,8 @@
|
||||
from app.custom_domain_validation import is_mx_equivalent, ExpectedValidationRecords
|
||||
from app.dns_utils import (
|
||||
get_mx_domains,
|
||||
get_network_dns_client,
|
||||
is_mx_equivalent,
|
||||
InMemoryDNSClient,
|
||||
MxRecord,
|
||||
)
|
||||
|
||||
from tests.utils import random_domain
|
||||
@ -17,9 +16,9 @@ def test_get_mx_domains():
|
||||
|
||||
assert len(r) > 0
|
||||
|
||||
for x in r:
|
||||
assert x.priority > 0
|
||||
assert x.domain
|
||||
for prio in r:
|
||||
assert prio > 0
|
||||
assert len(r[prio]) > 0
|
||||
|
||||
|
||||
def test_get_spf_domain():
|
||||
@ -33,33 +32,49 @@ def test_get_txt_record():
|
||||
|
||||
|
||||
def test_is_mx_equivalent():
|
||||
assert is_mx_equivalent([], [])
|
||||
assert is_mx_equivalent({}, {})
|
||||
assert is_mx_equivalent(
|
||||
mx_domains=[MxRecord(1, "domain")], ref_mx_domains=[MxRecord(1, "domain")]
|
||||
mx_domains={1: ["domain"]},
|
||||
expected_mx_domains={
|
||||
1: ExpectedValidationRecords(recommended="nop", allowed=["domain"])
|
||||
},
|
||||
)
|
||||
assert is_mx_equivalent(
|
||||
mx_domains=[MxRecord(10, "domain1"), MxRecord(20, "domain2")],
|
||||
ref_mx_domains=[MxRecord(10, "domain1"), MxRecord(20, "domain2")],
|
||||
mx_domains={10: ["domain10"], 20: ["domain20"]},
|
||||
expected_mx_domains={
|
||||
10: ExpectedValidationRecords(recommended="nop", allowed=["domain10"]),
|
||||
20: ExpectedValidationRecords(recommended="nop", allowed=["domain20"]),
|
||||
},
|
||||
)
|
||||
|
||||
assert is_mx_equivalent(
|
||||
mx_domains=[MxRecord(5, "domain1"), MxRecord(10, "domain2")],
|
||||
ref_mx_domains=[MxRecord(10, "domain1"), MxRecord(20, "domain2")],
|
||||
mx_domains={5: ["domain1"], 10: ["domain2"]},
|
||||
expected_mx_domains={
|
||||
10: ExpectedValidationRecords(recommended="nop", allowed=["domain1"]),
|
||||
20: ExpectedValidationRecords(recommended="nop", allowed=["domain2"]),
|
||||
},
|
||||
)
|
||||
assert is_mx_equivalent(
|
||||
mx_domains=[
|
||||
MxRecord(5, "domain1"),
|
||||
MxRecord(10, "domain2"),
|
||||
MxRecord(20, "domain3"),
|
||||
],
|
||||
ref_mx_domains=[MxRecord(10, "domain1"), MxRecord(20, "domain2")],
|
||||
|
||||
assert not is_mx_equivalent(
|
||||
mx_domains={10: ["domain10", "domain11"], 20: ["domain20"]},
|
||||
expected_mx_domains={
|
||||
10: ExpectedValidationRecords(recommended="nop", allowed=["domain10"]),
|
||||
20: ExpectedValidationRecords(recommended="nop", allowed=["domain20"]),
|
||||
},
|
||||
)
|
||||
assert not is_mx_equivalent(
|
||||
mx_domains=[MxRecord(5, "domain1"), MxRecord(10, "domain2")],
|
||||
ref_mx_domains=[
|
||||
MxRecord(10, "domain1"),
|
||||
MxRecord(20, "domain2"),
|
||||
MxRecord(20, "domain3"),
|
||||
],
|
||||
mx_domains={5: ["domain1"], 10: ["domain2"], 20: ["domain3"]},
|
||||
expected_mx_domains={
|
||||
10: ExpectedValidationRecords(recommended="nop", allowed=["domain1"]),
|
||||
20: ExpectedValidationRecords(recommended="nop", allowed=["domain2"]),
|
||||
},
|
||||
)
|
||||
assert not is_mx_equivalent(
|
||||
mx_domains={10: ["domain1"]},
|
||||
expected_mx_domains={
|
||||
10: ExpectedValidationRecords(recommended="nop", allowed=["domain1"]),
|
||||
20: ExpectedValidationRecords(recommended="nop", allowed=["domain2"]),
|
||||
},
|
||||
)
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user