Skip to content

armgit / zulip

Public Imported from GitHub
0

Zulip server and web application. Open-source team chat that helps teams stay productive and focused.

test_stripe: Normalize CSP / Reporting header nonces.

Aman Agrawal96a1f810a615
diff --git a/corporate/lib/test_stripe_class.py b/corporate/lib/test_stripe_class.py
index fa29a77f280..bee1942d5a7 100644
--- a/corporate/lib/test_stripe_class.py
+++ b/corporate/lib/test_stripe_class.py
@@ -260,6 +260,9 @@ def normalize_fixture_data(decorated_function: CallableT) -> None: # nocoverage
r"\1client_secret\2NORMALIZED\3",
file_content,
)
+ # Stripe's CSP / Reporting headers carry a per-response random
+ # ``?q=<token>`` that's unrelated to anything we test.
+ file_content = re.sub(r"\?q=[\w-]+", "?q=NORMALIZED", file_content)
# Dates
file_content = re.sub(r'(?<="Date": )"(.* GMT)"', '"NORMALIZED DATETIME"', file_content)
file_content = re.sub(r"[0-3]\d [A-Z][a-z]{2} 20[1-2]\d", "NORMALIZED DATE", file_content)
diff --git a/corporate/tests/stripe_fixtures/card_attached_to_customer_but_payment_fails--Invoice.pay.1.json b/corporate/tests/stripe_fixtures/card_attached_to_customer_but_payment_fails--Invoice.pay.1.json
index 20a3dec6c4f..33ea71fed42 100644
--- a/corporate/tests/stripe_fixtures/card_attached_to_customer_but_payment_fails--Invoice.pay.1.json
+++ b/corporate/tests/stripe_fixtures/card_attached_to_customer_but_payment_fails--Invoice.pay.1.json
@@ -196,7 +196,7 @@
"Cache-Control": "no-cache, no-store",
"Connection": "keep-alive",
"Content-Length": "5521",
- "Content-Security-Policy": "base-uri 'none'; default-src 'none'; form-action 'none'; frame-ancestors 'none'; img-src 'self'; script-src 'self' 'report-sample'; style-src 'self'; worker-src 'none'; upgrade-insecure-requests; report-uri https://q.stripe.com/csp-violation?q=kLfPfx2HhngGH4OXW3QNuWE1S2_gVK0u8e4llr0D2d7xwJ06Tpo8OdyAiKhx5i96CuFU9UP_LP1tKqhn",
+ "Content-Security-Policy": "base-uri 'none'; default-src 'none'; form-action 'none'; frame-ancestors 'none'; img-src 'self'; script-src 'self' 'report-sample'; style-src 'self'; worker-src 'none'; upgrade-insecure-requests; report-uri https://q.stripe.com/csp-violation?q=NORMALIZED",
"Content-Type": "application/json",
"Date": "NORMALIZED DATETIME",
"Idempotency-Key": "00000000-0000-0000-0000-000000000000",
diff --git a/corporate/tests/stripe_fixtures/replace_payment_method--Invoice.pay.2.json b/corporate/tests/stripe_fixtures/replace_payment_method--Invoice.pay.2.json
index 563cd729bfe..84978ade467 100644
--- a/corporate/tests/stripe_fixtures/replace_payment_method--Invoice.pay.2.json
+++ b/corporate/tests/stripe_fixtures/replace_payment_method--Invoice.pay.2.json
@@ -196,7 +196,7 @@
"Cache-Control": "no-cache, no-store",
"Connection": "keep-alive",
"Content-Length": "5502",
- "Content-Security-Policy": "base-uri 'none'; default-src 'none'; form-action 'none'; frame-ancestors 'none'; img-src 'self'; script-src 'self' 'report-sample'; style-src 'self'; worker-src 'none'; upgrade-insecure-requests; report-uri https://q.stripe.com/csp-violation?q=kLfPfx2HhngGH4OXW3QNuWE1S2_gVK0u8e4llr0D2d7xwJ06Tpo8OdyAiKhx5i96CuFU9UP_LP1tKqhn",
+ "Content-Security-Policy": "base-uri 'none'; default-src 'none'; form-action 'none'; frame-ancestors 'none'; img-src 'self'; script-src 'self' 'report-sample'; style-src 'self'; worker-src 'none'; upgrade-insecure-requests; report-uri https://q.stripe.com/csp-violation?q=NORMALIZED",
"Content-Type": "application/json",
"Date": "NORMALIZED DATETIME",
"Idempotency-Key": "00000000-0000-0000-0000-000000000000",
diff --git a/corporate/tests/stripe_fixtures/replace_payment_method--SetupIntent.create.2.json b/corporate/tests/stripe_fixtures/replace_payment_method--SetupIntent.create.2.json
index 4ffbdba6168..4c6d7ade807 100644
--- a/corporate/tests/stripe_fixtures/replace_payment_method--SetupIntent.create.2.json
+++ b/corporate/tests/stripe_fixtures/replace_payment_method--SetupIntent.create.2.json
@@ -169,7 +169,7 @@
"Cache-Control": "no-cache, no-store",
"Connection": "keep-alive",
"Content-Length": "4636",
- "Content-Security-Policy": "base-uri 'none'; default-src 'none'; form-action 'none'; frame-ancestors 'none'; img-src 'self'; script-src 'self' 'report-sample'; style-src 'self'; worker-src 'none'; upgrade-insecure-requests; report-uri https://q.stripe.com/csp-violation?q=kLfPfx2HhngGH4OXW3QNuWE1S2_gVK0u8e4llr0D2d7xwJ06Tpo8OdyAiKhx5i96CuFU9UP_LP1tKqhn",
+ "Content-Security-Policy": "base-uri 'none'; default-src 'none'; form-action 'none'; frame-ancestors 'none'; img-src 'self'; script-src 'self' 'report-sample'; style-src 'self'; worker-src 'none'; upgrade-insecure-requests; report-uri https://q.stripe.com/csp-violation?q=NORMALIZED",
"Content-Type": "application/json",
"Date": "NORMALIZED DATETIME",
"Idempotency-Key": "00000000-0000-0000-0000-000000000000",