Skip to content

Commit e619b34

Browse files
committed
BUG/MEDIUM: fix missing int and expression in http-after-response sc-add-gpc
1 parent da76b8f commit e619b34

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

configuration/http_after_response_rule.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -349,6 +349,8 @@ func ParseHTTPAfterRule(f types.Action) (*models.HTTPAfterResponseRule, error) {
349349
Type: "sc-add-gpc",
350350
ScID: ID,
351351
ScIdx: Idx,
352+
ScExpr: strings.Join(v.Expr.Expr, " "),
353+
ScInt: v.Int,
352354
Cond: v.Cond,
353355
CondTest: v.CondTest,
354356
Metadata: parseMetadata(v.Comment),
@@ -498,7 +500,7 @@ func ParseHTTPAfterRule(f types.Action) (*models.HTTPAfterResponseRule, error) {
498500
return nil, nil //nolint:nilnil
499501
}
500502

501-
func SerializeHTTPAfterRule(f models.HTTPAfterResponseRule) (types.Action, error) { //nolint:ireturn
503+
func SerializeHTTPAfterRule(f models.HTTPAfterResponseRule) (types.Action, error) { //nolint:ireturn,maintidx
502504
comment, err := serializeMetadata(f.Metadata)
503505
if err != nil {
504506
return nil, err
@@ -562,9 +564,17 @@ func SerializeHTTPAfterRule(f models.HTTPAfterResponseRule) (types.Action, error
562564
Comment: comment,
563565
}
564566
case "sc-add-gpc":
567+
if len(f.ScExpr) > 0 && f.ScInt != nil {
568+
return nil, NewConfError(ErrValidationError, "sc-add-gpc int and expr are exclusive")
569+
}
570+
if len(f.ScExpr) == 0 && f.ScInt == nil {
571+
return nil, NewConfError(ErrValidationError, "sc-add-gpc int or expr has to be set")
572+
}
565573
rule = &actions.ScAddGpc{
566574
ID: strconv.FormatInt(f.ScID, 10),
567575
Idx: strconv.FormatInt(f.ScIdx, 10),
576+
Int: f.ScInt,
577+
Expr: common.Expression{Expr: strings.Split(f.ScExpr, " ")},
568578
Cond: f.Cond,
569579
CondTest: f.CondTest,
570580
Comment: comment,

test/expected/structured.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1715,6 +1715,7 @@
17151715
"cond": "if",
17161716
"cond_test": "FALSE",
17171717
"sc_id": 1,
1718+
"sc_int": 1,
17181719
"type": "sc-add-gpc"
17191720
},
17201721
{

0 commit comments

Comments
 (0)