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 Idempotency-Key response headers.

Aman Agrawal790916b8a8d2
diff --git a/corporate/lib/test_stripe_class.py b/corporate/lib/test_stripe_class.py
index 2ace43076ae..c951311a040 100644
--- a/corporate/lib/test_stripe_class.py
+++ b/corporate/lib/test_stripe_class.py
@@ -246,9 +246,12 @@ def normalize_fixture_data(decorated_function: CallableT) -> None: # nocoverage
file_content = file_content.replace(match, normalized_values[pattern][match])
file_content = re.sub(r'(?<="risk_score": )(\d+)', "0", file_content)
file_content = re.sub(r'(?<="times_redeemed": )(\d+)', "0", file_content)
+ # Idempotency keys appear as a lowercase JSON field ("idempotency_key") and
+ # as a response-header field ("Idempotency-Key"). Stripe assigns a fresh
+ # uuid for both on every call.
file_content = re.sub(
- r'(?<="idempotency_key": )"([0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12})"',
- '"00000000-0000-0000-0000-000000000000"',
+ r'(?<=")(idempotency_key|Idempotency-Key)": "[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}"',
+ r'\1": "00000000-0000-0000-0000-000000000000"',
file_content,
)
# Dates
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 49600576bea..ade1848df27 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
@@ -199,7 +199,7 @@
"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-Type": "application/json",
"Date": "NORMALIZED DATETIME",
- "Idempotency-Key": "9272ba50-417b-4661-a94d-92c78efe84f0",
+ "Idempotency-Key": "00000000-0000-0000-0000-000000000000",
"Original-Request": "req_NORMALIZED",
"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 26063c28ef6..2681b7c9568 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
@@ -199,7 +199,7 @@
"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-Type": "application/json",
"Date": "NORMALIZED DATETIME",
- "Idempotency-Key": "57eb0faa-3bf9-4416-90b1-99496c13b2ea",
+ "Idempotency-Key": "00000000-0000-0000-0000-000000000000",
"Original-Request": "req_NORMALIZED",
"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 434eed341a3..a1b2f92ecdc 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
@@ -172,7 +172,7 @@
"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-Type": "application/json",
"Date": "NORMALIZED DATETIME",
- "Idempotency-Key": "b8c44d16-3ebb-4d3b-99ed-d3f13e48d9a5",
+ "Idempotency-Key": "00000000-0000-0000-0000-000000000000",
"Original-Request": "req_NORMALIZED",
"Request-Id": "req_NORMALIZED",
"Server": "nginx",