Skip to content

Commit

Permalink
fix(api): check name pattern on postProjectIntegrationHandler (#6169)
Browse files Browse the repository at this point in the history
  • Loading branch information
fsamin authored May 17, 2022
1 parent 8872d84 commit 9aa776a
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
6 changes: 6 additions & 0 deletions engine/api/project_integration.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ func (api *API) putProjectIntegrationHandler() service.Handler {
return sdk.WithStack(sdk.ErrForbidden)
}

projectIntegration.Name = ppDB.Name
projectIntegration.ID = ppDB.ID

for kkBody := range projectIntegration.Config {
Expand Down Expand Up @@ -210,6 +211,11 @@ func (api *API) postProjectIntegrationHandler() service.Handler {
return sdk.WrapError(err, "Cannot read body")
}

regexp := sdk.NamePatternRegex
if !regexp.MatchString(pp.Name) {
return sdk.NewErrorFrom(sdk.ErrWrongRequest, "name %q do not respect pattern %s", pp.Name, sdk.NamePattern)
}

pp.ProjectID = p.ID
if pp.IntegrationModelID == 0 {
pp.IntegrationModelID = pp.Model.ID
Expand Down
2 changes: 1 addition & 1 deletion engine/api/project_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func TestAddUpdateAndDeleteProjectIntegration(t *testing.T) {
assert.Equal(t, 200, w.Code)

// UPDATE integration
pp.Name = "kafkaTest2"
pp.Name = "kafkaTest"
pp.ProjectID = proj.ID

vars = map[string]string{}
Expand Down

0 comments on commit 9aa776a

Please sign in to comment.