Skip to content

Commit 0f30adc

Browse files
committed
Introduce test for misuse of the quite open legacy-schema to smuggle in a service-key-request;
1 parent 431fbf2 commit 0f30adc

File tree

2 files changed

+61
-19
lines changed

2 files changed

+61
-19
lines changed

Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ ${app-fakes-dir} ${app-fakes-files} &: ./go.mod ./go.sum ${fake-relevant-go-file
102102
@echo '# Generating counterfeits'
103103
mkdir -p '${app-fakes-dir}'
104104
COUNTERFEITER_NO_GENERATE_WARNING='true' GOFLAGS='-mod=mod' go generate './...'
105+
@touch '${app-fakes-dir}' # Ensure that the folder-modification-timestamp gets updated.
105106

106107
.PHONY: test-app.generate-fakes
107108
test-app.generate-fakes:

api/broker/broker_test.go

Lines changed: 60 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -588,35 +588,76 @@ var _ = Describe("Broker", func() {
588588
Expect(savedPolicy).NotTo(BeNil())
589589
Expect(savedPolicyGuid).NotTo(BeEmpty())
590590
})
591-
It("Fails when no schema-version has been provided", func() {
592-
var bindingParams = []byte(`
591+
When("No schema-version has been provided", func() {
592+
It("Fails when doing a minimal bind-request", func() {
593+
var bindingParams = []byte(`
593594
{
594595
"configuration": {
595596
"app_guid": "12345678-abcd-1234-5678-123456789abc"
596597
}
597598
}`)
598599

599-
details = domain.BindDetails{
600-
AppGUID: "", // No deprecated app GUID
601-
PlanID: "some_plan-id",
602-
ServiceID: "some_service-id",
603-
BindResource: nil, // No BindResource for service keys
604-
RawParameters: bindingParams,
605-
}
600+
details = domain.BindDetails{
601+
AppGUID: "", // No deprecated app GUID
602+
PlanID: "some_plan-id",
603+
ServiceID: "some_service-id",
604+
BindResource: nil, // No BindResource for service keys
605+
RawParameters: bindingParams,
606+
}
606607

607-
// Execution
608-
_, err := aBroker.Bind(ctx, instanceID, bindingID, details, false)
608+
// Execution
609+
_, err := aBroker.Bind(ctx, instanceID, bindingID, details, false)
609610

610-
Expect(err).NotTo(BeNil())
611-
Expect(err).To(MatchError(ContainSubstring(
612-
`{"context":"(root)","description":"schema-version is required"}`,
613-
)))
611+
Expect(err).NotTo(BeNil())
612+
Expect(err).To(MatchError(ContainSubstring(
613+
`{"context":"(root)","description":"schema-version is required"}`,
614+
)))
614615

615-
// Verify that fakeBindingDB does not create an entry
616-
Expect(fakeBindingDB.CreateServiceBindingCallCount()).To(Equal(0))
616+
// Verify that fakeBindingDB does not create an entry
617+
Expect(fakeBindingDB.CreateServiceBindingCallCount()).To(Equal(0))
617618

618-
// Verify that no policy was saved with the correct app GUID
619-
Expect(fakePolicyDB.SaveAppPolicyCallCount()).To(Equal(0))
619+
// Verify that no policy was saved with the correct app GUID
620+
Expect(fakePolicyDB.SaveAppPolicyCallCount()).To(Equal(0))
621+
})
622+
FIt("Fails when smuggling into a legacy bind-request", func() {
623+
var bindingParams = []byte(`
624+
{
625+
"configuration": {
626+
"app_guid": "12345678-abcd-1234-5678-123456789abc",
627+
"custom_metrics": {
628+
"metric_submission_strategy": {
629+
"allow_from": "bound_app"
630+
}
631+
}
632+
},
633+
"instance_min_count": 1,
634+
"instance_max_count": 5,
635+
"scaling_rules": [
636+
{
637+
"metric_type": "memoryused",
638+
"threshold": 100,
639+
"operator": "<",
640+
"adjustment": "+1"
641+
}
642+
]
643+
}`)
644+
645+
details = domain.BindDetails{
646+
AppGUID: "", // No deprecated app GUID
647+
PlanID: "some_plan-id",
648+
ServiceID: "some_service-id",
649+
BindResource: nil, // No BindResource for service keys
650+
RawParameters: bindingParams,
651+
}
652+
653+
// Execution
654+
_, err := aBroker.Bind(ctx, instanceID, bindingID, details, false)
655+
656+
Expect(err).NotTo(BeNil())
657+
Expect(err).To(MatchError(ContainSubstring(
658+
`{"context":"(root)","description":"schema-version is required"}`,
659+
)))
660+
})
620661
})
621662
})
622663
})

0 commit comments

Comments
 (0)