Skip to content

Commit

Permalink
Ignore acceptIncomplete parameter in binding when API version < 2.14
Browse files Browse the repository at this point in the history
Co-authored-by: Kieron Browne <[email protected]>
  • Loading branch information
Derik Evangelista and Kieron Browne committed Sep 26, 2018
1 parent 176671d commit 036a459
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 43 deletions.
10 changes: 3 additions & 7 deletions api.go
Original file line number Diff line number Diff line change
Expand Up @@ -449,13 +449,9 @@ func (h serviceBrokerHandler) bind(w http.ResponseWriter, req *http.Request) {
return
}

asyncAllowed := req.FormValue("accepts_incomplete") == "true"
if asyncAllowed && versionCompatibility.Minor < 14 {
h.respond(w, http.StatusUnprocessableEntity, ErrorResponse{
Description: "async binding only supported from OSB version 2.14 and up",
})
logger.Error(apiVersionInvalidKey, err)
return
asyncAllowed := false
if versionCompatibility.Minor >= 14 {
asyncAllowed = req.FormValue("accepts_incomplete") == "true"
}

binding, err := h.serviceBroker.Bind(req.Context(), instanceID, bindingID, details, asyncAllowed)
Expand Down
73 changes: 39 additions & 34 deletions api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ import (
"code.cloudfoundry.org/lager"
"code.cloudfoundry.org/lager/lagertest"
"github.com/drewolson/testflight"
"github.com/pivotal-cf/brokerapi"
"github.com/pivotal-cf/brokerapi/fakes"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"github.com/pivotal-cf/brokerapi"
"github.com/pivotal-cf/brokerapi/fakes"
)

var _ = Describe("Service Broker API", func() {
Expand Down Expand Up @@ -1631,51 +1631,56 @@ var _ = Describe("Service Broker API", func() {
var (
fakeAsyncServiceBroker *fakes.FakeAsyncServiceBroker
)

BeforeEach(func() {
fakeAsyncServiceBroker = &fakes.FakeAsyncServiceBroker{
FakeServiceBroker: *fakeServiceBroker,
ShouldBindAsync: true,
}
brokerAPI = brokerapi.New(fakeAsyncServiceBroker, brokerLogger, credentials)
})

It("when the api version is before 2.14 for Bind request", func() {
response := makeBindingRequestWithSpecificAPIVersion(instanceID, bindingID, details, "2.13", true)
Expect(response.StatusCode).To(Equal(http.StatusUnprocessableEntity))
})
When("the api version is < 2.14", func() {
It("successfully returns a sync binding response", func() {
response := makeBindingRequestWithSpecificAPIVersion(instanceID, bindingID, details, "2.13", true)
Expect(response.StatusCode).To(Equal(http.StatusCreated))
Expect(response.Body).To(MatchJSON(fixture("binding.json")))
})

It("when the api version is before 2.14 for LastBindingOperation request", func() {
response := makeLastBindingOperationRequestWithSpecificAPIVersion(instanceID, bindingID, "1.13")
Expect(response.StatusCode).To(Equal(http.StatusPreconditionFailed))
response = makeLastBindingOperationRequestWithSpecificAPIVersion(instanceID, bindingID, "2.13")
Expect(response.StatusCode).To(Equal(http.StatusPreconditionFailed))
})
It("fails for LastBindingOperation request", func() {
response := makeLastBindingOperationRequestWithSpecificAPIVersion(instanceID, bindingID, "1.13")
Expect(response.StatusCode).To(Equal(http.StatusPreconditionFailed))
response = makeLastBindingOperationRequestWithSpecificAPIVersion(instanceID, bindingID, "2.13")
Expect(response.StatusCode).To(Equal(http.StatusPreconditionFailed))
})

It("when the api version is before 2.14 for GetBinding request", func() {
response := makeGetBindingRequestWithSpecificAPIVersion(instanceID, bindingID, "1.13")
Expect(response.StatusCode).To(Equal(http.StatusPreconditionFailed))
response = makeGetBindingRequestWithSpecificAPIVersion(instanceID, bindingID, "2.13")
Expect(response.StatusCode).To(Equal(http.StatusPreconditionFailed))
It("fails for GetBinding request", func() {
response := makeGetBindingRequestWithSpecificAPIVersion(instanceID, bindingID, "1.13")
Expect(response.StatusCode).To(Equal(http.StatusPreconditionFailed))
response = makeGetBindingRequestWithSpecificAPIVersion(instanceID, bindingID, "2.13")
Expect(response.StatusCode).To(Equal(http.StatusPreconditionFailed))
})
})

It("it returns an appropriate status code and operation data", func() {
response := makeAsyncBindingRequest(instanceID, bindingID, details)
Expect(response.StatusCode).To(Equal(http.StatusAccepted))
Expect(response.Body).To(MatchJSON(fixture("async_bind_response.json")))
})
When("the api version is 2.14", func() {
It("returns an appropriate status code and operation data", func() {
response := makeAsyncBindingRequest(instanceID, bindingID, details)
Expect(response.StatusCode).To(Equal(http.StatusAccepted))
Expect(response.Body).To(MatchJSON(fixture("async_bind_response.json")))
})

It("can be polled with lastBindingOperation", func() {
fakeAsyncServiceBroker.LastOperationState = "succeeded"
fakeAsyncServiceBroker.LastOperationDescription = "some description"
response := makeLastBindingOperationRequestWithSpecificAPIVersion(instanceID, bindingID, "2.14")
Expect(response.StatusCode).To(Equal(http.StatusOK))
Expect(response.Body).To(MatchJSON(fixture("last_operation_succeeded.json")))
})
It("can be polled with lastBindingOperation", func() {
fakeAsyncServiceBroker.LastOperationState = "succeeded"
fakeAsyncServiceBroker.LastOperationDescription = "some description"
response := makeLastBindingOperationRequestWithSpecificAPIVersion(instanceID, bindingID, "2.14")
Expect(response.StatusCode).To(Equal(http.StatusOK))
Expect(response.Body).To(MatchJSON(fixture("last_operation_succeeded.json")))
})

It("getBinding returns the binding for the async request", func() {
response := makeGetBindingRequestWithSpecificAPIVersion(instanceID, bindingID, "2.14")
Expect(response.StatusCode).To(Equal(http.StatusOK))
Expect(response.Body).To(MatchJSON(fixture("binding.json")))
It("returns the binding for the async request on getBinding", func() {
response := makeGetBindingRequestWithSpecificAPIVersion(instanceID, bindingID, "2.14")
Expect(response.StatusCode).To(Equal(http.StatusOK))
Expect(response.Body).To(MatchJSON(fixture("binding.json")))
})
})
})
})
Expand Down
3 changes: 1 addition & 2 deletions fakes/fake_service_broker.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ type FakeServiceBroker struct {
type FakeAsyncServiceBroker struct {
FakeServiceBroker
ShouldProvisionAsync bool
ShouldBindAsync bool
}

type FakeAsyncOnlyServiceBroker struct {
Expand Down Expand Up @@ -319,7 +318,7 @@ func (fakeBroker *FakeAsyncServiceBroker) Bind(context context.Context, instance
fakeBroker.BoundInstanceIDs = append(fakeBroker.BoundInstanceIDs, instanceID)
fakeBroker.BoundBindingIDs = append(fakeBroker.BoundBindingIDs, bindingID)

if fakeBroker.ShouldBindAsync {
if asyncAllowed {
return brokerapi.Binding{
IsAsync: true,
OperationData: "0xDEADBEEF",
Expand Down

0 comments on commit 036a459

Please sign in to comment.