#!/usr/bin/env python3 """ Test script to verify that the stripe-signature header fix works correctly. """ import sys import os # Add the gateway directory to the path sys.path.insert(0, os.path.dirname(os.path.abspath(__file__))) def test_stripe_signature_in_forwardable_headers(): """Test that stripe-signature is in the forwardable headers list.""" # Read the header manager file with open('app/core/header_manager.py', 'r') as f: content = f.read() # Check if stripe-signature is in the forwardable headers stripe_signature_header = "'stripe-signature'" if stripe_signature_header in content: print("✅ stripe-signature header found in FORWARDABLE_HEADERS") return True else: print("❌ stripe-signature header NOT found in FORWARDABLE_HEADERS") return False def test_stripe_signature_comment(): """Test that there's a comment explaining why stripe-signature is needed.""" # Read the header manager file with open('app/core/header_manager.py', 'r') as f: content = f.read() # Check if there's a comment about Stripe webhook signature verification comment = "Required for Stripe webhook signature verification" if comment in content: print("✅ Comment found explaining stripe-signature requirement") return True else: print("❌ Comment NOT found explaining stripe-signature requirement") return False def main(): """Run all tests.""" print("Testing stripe-signature header fix...") print() tests = [ test_stripe_signature_in_forwardable_headers, test_stripe_signature_comment, ] results = [] for test in tests: try: result = test() results.append(result) except Exception as e: print(f"❌ Error running {test.__name__}: {e}") results.append(False) print() if all(results): print("🎉 All tests passed! stripe-signature header should now be forwarded.") print() print("Summary of changes:") print("- Added 'stripe-signature' to FORWARDABLE_HEADERS list") print("- This ensures the Stripe signature is forwarded to tenant service") print("- Tenant service can now verify webhook signatures correctly") return True else: print("❌ Some tests failed. stripe-signature header may not be forwarded correctly.") return False if __name__ == "__main__": success = main() sys.exit(0 if success else 1)