Skip to content

Commit

Permalink
chore: sync release v1.30.2 to main branch (#4929)
Browse files Browse the repository at this point in the history
  • Loading branch information
Sidddddarth authored Jul 24, 2024
2 parents ee3131f + 2a654cf commit dd6791d
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 1 deletion.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# Changelog

## [1.30.2](https://github.com/rudderlabs/rudder-server/compare/v1.30.1...v1.30.2) (2024-07-24)


### Bug Fixes

* introduce config for get requests in webhook sources ([#4927](https://github.com/rudderlabs/rudder-server/issues/4927)) ([2494e69](https://github.com/rudderlabs/rudder-server/commit/2494e69cb64b0374f9cbfadcd25f2504c6e813de))

## [1.30.1](https://github.com/rudderlabs/rudder-server/compare/v1.30.0...v1.30.1) (2024-07-24)


Expand Down
9 changes: 9 additions & 0 deletions gateway/webhook/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"time"

"github.com/hashicorp/go-retryablehttp"
"github.com/samber/lo"

"github.com/rudderlabs/rudder-go-kit/config"

Expand Down Expand Up @@ -55,6 +56,14 @@ func Setup(gwHandle Gateway, transformerFeaturesService transformer.FeaturesServ
maxTransformerProcess := config.GetIntVar(64, 1, "Gateway.webhook.maxTransformerProcess")
// Parse all query params from sources mentioned in this list
webhook.config.sourceListForParsingParams = config.GetStringSliceVar([]string{"Shopify", "adjust"}, "Gateway.webhook.sourceListForParsingParams")

webhook.config.forwardGetRequestForSrcMap = lo.SliceToMap(
config.GetStringSliceVar([]string{"adjust"}, "Gateway.webhook.forwardGetRequestForSrcs"),
func(item string) (string, struct{}) {
return item, struct{}{}
},
)

// lowercasing the strings in sourceListForParsingParams
for i, s := range webhook.config.sourceListForParsingParams {
webhook.config.sourceListForParsingParams[i] = strings.ToLower(s)
Expand Down
8 changes: 7 additions & 1 deletion gateway/webhook/webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ type HandleT struct {
webhookBatchTimeout config.ValueLoader[time.Duration]
maxWebhookBatchSize config.ValueLoader[int]
sourceListForParsingParams []string
forwardGetRequestForSrcMap map[string]struct{}
}
}

Expand Down Expand Up @@ -104,6 +105,11 @@ func (webhook *HandleT) failRequest(w http.ResponseWriter, r *http.Request, reas
http.Error(w, reason, statusCode)
}

func (wb *HandleT) IsGetAndNotAllow(reqMethod, sourceDefName string) bool {
_, ok := wb.config.forwardGetRequestForSrcMap[sourceDefName]
return reqMethod == http.MethodGet && !ok
}

func (webhook *HandleT) RequestHandler(w http.ResponseWriter, r *http.Request) {
reqType := r.Context().Value(gwtypes.CtxParamCallType).(string)
arctx := r.Context().Value(gwtypes.CtxParamAuthRequestContext).(*gwtypes.AuthRequestContext)
Expand All @@ -114,7 +120,7 @@ func (webhook *HandleT) RequestHandler(w http.ResponseWriter, r *http.Request) {
var postFrom url.Values
var multipartForm *multipart.Form

if r.Method == "GET" {
if webhook.IsGetAndNotAllow(r.Method, sourceDefName) {
return
}
contentType := r.Header.Get("Content-Type")
Expand Down
49 changes: 49 additions & 0 deletions gateway/webhook/webhook_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -519,3 +519,52 @@ func TestPrepareRequestBody(t *testing.T) {
})
}
}

func TestAllowGetReqForWebhookSrc(t *testing.T) {
cases := []struct {
name string
forwardGetRequestForSrcMap map[string]struct{}
method string
srcDef string
expected bool
}{
{
name: "should allow get request for adjust",
method: http.MethodGet,
forwardGetRequestForSrcMap: map[string]struct{}{
"adjust": {},
},
srcDef: "adjust",
expected: false,
},
{
name: "should allow post request for adjust",
method: http.MethodPost,
forwardGetRequestForSrcMap: map[string]struct{}{
"adjust": {},
},
srcDef: "adjust",
expected: false,
},
{
name: "should not allow get request for shopify",
forwardGetRequestForSrcMap: map[string]struct{}{
"adjust": {},
"customerio": {},
},
method: http.MethodGet,
srcDef: "Shopify",
expected: true,
},
}

for _, tc := range cases {
t.Run(tc.name, func(t *testing.T) {
wbh := HandleT{}
wbh.config.forwardGetRequestForSrcMap = tc.forwardGetRequestForSrcMap

isGetAndNotAllow := wbh.IsGetAndNotAllow(tc.method, tc.srcDef)
require.Equal(t, tc.expected, isGetAndNotAllow)
})
}
}

0 comments on commit dd6791d

Please sign in to comment.