Skip to content

Commit

Permalink
Dont allow users to create bandwidthLimit disruptions below 32 bytes (#…
Browse files Browse the repository at this point in the history
…795)

* Dont allow users to create bandwidthLimit disruptions below 32 bytes

* add a unit test
  • Loading branch information
ptnapoleon committed Oct 18, 2023
1 parent 72e29fe commit 9fe0805
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
4 changes: 4 additions & 0 deletions api/v1beta1/network_disruption.go
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,10 @@ func (s *NetworkDisruptionSpec) Validate() (retErr error) {
}
}

if s.BandwidthLimit > 0 && s.BandwidthLimit < 32 {
retErr = multierror.Append(retErr, fmt.Errorf("bandwidthLimits below 32 bytes are not supported"))
}

return multierror.Prefix(retErr, "Network:")
}

Expand Down
16 changes: 16 additions & 0 deletions api/v1beta1/network_disruption_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -442,6 +442,22 @@ var _ = Describe("NetworkDisruptionSpec", func() {
})
})

Describe("test option limits", func() {
It("rejects bandwidthLimits below 32 bytes", func() {
disruptionSpec := NetworkDisruptionSpec{BandwidthLimit: 0}
err := disruptionSpec.Validate()
Expect(err).ShouldNot(HaveOccurred())

disruptionSpec.BandwidthLimit = 32
err = disruptionSpec.Validate()
Expect(err).ShouldNot(HaveOccurred())

disruptionSpec.BandwidthLimit = 16
err = disruptionSpec.Validate()
Expect(err).Should(HaveOccurred())
})
})

DescribeTable("multi error cases",
func(invalidPaths HTTPPaths, invalidMethods HTTPMethods, expectedErrorMessages []string) {
// Arrange
Expand Down

0 comments on commit 9fe0805

Please sign in to comment.