• 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

23.81
/privaterelay/storage.py
1
"""
2
Staticfiles storage implementation for Relay.
3

4
This is used when running ./manage.py collectstatic, or rendering Django templates.
5
"""
6

7
from typing import Any
1✔
8

9
from whitenoise.storage import CompressedManifestStaticFilesStorage
1✔
10

11

12
class RelayStaticFilesStorage(CompressedManifestStaticFilesStorage):
1✔
13
    """
14
    Customize Whitenoise storage for Relay
15

16
    The Django ManifestStaticFilesStorage creates a copy of each file that
17
    includes a hash of its contents, and serves these with a long cache time.
18
    It also creates staticfiles/staticfiles.json that lists all the known static
19
    files, rather than scanning the folder for files at startup.
20

21
    The Whitenoise CompressedManifestStaticFilesStorage builds on this by
22
    pre-compressing files as well, so that the gzipped versions can be served.
23

24
    This class skips renaming files from Next.js, which already include hashes
25
    in the filenames.
26

27
    See:
28
    https://docs.djangoproject.com/en/4.2/ref/contrib/staticfiles/#manifeststaticfilesstorage
29
    http://whitenoise.evans.io/en/stable/django.html#add-compression-and-caching-support
30
    """
31

32
    def hashed_name(
1✔
33
        self, name: str, content: str | None = None, filename: str | None = None
34
    ) -> str:
35
        """Skip hashing filenames output by Next.js"""
36
        if name.startswith("_next/static/"):
×
37
            return name
×
38
        else:
39
            new_name = super().hashed_name(name, content, filename)
×
NEW
40
            if not isinstance(new_name, str):
×
NEW
41
                raise TypeError("new_name must be type str")
×
UNCOV
42
            return new_name
×
43

44
    def url_converter(
1✔
45
        self, name: str, hashed_files: dict[str, str], template: str | None = None
46
    ) -> Any:
47
        """
48
        Convert Next.js source map URL to absolute URL.
49

50
        If this changes, or other django.contrib.staticfiles changes adjust CSS output,
51
        then update the cache version in globals.scss and tokens.scss to bust the cache.
52
        """
53
        if (
×
54
            name.startswith("_next/static/css/")
55
            and name.endswith(".css")
56
            and template == "/*# sourceMappingURL=%(url)s */"
57
        ):
58
            path = name.rsplit("/", 1)[0]
×
59
            template = f"/*# sourceMappingURL={self.base_url}{path}/%(url)s */"
×
60
        return super().url_converter(name, hashed_files, template)
×
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