Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion examples/async_event_notification_handler_endpoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion examples/event_notification_handler_endpoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion examples/event_notification_webhook_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
2 changes: 1 addition & 1 deletion examples/webhooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__)

Expand Down
10 changes: 10 additions & 0 deletions tests/test_webhook.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand Down