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 Stripe Report-To header value.

Aman Agrawalc64176a41c12
diff --git a/corporate/lib/test_stripe_class.py b/corporate/lib/test_stripe_class.py
index 14846a006a6..14d16ad6be3 100644
--- a/corporate/lib/test_stripe_class.py
+++ b/corporate/lib/test_stripe_class.py
@@ -331,6 +331,10 @@ def normalize_fixture_data(decorated_function: CallableT) -> None: # nocoverage
# 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)
+ # Stripe's ``Report-To`` response header carries an embedded
+ # JSON document as a string value. The value has no test
+ # relevance, so collapse it to a placeholder.
+ file_content = re.sub(r'(?<="Report-To": )".*"', '"NORMALIZED"', file_content)
# The ``webhooks_delivered_at`` field is null or a Unix timestamp,
# depending on when Stripe finishes delivering webhooks. We handle
# this race in fixture generation by normalizing on null.
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 1d07431accb..96ac12409df 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
@@ -16,7 +16,7 @@
"Date": "NORMALIZED DATETIME",
"Idempotency-Key": "00000000-0000-0000-0000-000000000000",
"Original-Request": "req_NORMALIZED",
- "Report-To": "{\"group\":\"csp\",\"max_age\":8640,\"endpoints\":[{\"url\":\"https://q.stripe.com/csp-report-v2?q=NORMALIZED&t=1\"}],\"include_subdomains\":true}",
+ "Report-To": "NORMALIZED",
"Reporting-Endpoints": "csp=\"https://q.stripe.com/csp-report-v2?q=NORMALIZED&t=1\"",
"Request-Id": "req_NORMALIZED",
"Server": "nginx",
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 03484965636..7b63af48ab4 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
@@ -16,7 +16,7 @@
"Date": "NORMALIZED DATETIME",
"Idempotency-Key": "00000000-0000-0000-0000-000000000000",
"Original-Request": "req_NORMALIZED",
- "Report-To": "{\"group\":\"csp\",\"max_age\":8640,\"endpoints\":[{\"url\":\"https://q.stripe.com/csp-report-v2?q=NORMALIZED&t=1\"}],\"include_subdomains\":true}",
+ "Report-To": "NORMALIZED",
"Reporting-Endpoints": "csp=\"https://q.stripe.com/csp-report-v2?q=NORMALIZED&t=1\"",
"Request-Id": "req_NORMALIZED",
"Server": "nginx",
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 0f826c289ee..fd5130ebf5b 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
@@ -16,7 +16,7 @@
"Date": "NORMALIZED DATETIME",
"Idempotency-Key": "00000000-0000-0000-0000-000000000000",
"Original-Request": "req_NORMALIZED",
- "Report-To": "{\"group\":\"csp\",\"max_age\":8640,\"endpoints\":[{\"url\":\"https://q.stripe.com/csp-report-v2?q=NORMALIZED&t=1\"}],\"include_subdomains\":true}",
+ "Report-To": "NORMALIZED",
"Reporting-Endpoints": "csp=\"https://q.stripe.com/csp-report-v2?q=NORMALIZED&t=1\"",
"Request-Id": "req_NORMALIZED",
"Server": "nginx",