Verified Commit f45aafc0 authored by Kevin Morris's avatar Kevin Morris
Browse files

Merge branch 'master' into live

parents 7869a354 2a393f95
Pipeline #16408 passed with stages
in 3 minutes and 35 seconds
...@@ -6,7 +6,7 @@ from typing import Any ...@@ -6,7 +6,7 @@ from typing import Any
# Publicly visible version of aurweb. This is used to display # Publicly visible version of aurweb. This is used to display
# aurweb versioning in the footer and must be maintained. # aurweb versioning in the footer and must be maintained.
# Todo: Make this dynamic/automated. # Todo: Make this dynamic/automated.
AURWEB_VERSION = "v6.0.22" AURWEB_VERSION = "v6.0.23"
_parser = None _parser = None
......
...@@ -104,7 +104,10 @@ class Notification: ...@@ -104,7 +104,10 @@ class Notification:
False: smtplib.SMTP, False: smtplib.SMTP,
True: smtplib.SMTP_SSL, True: smtplib.SMTP_SSL,
} }
server = classes[use_ssl](server_addr, server_port) smtp_timeout = aurweb.config.getint("notifications",
"smtp-timeout")
server = classes[use_ssl](server_addr, server_port,
timeout=smtp_timeout)
if use_starttls: if use_starttls:
server.ehlo() server.ehlo()
...@@ -399,10 +402,7 @@ class ComaintainershipEventNotification(Notification): ...@@ -399,10 +402,7 @@ class ComaintainershipEventNotification(Notification):
self._pkgbase = db.query(PackageBase.Name).filter( self._pkgbase = db.query(PackageBase.Name).filter(
PackageBase.ID == pkgbase_id).first().Name PackageBase.ID == pkgbase_id).first().Name
user = db.query(User).filter( user = db.query(User).filter(User.ID == uid).with_entities(
and_(User.ID == uid,
User.Suspended == 0)
).with_entities(
User.Email, User.Email,
User.LangPreference User.LangPreference
).first() ).first()
......
...@@ -37,6 +37,15 @@ class Email: ...@@ -37,6 +37,15 @@ class Email:
if autoparse: if autoparse:
self._parse() self._parse()
@staticmethod
def reset() -> None:
# Cleanup all email files for this test suite.
prefix = Email.email_prefix(suite=True)
files = os.listdir(Email.TEST_DIR)
for file in files:
if file.startswith(prefix):
os.remove(os.path.join(Email.TEST_DIR, file))
@staticmethod @staticmethod
def email_prefix(suite: bool = False) -> str: def email_prefix(suite: bool = False) -> str:
""" """
......
...@@ -36,6 +36,9 @@ class FakeSMTP: ...@@ -36,6 +36,9 @@ class FakeSMTP:
def quit(self) -> None: def quit(self) -> None:
self.quit_count += 1 self.quit_count += 1
def __call__(self, *args, **kwargs) -> "FakeSMTP":
return self
class FakeSMTP_SSL(FakeSMTP): class FakeSMTP_SSL(FakeSMTP):
""" A fake version of smtplib.SMTP_SSL used for testing. """ """ A fake version of smtplib.SMTP_SSL used for testing. """
......
...@@ -65,6 +65,7 @@ smtp-use-ssl = 0 ...@@ -65,6 +65,7 @@ smtp-use-ssl = 0
smtp-use-starttls = 0 smtp-use-starttls = 0
smtp-user = smtp-user =
smtp-password = smtp-password =
smtp-timeout = 60
sender = notify@aur.archlinux.org sender = notify@aur.archlinux.org
reply-to = noreply@aur.archlinux.org reply-to = noreply@aur.archlinux.org
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
# #
[tool.poetry] [tool.poetry]
name = "aurweb" name = "aurweb"
version = "v6.0.22" version = "v6.0.23"
license = "GPL-2.0-only" license = "GPL-2.0-only"
description = "Source code for the Arch User Repository's website" description = "Source code for the Arch User Repository's website"
homepage = "https://aur.archlinux.org" homepage = "https://aur.archlinux.org"
......
...@@ -299,6 +299,21 @@ You were removed from the co-maintainer list of {pkgbase.Name} [1]. ...@@ -299,6 +299,21 @@ You were removed from the co-maintainer list of {pkgbase.Name} [1].
assert email.body == expected assert email.body == expected
def test_suspended_ownership_change(user: User, pkgbases: List[PackageBase]):
with db.begin():
user.Suspended = 1
pkgbase = pkgbases[0]
notif = notify.ComaintainerAddNotification(user.ID, pkgbase.ID)
notif.send()
assert Email.count() == 1
Email.reset() # Clear the Email pool
notif = notify.ComaintainerRemoveNotification(user.ID, pkgbase.ID)
notif.send()
assert Email.count() == 1
def test_delete(user: User, user2: User, pkgbases: List[PackageBase]): def test_delete(user: User, user2: User, pkgbases: List[PackageBase]):
pkgbase = pkgbases[0] pkgbase = pkgbases[0]
notif = notify.DeleteNotification(user2.ID, pkgbase.ID) notif = notify.DeleteNotification(user2.ID, pkgbase.ID)
...@@ -532,18 +547,18 @@ def test_smtp(user: User): ...@@ -532,18 +547,18 @@ def test_smtp(user: User):
with db.begin(): with db.begin():
user.ResetKey = "12345678901234567890123456789012" user.ResetKey = "12345678901234567890123456789012"
SMTP = FakeSMTP() smtp = FakeSMTP()
get = "aurweb.config.get" get = "aurweb.config.get"
getboolean = "aurweb.config.getboolean" getboolean = "aurweb.config.getboolean"
with mock.patch(get, side_effect=mock_smtp_config(str)): with mock.patch(get, side_effect=mock_smtp_config(str)):
with mock.patch(getboolean, side_effect=mock_smtp_config(bool)): with mock.patch(getboolean, side_effect=mock_smtp_config(bool)):
with mock.patch("smtplib.SMTP", side_effect=lambda a, b: SMTP): with mock.patch("smtplib.SMTP", side_effect=smtp):
config.rehash() config.rehash()
notif = notify.WelcomeNotification(user.ID) notif = notify.WelcomeNotification(user.ID)
notif.send() notif.send()
config.rehash() config.rehash()
assert len(SMTP.emails) == 1 assert len(smtp.emails) == 1
def mock_smtp_starttls_config(cls): def mock_smtp_starttls_config(cls):
...@@ -571,25 +586,25 @@ def test_smtp_starttls(user: User): ...@@ -571,25 +586,25 @@ def test_smtp_starttls(user: User):
user.ResetKey = "12345678901234567890123456789012" user.ResetKey = "12345678901234567890123456789012"
user.BackupEmail = "backup@example.org" user.BackupEmail = "backup@example.org"
SMTP = FakeSMTP() smtp = FakeSMTP()
get = "aurweb.config.get" get = "aurweb.config.get"
getboolean = "aurweb.config.getboolean" getboolean = "aurweb.config.getboolean"
with mock.patch(get, side_effect=mock_smtp_starttls_config(str)): with mock.patch(get, side_effect=mock_smtp_starttls_config(str)):
with mock.patch( with mock.patch(
getboolean, side_effect=mock_smtp_starttls_config(bool)): getboolean, side_effect=mock_smtp_starttls_config(bool)):
with mock.patch("smtplib.SMTP", side_effect=lambda a, b: SMTP): with mock.patch("smtplib.SMTP", side_effect=smtp):
notif = notify.WelcomeNotification(user.ID) notif = notify.WelcomeNotification(user.ID)
notif.send() notif.send()
assert SMTP.starttls_enabled assert smtp.starttls_enabled
assert SMTP.user assert smtp.user
assert SMTP.passwd assert smtp.passwd
assert len(SMTP.emails) == 2 assert len(smtp.emails) == 2
to = SMTP.emails[0][1] to = smtp.emails[0][1]
assert to == [user.Email] assert to == [user.Email]
to = SMTP.emails[1][1] to = smtp.emails[1][1]
assert to == [user.BackupEmail] assert to == [user.BackupEmail]
...@@ -614,19 +629,19 @@ def test_smtp_ssl(user: User): ...@@ -614,19 +629,19 @@ def test_smtp_ssl(user: User):
with db.begin(): with db.begin():
user.ResetKey = "12345678901234567890123456789012" user.ResetKey = "12345678901234567890123456789012"
SMTP = FakeSMTP_SSL() smtp = FakeSMTP_SSL()
get = "aurweb.config.get" get = "aurweb.config.get"
getboolean = "aurweb.config.getboolean" getboolean = "aurweb.config.getboolean"
with mock.patch(get, side_effect=mock_smtp_ssl_config(str)): with mock.patch(get, side_effect=mock_smtp_ssl_config(str)):
with mock.patch(getboolean, side_effect=mock_smtp_ssl_config(bool)): with mock.patch(getboolean, side_effect=mock_smtp_ssl_config(bool)):
with mock.patch("smtplib.SMTP_SSL", side_effect=lambda a, b: SMTP): with mock.patch("smtplib.SMTP_SSL", side_effect=smtp):
notif = notify.WelcomeNotification(user.ID) notif = notify.WelcomeNotification(user.ID)
notif.send() notif.send()
assert len(SMTP.emails) == 1 assert len(smtp.emails) == 1
assert SMTP.use_ssl assert smtp.use_ssl
assert SMTP.user assert smtp.user
assert SMTP.passwd assert smtp.passwd
def test_notification_defaults(): def test_notification_defaults():
...@@ -640,6 +655,7 @@ def test_notification_oserror(user: User, caplog: pytest.LogCaptureFixture): ...@@ -640,6 +655,7 @@ def test_notification_oserror(user: User, caplog: pytest.LogCaptureFixture):
""" Try sending a notification with a bad SMTP configuration. """ """ Try sending a notification with a bad SMTP configuration. """
caplog.set_level(ERROR) caplog.set_level(ERROR)
config_get = config.get config_get = config.get
config_getint = config.getint
mocked_options = { mocked_options = {
"sendmail": str(), "sendmail": str(),
...@@ -647,8 +663,9 @@ def test_notification_oserror(user: User, caplog: pytest.LogCaptureFixture): ...@@ -647,8 +663,9 @@ def test_notification_oserror(user: User, caplog: pytest.LogCaptureFixture):
"smtp-port": "587", "smtp-port": "587",
"smtp-user": "notify@server.xyz", "smtp-user": "notify@server.xyz",
"smtp-password": "notify_server_xyz", "smtp-password": "notify_server_xyz",
"smtp-timeout": 1,
"sender": "notify@server.xyz", "sender": "notify@server.xyz",
"reply-to": "no-reply@server.xyz" "reply-to": "no-reply@server.xyz",
} }
def mock_config_get(section: str, key: str) -> str: def mock_config_get(section: str, key: str) -> str:
...@@ -657,9 +674,16 @@ def test_notification_oserror(user: User, caplog: pytest.LogCaptureFixture): ...@@ -657,9 +674,16 @@ def test_notification_oserror(user: User, caplog: pytest.LogCaptureFixture):
return mocked_options.get(key) return mocked_options.get(key)
return config_get(section, key) return config_get(section, key)
def mock_config_getint(section: str, key: str) -> str:
if section == "notifications":
if key in mocked_options:
return mocked_options.get(key)
return config_getint(section, key)
notif = notify.WelcomeNotification(user.ID) notif = notify.WelcomeNotification(user.ID)
with mock.patch("aurweb.config.get", side_effect=mock_config_get): with mock.patch("aurweb.config.getint", side_effect=mock_config_getint):
notif.send() with mock.patch("aurweb.config.get", side_effect=mock_config_get):
notif.send()
expected = "Unable to emit notification due to an OSError" expected = "Unable to emit notification due to an OSError"
assert expected in caplog.text assert expected in caplog.text
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment