mirror of
https://github.com/jwinterm/modoboa.git
synced 2026-10-17 05:41:25 +02:00
Improved coverage
This commit is contained in:
@@ -1,33 +0,0 @@
|
||||
"""Modoboa amavis constants."""
|
||||
|
||||
import collections
|
||||
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
|
||||
MESSAGE_TYPES = collections.OrderedDict(
|
||||
(
|
||||
("C", _("Clean")),
|
||||
("S", _("Spam")),
|
||||
("Y", _("Spammy")),
|
||||
("V", _("Virus")),
|
||||
("H", _("Bad Header")),
|
||||
("M", _("Bad MIME")),
|
||||
("B", _("Banned")),
|
||||
("O", _("Over sized")),
|
||||
("T", _("MTA error")),
|
||||
("U", _("Unchecked")),
|
||||
)
|
||||
)
|
||||
|
||||
MESSAGE_TYPE_COLORS = {
|
||||
"C": "success",
|
||||
"S": "danger",
|
||||
"Y": "warning",
|
||||
"V": "danger",
|
||||
"H": "warning",
|
||||
"M": "warning",
|
||||
"B": "warning",
|
||||
"O": "warning",
|
||||
"T": "warning",
|
||||
"U": "default",
|
||||
}
|
||||
@@ -3,13 +3,10 @@ import re
|
||||
import socket
|
||||
import struct
|
||||
from email.utils import parseaddr
|
||||
from functools import wraps
|
||||
|
||||
import idna
|
||||
|
||||
from django.conf import settings
|
||||
from django.contrib.auth.views import redirect_to_login
|
||||
from django.urls import reverse
|
||||
from django.utils.translation import gettext as _
|
||||
|
||||
from rest_framework import authentication, exceptions
|
||||
@@ -23,33 +20,6 @@ from .models import Msgrcpt, Policy, Users
|
||||
from .utils import smart_bytes, smart_str
|
||||
|
||||
|
||||
def selfservice(ssfunc=None):
|
||||
"""Decorator used to expose views to the 'self-service' feature
|
||||
|
||||
The 'self-service' feature allows users to act on quarantined
|
||||
messages without beeing authenticated.
|
||||
|
||||
This decorator only acts as a 'router'.
|
||||
|
||||
:param ssfunc: the function to call if the 'self-service'
|
||||
pre-requisites are satisfied
|
||||
"""
|
||||
|
||||
def decorator(f):
|
||||
@wraps(f)
|
||||
def wrapped_f(request, *args, **kwargs):
|
||||
secret_id = request.GET.get("secret_id")
|
||||
if not secret_id and request.user.is_authenticated:
|
||||
return f(request, *args, **kwargs)
|
||||
if not param_tools.get_global_parameter("self_service"):
|
||||
return redirect_to_login(reverse("modoboa_amavis:index"))
|
||||
return ssfunc(request, *args, **kwargs)
|
||||
|
||||
return wrapped_f
|
||||
|
||||
return decorator
|
||||
|
||||
|
||||
class SelfServiceAuthentication(authentication.BaseAuthentication):
|
||||
|
||||
def authenticate(self, request):
|
||||
|
||||
@@ -17,6 +17,21 @@ from modoboa.core import models as core_models
|
||||
from modoboa.lib.tests import ModoAPITestCase
|
||||
|
||||
|
||||
AMAVIS_SETTINGS = {
|
||||
"localpart_is_case_sensitive": False,
|
||||
"recipient_delimiter": "",
|
||||
"max_attachment_size": 14,
|
||||
"released_msgs_cleanup": False,
|
||||
"am_pdp_mode": "unix",
|
||||
"am_pdp_host": "localhost",
|
||||
"am_pdp_port": 9998,
|
||||
"user_can_release": False,
|
||||
"self_service": False,
|
||||
"manual_learning": True,
|
||||
"sa_is_local": True,
|
||||
}
|
||||
|
||||
|
||||
class TestDataMixin:
|
||||
"""A mixin to provide test data."""
|
||||
|
||||
@@ -71,6 +86,13 @@ class QuarantineViewSetTestCase(TestDataMixin, ModoAPITestCase):
|
||||
resp = self.client.get(f"{url}?rcpt={rcpt}")
|
||||
self.assertEqual(resp.status_code, 200)
|
||||
|
||||
user = core_models.User.objects.get(username="user@test.com")
|
||||
self.client.force_authenticate(user)
|
||||
resp = self.client.get(f"{url}?rcpt={rcpt}")
|
||||
self.assertEqual(resp.status_code, 200)
|
||||
self.msgrcpt.refresh_from_db()
|
||||
self.assertEqual(self.msgrcpt.rs, "V")
|
||||
|
||||
def test_headers(self):
|
||||
mail_id = smart_str(self.msgrcpt.mail.mail_id)
|
||||
url = reverse("v2:amavis-quarantine-headers", args=[mail_id])
|
||||
@@ -286,3 +308,12 @@ class PolicyViewSetTestCase(ModoAPITestCase):
|
||||
p = models.Policy.objects.get(users__email="@test.com")
|
||||
self.assertEqual(p.bypass_virus_checks, data["bypass_virus_checks"])
|
||||
self.assertEqual(p.spam_tag2_level, data["spam_tag2_level"])
|
||||
|
||||
|
||||
class ParametersAPITestCase(ModoAPITestCase):
|
||||
|
||||
def test_update(self):
|
||||
settings = AMAVIS_SETTINGS.copy()
|
||||
url = reverse("v2:parameter-global-detail", args=["core"])
|
||||
resp = self.client.put(url, settings, format="json")
|
||||
self.assertEqual(resp.status_code, 200)
|
||||
|
||||
Reference in New Issue
Block a user