Skip to content

Commit 9fe0805

Browse files
authored
Dont allow users to create bandwidthLimit disruptions below 32 bytes (#795)
* Dont allow users to create bandwidthLimit disruptions below 32 bytes * add a unit test
1 parent 72e29fe commit 9fe0805

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

api/v1beta1/network_disruption.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -346,6 +346,10 @@ func (s *NetworkDisruptionSpec) Validate() (retErr error) {
346346
}
347347
}
348348

349+
if s.BandwidthLimit > 0 && s.BandwidthLimit < 32 {
350+
retErr = multierror.Append(retErr, fmt.Errorf("bandwidthLimits below 32 bytes are not supported"))
351+
}
352+
349353
return multierror.Prefix(retErr, "Network:")
350354
}
351355

api/v1beta1/network_disruption_test.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -442,6 +442,22 @@ var _ = Describe("NetworkDisruptionSpec", func() {
442442
})
443443
})
444444

445+
Describe("test option limits", func() {
446+
It("rejects bandwidthLimits below 32 bytes", func() {
447+
disruptionSpec := NetworkDisruptionSpec{BandwidthLimit: 0}
448+
err := disruptionSpec.Validate()
449+
Expect(err).ShouldNot(HaveOccurred())
450+
451+
disruptionSpec.BandwidthLimit = 32
452+
err = disruptionSpec.Validate()
453+
Expect(err).ShouldNot(HaveOccurred())
454+
455+
disruptionSpec.BandwidthLimit = 16
456+
err = disruptionSpec.Validate()
457+
Expect(err).Should(HaveOccurred())
458+
})
459+
})
460+
445461
DescribeTable("multi error cases",
446462
func(invalidPaths HTTPPaths, invalidMethods HTTPMethods, expectedErrorMessages []string) {
447463
// Arrange

0 commit comments

Comments
 (0)