Skip to content

Commit

Permalink
fix: fix ruleID check (#2693)
Browse files Browse the repository at this point in the history
Signed-off-by: yisaer <[email protected]>
  • Loading branch information
Yisaer authored Mar 12, 2024
1 parent 43151c7 commit c627313
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
2 changes: 1 addition & 1 deletion internal/processor/rule.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ func (p *RuleProcessor) GetRuleByJson(id, ruleJson string) (*api.Rule, error) {
if rule.Id == "" {
rule.Id = id
}
if err := validateRuleID(id); err != nil {
if err := validateRuleID(rule.Id); err != nil {
return nil, err
}
if rule.Sql != "" {
Expand Down
12 changes: 12 additions & 0 deletions internal/server/rest_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,18 @@ func (suite *RestTestSuite) Test_rulesManageHandler() {
assert.Equal(suite.T(), http.StatusUnprocessableEntity, w2.Code)
assert.Equal(suite.T(), expect, string(returnVal))

// create rule with trigger false
ruleJson = `{"id": "rule3/21","triggered": false,"sql": "select * from alert","actions": [{"log": {}}]}`

buf2 = bytes.NewBuffer([]byte(ruleJson))
req2, _ = http.NewRequest(http.MethodPost, "http://localhost:8080/rules", buf2)
w2 = httptest.NewRecorder()
suite.r.ServeHTTP(w2, req2)
returnVal, _ = io.ReadAll(w2.Result().Body)
expect = `{"error":1000,"message":"invalid rule json: ruleID:rule3/21 contains invalidChar:/"}`
expect = expect + "\n"
assert.Equal(suite.T(), expect, string(returnVal))

// create rule with trigger false
ruleJson = `{"id": "rule321","triggered": false,"sql": "select * from alert","actions": [{"log": {}}]}`

Expand Down

0 comments on commit c627313

Please sign in to comment.