summaryrefslogtreecommitdiff
path: root/tests/test-csp-hash.py
diff options
context:
space:
mode:
authorPreston Pan <ret2pop@nullring.xyz>2026-03-10 18:41:22 -0700
committerPreston Pan <ret2pop@nullring.xyz>2026-03-10 18:41:22 -0700
commit72d9b0f77016ff0058a2bda873c7bd71caa8649e (patch)
tree61aee33851fa27af655025f5c1bad8fae5cfecb6 /tests/test-csp-hash.py
parenta18bafba09090a113927b3e3cc639ce4962e8f5c (diff)
add csp hash test
Diffstat (limited to 'tests/test-csp-hash.py')
-rw-r--r--tests/test-csp-hash.py10
1 files changed, 10 insertions, 0 deletions
diff --git a/tests/test-csp-hash.py b/tests/test-csp-hash.py
new file mode 100644
index 0000000..8401979
--- /dev/null
+++ b/tests/test-csp-hash.py
@@ -0,0 +1,10 @@
+import sys, re, hashlib, base64
+html = open(sys.argv[1]).read()
+match = re.search(r'<style[^>]*>(.*?)</style>', html, re.DOTALL | re.IGNORECASE)
+if match:
+ content = match.group(1).encode('utf-8')
+ print(base64.b64encode(hashlib.sha256(content).digest()).decode())
+ exit(0)
+else:
+ print('Error: Still could not find a <style> tag in the HTML.')
+ exit(1)