summaryrefslogtreecommitdiff
path: root/tests/test-csp-hash.py
diff options
context:
space:
mode:
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)