Skip to content

Commit

Permalink
[CLOUDTRUST-5106] Fix bug in validation tools
Browse files Browse the repository at this point in the history
  • Loading branch information
fperot74 authored Sep 26, 2023
1 parent 070c0a7 commit 019947f
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 6 deletions.
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module github.com/cloudtrust/common-service/v2
go 1.17

require (
github.com/IBM/sarama v1.41.1
github.com/IBM/sarama v1.41.1
github.com/gbrlsnchs/jwt/v2 v2.0.0
github.com/getsentry/raven-go v0.2.0
github.com/go-kit/kit v0.12.0
Expand All @@ -13,7 +13,7 @@ require (
github.com/google/uuid v1.3.0
github.com/gorilla/mux v1.8.0
github.com/influxdata/influxdb1-client v0.0.0-20200827194710-b269163b24ab
github.com/nyaruka/phonenumbers v1.0.74
github.com/nyaruka/phonenumbers v1.1.8
github.com/opentracing/opentracing-go v1.2.0
github.com/pkg/errors v0.9.1
github.com/stretchr/testify v1.8.4
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -357,8 +357,8 @@ github.com/nbio/st v0.0.0-20140626010706-e9e8d9816f32/go.mod h1:9wM+0iRr9ahx58uY
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno=
github.com/nxadm/tail v1.4.4/go.mod h1:kenIhsEOeOJmVchQTgglprH7qJGnHDVpk1VPCcaMI8A=
github.com/nxadm/tail v1.4.8/go.mod h1:+ncqLTQzXmGhMZNUePPaPqPvBxHAIsmXswZKocGu+AU=
github.com/nyaruka/phonenumbers v1.0.74 h1:Eo3aIKM6zfaHd+mCs+BY7FYpmHobb5C/erLkgs5Wx8U=
github.com/nyaruka/phonenumbers v1.0.74/go.mod h1:3aiS+PS3DuYwkbK3xdcmRwMiPNECZ0oENH8qUT1lY7Q=
github.com/nyaruka/phonenumbers v1.1.8 h1:mjFu85FeoH2Wy18aOMUvxqi1GgAqiQSJsa/cCC5yu2s=
github.com/nyaruka/phonenumbers v1.1.8/go.mod h1:DC7jZd321FqUe+qWSNcHi10tyIyGNXGcNbfkPvdp1Vs=
github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
github.com/onsi/ginkgo v1.7.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
github.com/onsi/ginkgo v1.12.1/go.mod h1:zj2OWP4+oCPe1qIXoGWkgMRwljMUYCdkwsT2108oapk=
Expand Down
2 changes: 1 addition & 1 deletion validation/validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ func (v *successValidator) ValidateParameterIn(prmName string, value *string, al
return &failedValidator{err: cerrors.CreateMissingParameterError(prmName)}
}
} else {
if _, ok := allowedValues[*value]; !ok {
if allowed, ok := allowedValues[*value]; !ok || !allowed {
return &failedValidator{err: cerrors.CreateBadRequestError(cerrors.MsgErrInvalidParam + "." + prmName)}
}
}
Expand Down
6 changes: 5 additions & 1 deletion validation/validator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,10 @@ func TestValidateParameterNotNil(t *testing.T) {
}

func TestValidateParameterIn(t *testing.T) {
var weekend = map[string]bool{"saturday": true, "sunday": true}
var weekend = map[string]bool{"saturday": true, "sunday": true, "wednesday": false}
var validValue = "sunday"
var invalidValue = "green"
var disallowedValue = "wednesday"

t.Run("Nil value, not mandatory", func(t *testing.T) {
assert.Nil(t, NewParameterValidator().ValidateParameterIn("param", nil, weekend, false).Status())
Expand All @@ -127,6 +128,9 @@ func TestValidateParameterIn(t *testing.T) {
t.Run("Invalid value", func(t *testing.T) {
assert.NotNil(t, NewParameterValidator().ValidateParameterIn("param", &invalidValue, weekend, true).Status())
})
t.Run("Disallowed value", func(t *testing.T) {
assert.NotNil(t, NewParameterValidator().ValidateParameterIn("param", &disallowedValue, weekend, true).Status())
})
t.Run("Valid check after failed validation", func(t *testing.T) {
assert.NotNil(t, failingValidator().ValidateParameterIn("param", nil, weekend, false).Status())
})
Expand Down

0 comments on commit 019947f

Please sign in to comment.