diff --git a/examples/async_event_notification_handler_endpoint.py b/examples/async_event_notification_handler_endpoint.py index 2cad998ed..3a7f6a9ec 100644 --- a/examples/async_event_notification_handler_endpoint.py +++ b/examples/async_event_notification_handler_endpoint.py @@ -22,7 +22,7 @@ app = FastAPI() api_key = os.environ.get("STRIPE_API_KEY", "") -webhook_secret = os.environ.get("WEBHOOK_SECRET", "") +webhook_secret = os.environ["WEBHOOK_SECRET"] # Webhooks can be delivered more than once, so we track ids we've already # processed. In production, back this with something durable and shared diff --git a/examples/event_notification_handler_endpoint.py b/examples/event_notification_handler_endpoint.py index c1db46f13..b33b845b2 100644 --- a/examples/event_notification_handler_endpoint.py +++ b/examples/event_notification_handler_endpoint.py @@ -19,7 +19,7 @@ app = Flask(__name__) api_key = os.environ.get("STRIPE_API_KEY", "") -webhook_secret = os.environ.get("WEBHOOK_SECRET", "") +webhook_secret = os.environ["WEBHOOK_SECRET"] # Webhooks can be delivered more than once, so we track ids we've already # processed. In production, back this with something durable and shared diff --git a/examples/event_notification_webhook_handler.py b/examples/event_notification_webhook_handler.py index d05117c8c..6bfdb8cb2 100644 --- a/examples/event_notification_webhook_handler.py +++ b/examples/event_notification_webhook_handler.py @@ -25,7 +25,7 @@ app = Flask(__name__) api_key = os.environ.get("STRIPE_API_KEY", "") -webhook_secret = os.environ.get("WEBHOOK_SECRET", "") +webhook_secret = os.environ["WEBHOOK_SECRET"] client = StripeClient(api_key) diff --git a/examples/webhooks.py b/examples/webhooks.py index 79352b1a6..5f393bf00 100644 --- a/examples/webhooks.py +++ b/examples/webhooks.py @@ -6,7 +6,7 @@ # this is for handling v1-style Snapshot Events. # To handle v2-style Events, see `event_notification_webhook_handler.py` -webhook_secret = os.environ.get("WEBHOOK_SECRET") +webhook_secret = os.environ["WEBHOOK_SECRET"] app = Flask(__name__) diff --git a/tests/test_webhook.py b/tests/test_webhook.py index 9b1420a8d..08c9e20b7 100644 --- a/tests/test_webhook.py +++ b/tests/test_webhook.py @@ -274,6 +274,16 @@ def test_raise_on_v2_payload(self, stripe_mock_stripe_client): ) assert "parse_event_notification" in str(e.value) + @pytest.mark.parametrize("secret", [None, ""]) + def test_raise_on_missing_secret(self, stripe_mock_stripe_client, secret): + with pytest.raises( + SignatureVerificationError, + match="No webhook secret value was provided", + ): + stripe_mock_stripe_client.construct_event( + DUMMY_WEBHOOK_PAYLOAD, generate_header(), secret + ) + def test_construct_event_inherits_requestor(self, http_client_mock): http_client_mock.stub_request("delete", "/v1/terminal/readers/rdr_123")