Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow empty content type on DELETE #73

Merged
merged 1 commit into from
May 10, 2018

Conversation

brandur-stripe
Copy link
Contributor

We recently added checks in stripe-mock to make sure that the right
Content-Type was being sent. Unfortunately, the logic was not quite
right for deletes, where you occasionally see a Content-Type in rare
cases, but which usually have empty request bodies, and therefore an
empty Content-Type is allowed.

This patch brings in two fixes:

  1. The OpenAPI spec has been tweak so as to not incorrectly include
    expand parameters on DELETE operations. This means that most
    DELETE operations have no defined request schema at all.
  2. Special cases incoming DELETE operations so that they can be
    checked against a schema if they provide parameters, but are also
    allowed to specify an empty Content-Type as well.

Between the two improvements, all edges should be covered.

The impetus here is to resolve [1] where a stripe-mock upgrade is
incompatible with the current code. I've verified that with this patch
included, stripe-python's test suite runs successfully.

[1] stripe/stripe-python#426

We recently added checks in `stripe-mock` to make sure that the right
`Content-Type` was being sent. Unfortunately, the logic was not quite
right for deletes, where you occasionally see a `Content-Type` in rare
cases, but which usually have empty request bodies, and therefore an
empty `Content-Type` is allowed.

This patch brings in two fixes:

1. The OpenAPI spec has been tweak so as to not incorrectly include
   `expand` parameters on `DELETE` operations. This means that most
   `DELETE` operations have no defined request schema at all.
2. Special cases incoming `DELETE` operations so that they can be
   checked against a schema if they provide parameters, but are also
   allowed to specify an empty `Content-Type` as well.

Between the two improvements, all edges should be covered.

The impetus here is to resolve [1] where a `stripe-mock` upgrade is
incompatible with the current code. I've verified that with this patch
included, `stripe-python`'s test suite runs successfully.

[1] stripe/stripe-python#426
@@ -83,14 +83,26 @@ func initTestSpec() {
Content: map[string]spec.MediaType{
"application/json": {
Schema: &spec.Schema{
Ref: "#/components/schemas/customer",
Ref: "#/components/schemas/charge",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This tweaks is an unrelated fix.

// Firstly, `Content-Type` is checked against the schema's media type, then
// string-encoded parameters are coerced to expected types (where possible).
// Finally, we validate the incoming payload against the schema.
func validateAndCoerceRequest(
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Most of this code is the same, but for cleanliness I've pulled it into its own function.

@@ -178,7 +186,7 @@ func TestStubServer_RoutesRequest(t *testing.T) {
&http.Request{Method: "POST",
URL: &url.URL{Path: "/v1/invoices/in_123/pay"}})
assert.NotNil(t, route)
assert.Equal(t, chargeDeleteMethod, route.operation)
assert.Equal(t, invoicePayMethod, route.operation)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My tweaks to the test fixtures revealed that these were previously wrong, so they've also been fixed.

@brandur-stripe
Copy link
Contributor Author

Going to self-approve this one so we can start closing out these upgrades:

LGTM.

@brandur-stripe brandur-stripe merged commit 720cbec into master May 10, 2018
@brandur-stripe brandur-stripe deleted the brandur-no-content-type-deletes branch May 10, 2018 20:11
brandur-stripe pushed a commit to stripe/stripe-python that referenced this pull request May 10, 2018
brandur-stripe pushed a commit to stripe/stripe-python that referenced this pull request May 10, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants