4.64.1
Some checks failed
Build-Release-Image / Build-Image (linux/amd64) (push) Successful in 2m58s
Build-Release-Image / Build-Image (linux/arm64) (push) Failing after 17m22s
Build-Release-Image / Merge-Images (push) Has been skipped
Build-Release-Image / Create-Release (push) Has been skipped
Build-Release-Image / Notify (push) Has been skipped
Some checks failed
Build-Release-Image / Build-Image (linux/amd64) (push) Successful in 2m58s
Build-Release-Image / Build-Image (linux/arm64) (push) Failing after 17m22s
Build-Release-Image / Merge-Images (push) Has been skipped
Build-Release-Image / Create-Release (push) Has been skipped
Build-Release-Image / Notify (push) Has been skipped
This commit is contained in:
@ -1,10 +1,11 @@
|
||||
from flask import url_for
|
||||
from app.models import Coupon
|
||||
|
||||
from app.models import Coupon, LifetimeCoupon
|
||||
from app.utils import random_string
|
||||
from tests.utils import login
|
||||
|
||||
|
||||
def test_use_coupon(flask_client):
|
||||
def test_redeem_coupon_without_subscription(flask_client):
|
||||
user = login(flask_client)
|
||||
code = random_string(10)
|
||||
Coupon.create(code=code, nb_year=1, commit=True)
|
||||
@ -14,7 +15,22 @@ def test_use_coupon(flask_client):
|
||||
data={"code": code},
|
||||
)
|
||||
|
||||
assert r.status_code == 302
|
||||
assert r.status_code == 200
|
||||
coupon = Coupon.get_by(code=code)
|
||||
assert coupon.used
|
||||
assert coupon.used_by_user_id == user.id
|
||||
|
||||
|
||||
def test_redeem_lifetime_coupon(flask_client):
|
||||
login(flask_client)
|
||||
code = random_string(10)
|
||||
LifetimeCoupon.create(code=code, nb_used=1, commit=True)
|
||||
|
||||
r = flask_client.post(
|
||||
url_for("dashboard.lifetime_licence"),
|
||||
data={"code": code},
|
||||
)
|
||||
|
||||
assert r.status_code == 302
|
||||
coupon = LifetimeCoupon.get_by(code=code)
|
||||
assert coupon.nb_used == 0
|
||||
|
21
app/tests/example_emls/multi_reply_to.eml
Normal file
21
app/tests/example_emls/multi_reply_to.eml
Normal file
@ -0,0 +1,21 @@
|
||||
X-SimpleLogin-Client-IP: 54.39.200.130
|
||||
Received-SPF: Softfail (mailfrom) identity=mailfrom; client-ip=34.59.200.130;
|
||||
helo=relay.somewhere.net; envelope-from=everwaste@gmail.com;
|
||||
receiver=<UNKNOWN>
|
||||
Received: from relay.somewhere.net (relay.somewhere.net [34.59.200.130])
|
||||
(using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits))
|
||||
(No client certificate requested)
|
||||
by mx1.sldev.ovh (Postfix) with ESMTPS id 6D8C13F069
|
||||
for <wehrman_mannequin@sldev.ovh>; Thu, 17 Mar 2022 16:50:20 +0000 (UTC)
|
||||
Date: Thu, 17 Mar 2022 16:50:18 +0000
|
||||
To: {{ alias_email }}
|
||||
From: somewhere@rainbow.com
|
||||
Reply-To: 666-Mail Test <a1@mailcstest.com>, 777-Mail Test <a2@mailcstest.com>,
|
||||
888-Mail Test <a3@mailcstest.com>, - 5 at mailcstest.com" <a4@simplelogin.co>
|
||||
Subject: test Thu, 17 Mar 2022 16:50:18 +0000
|
||||
Message-Id: <20220317165018.000191@somewhere-5488dd4b6b-7crp6>
|
||||
X-Mailer: swaks v20201014.0 jetmore.org/john/code/swaks/
|
||||
X-Rspamd-Queue-Id: 6D8C13F069
|
||||
X-Rspamd-Server: staging1
|
||||
|
||||
This is a test mailing
|
33
app/tests/handler/test_reply_to.py
Normal file
33
app/tests/handler/test_reply_to.py
Normal file
@ -0,0 +1,33 @@
|
||||
from aiosmtpd.smtp import Envelope
|
||||
|
||||
import email_handler
|
||||
from app.email import status, headers
|
||||
from app.email_utils import get_header_unicode, parse_full_address
|
||||
|
||||
from app.mail_sender import mail_sender
|
||||
from app.models import Alias, Contact
|
||||
from tests.utils import create_new_user, load_eml_file
|
||||
|
||||
|
||||
@mail_sender.store_emails_test_decorator
|
||||
def test_multi_reply_to():
|
||||
user = create_new_user()
|
||||
alias = Alias.create_new_random(user)
|
||||
envelope = Envelope()
|
||||
envelope.mail_from = "env.somewhere"
|
||||
envelope.rcpt_tos = [alias.email]
|
||||
msg = load_eml_file("multi_reply_to.eml", {"alias_email": alias.email})
|
||||
alias_id = alias.id
|
||||
result = email_handler.MailHandler()._handle(envelope, msg)
|
||||
assert result == status.E200
|
||||
sent_emails = mail_sender.get_stored_emails()
|
||||
assert 1 == len(sent_emails)
|
||||
msg = sent_emails[0].msg
|
||||
reply_to = get_header_unicode(msg[headers.REPLY_TO])
|
||||
entries = reply_to.split(",")
|
||||
assert 4 == len(entries)
|
||||
for entry in entries:
|
||||
dummy, email = parse_full_address(entry)
|
||||
contact = Contact.get_by(reply_email=email)
|
||||
assert contact is not None
|
||||
assert contact.alias_id == alias_id
|
159
app/tests/test_coupon_utils.py
Normal file
159
app/tests/test_coupon_utils.py
Normal file
@ -0,0 +1,159 @@
|
||||
import arrow
|
||||
import pytest
|
||||
|
||||
from app.coupon_utils import (
|
||||
redeem_coupon,
|
||||
CouponUserCannotRedeemError,
|
||||
redeem_lifetime_coupon,
|
||||
)
|
||||
from app.models import (
|
||||
Coupon,
|
||||
Subscription,
|
||||
ManualSubscription,
|
||||
AppleSubscription,
|
||||
CoinbaseSubscription,
|
||||
LifetimeCoupon,
|
||||
User,
|
||||
)
|
||||
from tests.utils import create_new_user, random_string
|
||||
|
||||
|
||||
def test_use_coupon():
|
||||
user = create_new_user()
|
||||
code = random_string(10)
|
||||
Coupon.create(code=code, nb_year=1, commit=True)
|
||||
|
||||
coupon = redeem_coupon(code, user)
|
||||
assert coupon
|
||||
|
||||
coupon = Coupon.get_by(code=code)
|
||||
assert coupon
|
||||
assert coupon.used
|
||||
assert coupon.used_by_user_id == user.id
|
||||
|
||||
sub = user.get_active_subscription()
|
||||
assert isinstance(sub, ManualSubscription)
|
||||
left = sub.end_at - arrow.utcnow()
|
||||
assert left.days > 364
|
||||
|
||||
|
||||
def test_use_coupon_extend_manual_sub():
|
||||
user = create_new_user()
|
||||
initial_end = arrow.now().shift(days=15)
|
||||
ManualSubscription.create(
|
||||
user_id=user.id,
|
||||
end_at=initial_end,
|
||||
flush=True,
|
||||
)
|
||||
code = random_string(10)
|
||||
Coupon.create(code=code, nb_year=1, commit=True)
|
||||
|
||||
coupon = redeem_coupon(code, user)
|
||||
assert coupon
|
||||
|
||||
coupon = Coupon.get_by(code=code)
|
||||
assert coupon
|
||||
assert coupon.used
|
||||
assert coupon.used_by_user_id == user.id
|
||||
|
||||
sub = user.get_active_subscription()
|
||||
assert isinstance(sub, ManualSubscription)
|
||||
left = sub.end_at - initial_end
|
||||
assert left.days > 364
|
||||
|
||||
|
||||
def test_coupon_with_subscription():
|
||||
user = create_new_user()
|
||||
end_at = arrow.utcnow().shift(days=1).replace(hour=0, minute=0, second=0)
|
||||
Subscription.create(
|
||||
user_id=user.id,
|
||||
cancel_url="",
|
||||
update_url="",
|
||||
subscription_id=random_string(10),
|
||||
event_time=arrow.now(),
|
||||
next_bill_date=end_at.date(),
|
||||
plan="yearly",
|
||||
flush=True,
|
||||
)
|
||||
with pytest.raises(CouponUserCannotRedeemError):
|
||||
redeem_coupon("", user)
|
||||
|
||||
|
||||
def test_webhook_with_apple_subscription():
|
||||
user = create_new_user()
|
||||
end_at = arrow.utcnow().shift(days=2).replace(hour=0, minute=0, second=0)
|
||||
AppleSubscription.create(
|
||||
user_id=user.id,
|
||||
receipt_data=arrow.now().date().strftime("%Y-%m-%d"),
|
||||
expires_date=end_at.date().strftime("%Y-%m-%d"),
|
||||
original_transaction_id=random_string(10),
|
||||
plan="yearly",
|
||||
product_id="",
|
||||
flush=True,
|
||||
)
|
||||
with pytest.raises(CouponUserCannotRedeemError):
|
||||
redeem_coupon("", user)
|
||||
|
||||
|
||||
def test_webhook_with_coinbase_subscription():
|
||||
user = create_new_user()
|
||||
end_at = arrow.utcnow().shift(days=3).replace(hour=0, minute=0, second=0)
|
||||
CoinbaseSubscription.create(
|
||||
user_id=user.id, end_at=end_at.date().strftime("%Y-%m-%d"), flush=True
|
||||
)
|
||||
|
||||
with pytest.raises(CouponUserCannotRedeemError):
|
||||
redeem_coupon("", user)
|
||||
|
||||
|
||||
def test_expired_coupon():
|
||||
user = create_new_user()
|
||||
code = random_string(10)
|
||||
Coupon.create(
|
||||
code=code, nb_year=1, commit=True, expires_date=arrow.utcnow().shift(days=-1)
|
||||
)
|
||||
|
||||
coupon = redeem_coupon(code, user)
|
||||
assert coupon is None
|
||||
|
||||
|
||||
def test_used_coupon():
|
||||
user = create_new_user()
|
||||
code = random_string(10)
|
||||
Coupon.create(code=code, nb_year=1, commit=True, used=True)
|
||||
coupon = redeem_coupon(code, user)
|
||||
assert coupon is None
|
||||
|
||||
|
||||
# Lifetime
|
||||
def test_lifetime_coupon():
|
||||
user = create_new_user()
|
||||
code = random_string(10)
|
||||
LifetimeCoupon.create(code=code, nb_used=1)
|
||||
coupon = redeem_lifetime_coupon(code, user)
|
||||
assert coupon
|
||||
user = User.get(user.id)
|
||||
assert user.lifetime
|
||||
assert not user.paid_lifetime
|
||||
|
||||
|
||||
def test_lifetime_paid_coupon():
|
||||
user = create_new_user()
|
||||
code = random_string(10)
|
||||
LifetimeCoupon.create(code=code, nb_used=1, paid=True)
|
||||
coupon = redeem_lifetime_coupon(code, user)
|
||||
assert coupon
|
||||
user = User.get(user.id)
|
||||
assert user.lifetime
|
||||
assert user.paid_lifetime
|
||||
|
||||
|
||||
def test_used_lifetime_coupon():
|
||||
user = create_new_user()
|
||||
code = random_string(10)
|
||||
LifetimeCoupon.create(code=code, nb_used=0, paid=True)
|
||||
coupon = redeem_lifetime_coupon(code, user)
|
||||
assert coupon is None
|
||||
user = User.get(user.id)
|
||||
assert not user.lifetime
|
||||
assert not user.paid_lifetime
|
@ -1,3 +1,4 @@
|
||||
import re
|
||||
from typing import Optional
|
||||
|
||||
import arrow
|
||||
@ -6,7 +7,11 @@ import pytest
|
||||
from app import mailbox_utils, config
|
||||
from app.db import Session
|
||||
from app.mail_sender import mail_sender
|
||||
from app.mailbox_utils import MailboxEmailChangeError, get_mailbox_for_reply_phase
|
||||
from app.mailbox_utils import (
|
||||
MailboxEmailChangeError,
|
||||
get_mailbox_for_reply_phase,
|
||||
request_mailbox_email_change,
|
||||
)
|
||||
from app.models import (
|
||||
Mailbox,
|
||||
MailboxActivation,
|
||||
@ -361,6 +366,24 @@ def test_verify_ok():
|
||||
assert mailbox.verified
|
||||
|
||||
|
||||
@mail_sender.store_emails_test_decorator
|
||||
def test_verify_ok_for_mailbox_email_change():
|
||||
out_create = mailbox_utils.create_mailbox(user, random_email(), verified=True)
|
||||
mailbox_id = out_create.mailbox.id
|
||||
new_email = f"new{out_create.mailbox.email}"
|
||||
out_change = mailbox_utils.request_mailbox_email_change(
|
||||
user, out_create.mailbox, new_email
|
||||
)
|
||||
assert out_change.activation.code is not None
|
||||
mailbox_utils.verify_mailbox_code(user, mailbox_id, out_change.activation.code)
|
||||
activation = MailboxActivation.get_by(mailbox_id=out_create.mailbox.id)
|
||||
assert activation is None
|
||||
mailbox = Mailbox.get(id=out_create.mailbox.id)
|
||||
assert mailbox.verified
|
||||
assert mailbox.email == new_email
|
||||
assert mailbox.new_email is None
|
||||
|
||||
|
||||
# perform_mailbox_email_change
|
||||
def test_perform_mailbox_email_change_invalid_id():
|
||||
res = mailbox_utils.perform_mailbox_email_change(99999)
|
||||
@ -507,3 +530,71 @@ def test_get_mailbox_from_mail_from_coming_from_header_if_domain_is_not_aligned(
|
||||
|
||||
mb = get_mailbox_for_reply_phase(envelope_from, mail_from, alias)
|
||||
assert mb is None
|
||||
|
||||
|
||||
@mail_sender.store_emails_test_decorator
|
||||
def test_change_mailbox_address(flask_client):
|
||||
user = create_new_user()
|
||||
domain = f"{random_string(10)}.com"
|
||||
mail1 = f"mail_1@{domain}"
|
||||
mbox = Mailbox.create(email=mail1, user_id=user.id, verified=True, flush=True)
|
||||
mail2 = f"mail_2@{domain}"
|
||||
out = request_mailbox_email_change(user, mbox, mail2)
|
||||
changed_mailbox = Mailbox.get(mbox.id)
|
||||
assert changed_mailbox.new_email == mail2
|
||||
assert out.activation.mailbox_id == changed_mailbox.id
|
||||
assert re.match("^[0-9]+$", out.activation.code) is None
|
||||
assert 1 == len(mail_sender.get_stored_emails())
|
||||
mail_sent = mail_sender.get_stored_emails()[0]
|
||||
mail_contents = str(mail_sent.msg)
|
||||
assert mail_contents.find(config.URL) > 0
|
||||
assert mail_contents.find(out.activation.code) > 0
|
||||
assert mail_sent.envelope_to == mail2
|
||||
|
||||
|
||||
@mail_sender.store_emails_test_decorator
|
||||
def test_change_mailbox_address_without_verification_email(flask_client):
|
||||
user = create_new_user()
|
||||
domain = f"{random_string(10)}.com"
|
||||
mail1 = f"mail_1@{domain}"
|
||||
mbox = Mailbox.create(email=mail1, user_id=user.id, verified=True, flush=True)
|
||||
mail2 = f"mail_2@{domain}"
|
||||
out = request_mailbox_email_change(user, mbox, mail2, send_email=False)
|
||||
changed_mailbox = Mailbox.get(mbox.id)
|
||||
assert changed_mailbox.new_email == mail2
|
||||
assert out.activation.mailbox_id == changed_mailbox.id
|
||||
assert re.match("^[0-9]+$", out.activation.code) is None
|
||||
assert 0 == len(mail_sender.get_stored_emails())
|
||||
|
||||
|
||||
@mail_sender.store_emails_test_decorator
|
||||
def test_change_mailbox_address_with_code(flask_client):
|
||||
user = create_new_user()
|
||||
domain = f"{random_string(10)}.com"
|
||||
mail1 = f"mail_1@{domain}"
|
||||
mbox = Mailbox.create(email=mail1, user_id=user.id, verified=True, flush=True)
|
||||
mail2 = f"mail_2@{domain}"
|
||||
out = request_mailbox_email_change(user, mbox, mail2, use_digit_codes=True)
|
||||
changed_mailbox = Mailbox.get(mbox.id)
|
||||
assert changed_mailbox.new_email == mail2
|
||||
assert out.activation.mailbox_id == changed_mailbox.id
|
||||
assert re.match("^[0-9]+$", out.activation.code) is not None
|
||||
assert 1 == len(mail_sender.get_stored_emails())
|
||||
mail_sent = mail_sender.get_stored_emails()[0]
|
||||
mail_contents = str(mail_sent.msg)
|
||||
assert mail_contents.find(config.URL) > 0
|
||||
assert mail_contents.find(out.activation.code) > 0
|
||||
assert mail_sent.envelope_to == mail2
|
||||
|
||||
|
||||
def test_change_mailbox_verified_address(flask_client):
|
||||
user = create_new_user()
|
||||
domain = f"{random_string(10)}.com"
|
||||
mail1 = f"mail_1@{domain}"
|
||||
mbox = Mailbox.create(email=mail1, user_id=user.id, verified=True, flush=True)
|
||||
mail2 = f"mail_2@{domain}"
|
||||
out = request_mailbox_email_change(user, mbox, mail2, email_ownership_verified=True)
|
||||
changed_mailbox = Mailbox.get(mbox.id)
|
||||
assert changed_mailbox.email == mail2
|
||||
assert out.activation is None
|
||||
assert 0 == len(mail_sender.get_stored_emails())
|
||||
|
Reference in New Issue
Block a user