• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

mozilla / fx-private-relay / d3128616-238d-446e-82c5-ab66cd38ceaf

09 May 2024 06:22PM CUT coverage: 84.07% (-0.6%) from 84.64%
d3128616-238d-446e-82c5-ab66cd38ceaf

push

circleci

web-flow
Merge pull request #4684 from mozilla/enable-flak8-bandit-checks-mpp-3802

fix MPP-3802: stop ignoring bandit security checks

3601 of 4734 branches covered (76.07%)

Branch coverage included in aggregate %.

74 of 158 new or added lines in 24 files covered. (46.84%)

5 existing lines in 5 files now uncovered.

14686 of 17018 relevant lines covered (86.3%)

10.86 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

78.69
/emails/apps.py
1
import logging
1✔
2
import os
1✔
3

4
from django.apps import AppConfig, apps
1✔
5
from django.conf import settings
1✔
6
from django.utils.functional import cached_property
1✔
7

8
import boto3
1✔
9
from botocore.config import Config
1✔
10
from mypy_boto3_ses.client import SESClient
1✔
11

12
logger = logging.getLogger("events")
1✔
13

14

15
class EmailsConfig(AppConfig):
1✔
16
    name = "emails"
1✔
17

18
    @cached_property
1✔
19
    def ses_client(self) -> SESClient | None:
1✔
20
        try:
×
21
            return boto3.client("ses", region_name=settings.AWS_REGION)
×
22
        except Exception:
×
23
            logger.exception("exception during SES connect")
×
24
            return None
×
25

26
    @cached_property
1✔
27
    def s3_client(self):
1✔
28
        try:
×
29
            s3_config = Config(
×
30
                region_name=settings.AWS_REGION,
31
                retries={
32
                    # max_attempts includes the initial attempt to get the email
33
                    # so this does not retry with backoff, to avoid timeouts
34
                    "max_attempts": 1,
35
                    "mode": "standard",
36
                },
37
            )
38
            return boto3.client("s3", config=s3_config)
×
39
        except Exception:
×
40
            logger.exception("exception during S3 connect")
×
41

42
    def __init__(self, app_name, app_module):
1✔
43
        super().__init__(app_name, app_module)
1✔
44

45
        # badwords file from:
46
        # https://www.cs.cmu.edu/~biglou/resources/bad-words.txt
47
        # Using `.text` extension because of
48
        # https://github.com/dependabot/dependabot-core/issues/1657
49
        self.badwords = self._load_terms("badwords.text")
1✔
50
        self.blocklist = self._load_terms("blocklist.text")
1✔
51

52
    def _load_terms(self, filename):
1✔
53
        terms = []
1✔
54
        terms_file_path = os.path.join(settings.BASE_DIR, "emails", filename)
1✔
55
        with open(terms_file_path) as terms_file:
1✔
56
            for word in terms_file:
1✔
57
                if len(word.strip()) > 0 and word.strip()[0] == "#":
1✔
58
                    continue
1✔
59
                terms.append(word.strip())
1✔
60
        return terms
1✔
61

62
    def ready(self):
1✔
63
        import emails.signals  # noqa: F401 (imported but unused warning)
1✔
64

65

66
def emails_config() -> EmailsConfig:
1✔
67
    emails_config = apps.get_app_config("emails")
1✔
68
    if not isinstance(emails_config, EmailsConfig):
1!
NEW
69
        raise TypeError("emails_config must be type EmailsConfig")
×
70
    return emails_config
1✔
71

72

73
def ses_client() -> SESClient | None:
1✔
74
    return emails_config().ses_client
1✔
75

76

77
def s3_client():
1✔
78
    return emails_config().s3_client
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc