Skip to content

Commit a8af7ce

Browse files
set default validator when nil (#92)
* set default validator when nil * updated changelog * added unit tests * prep for release
1 parent 052e0d4 commit a8af7ce

File tree

5 files changed

+28
-1
lines changed

5 files changed

+28
-1
lines changed

CHANGELOG.md

+5-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,10 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
55
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
66

77
## [Unreleased]
8+
9+
## [v0.3.5]
810
- Changed errorEncoder to log errors. [#90](https://github.com/xmidt-org/ancla/pull/90)
11+
- Fixed webhook request decoder panic; added default validator when none given. [#92](https://github.com/xmidt-org/ancla/pull/92)
912

1013
## [v0.3.4]
1114
- Added more details to some validation errors. [#91](https://github.com/xmidt-org/ancla/pull/91)
@@ -84,7 +87,8 @@ internalWebhooks. [#80](https://github.com/xmidt-org/ancla/pull/80)
8487
## [v0.1.0]
8588
- Initial release
8689

87-
[Unreleased]: https://github.com/xmidt-org/ancla/compare/v0.3.4...HEAD
90+
[Unreleased]: https://github.com/xmidt-org/ancla/compare/v0.3.5...HEAD
91+
[v0.3.5]: https://github.com/xmidt-org/ancla/compare/0.3.4...v0.3.5
8892
[v0.3.4]: https://github.com/xmidt-org/ancla/compare/0.3.3...v0.3.4
8993
[v0.3.3]: https://github.com/xmidt-org/ancla/compare/0.3.2...v0.3.3
9094
[v0.3.2]: https://github.com/xmidt-org/ancla/compare/0.3.1...v0.3.2

transport.go

+5
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,11 @@ func addWebhookRequestDecoder(config transportConfig) kithttp.DecodeRequestFunc
9797
config.basicPartnerIDsHeader = DefaultBasicPartnerIDsHeader
9898
}
9999

100+
// if no validators are given, we accept anything.
101+
if config.v == nil {
102+
config.v = AlwaysValid()
103+
}
104+
100105
return func(c context.Context, r *http.Request) (request interface{}, err error) {
101106
requestPayload, err := ioutil.ReadAll(r.Body)
102107
if err != nil {

transport_test.go

+6
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,12 @@ func TestAddWebhookRequestDecoder(t *testing.T) {
179179
Validator: Validators{},
180180
Auth: "jwt",
181181
},
182+
{
183+
Description: "No validator provided",
184+
InputPayload: addWebhookDecoderInput(),
185+
ExpectedDecodedRequest: addWebhookDecoderOutput(true),
186+
Auth: "jwt",
187+
},
182188
{
183189
Description: "Do not check PartnerIDs",
184190
InputPayload: addWebhookDecoderInput(),

webhookValidator.go

+7
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,13 @@ func (vf ValidatorFunc) Validate(w Webhook) error {
7171
return vf(w)
7272
}
7373

74+
// AlwaysValid doesn't check anything in the webhook and never returns an error.
75+
func AlwaysValid() ValidatorFunc {
76+
return func(w Webhook) error {
77+
return nil
78+
}
79+
}
80+
7481
// CheckEvents makes sure there is at least one value in Events and ensures that
7582
// all values should parse into regex.
7683
func CheckEvents() ValidatorFunc {

webhookValidator_test.go

+5
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,11 @@ var (
3434
negativeThreeDuration = -3 * time.Minute
3535
)
3636

37+
func TestAlwaysValid(t *testing.T) {
38+
err := AlwaysValid()(Webhook{})
39+
assert.NoError(t, err)
40+
}
41+
3742
func TestCheckEvents(t *testing.T) {
3843
tcs := []struct {
3944
desc string

0 commit comments

Comments
 (0)