Skip to content

Commit

Permalink
feat: add support for script integrity and cross-origin attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
d9pouces committed Dec 29, 2023
1 parent 1b02df5 commit 086be77
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
5 changes: 3 additions & 2 deletions pipeline/packager.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def manifest(self):
def compiler_options(self):
return self.config.get("compiler_options", {})

@lru_cache()
@lru_cache
def get_sri(self, path):
method = self.config.get("integrity")
if method not in {"sha256", "sha384", "sha512"}:
Expand All @@ -75,7 +75,8 @@ def get_sri(self, path):
h = getattr(hashlib, method)()
for data in iter(lambda: fd.read(16384), b""):
h.update(data)
return "%s-%s" % (method, base64.b64encode(h.digest()).decode())
digest = base64.b64encode(h.digest()).decode()
return f"{method}-{digest}"
return None


Expand Down
3 changes: 2 additions & 1 deletion tests/tests/test_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,8 @@ def test_sri_sha512(self):
def get_integrity(path, method):
with staticfiles_storage.open(path) as fd:
h = getattr(hashlib, method)(fd.read())
return "%s-%s" % (method, base64.b64encode(h.digest()).decode())
digest = base64.b64encode(h.digest()).decode()
return f"{method}-{digest}"


class DjangoTest(TestCase):
Expand Down

0 comments on commit 086be77

Please sign in to comment.