mirror of
https://github.com/adnanh/webhook.git
synced 2025-05-16 10:30:09 +00:00
Merge pull request #472 from moorereason/iss471-sc
Fix OrRule logic on parameter lookup failures
This commit is contained in:
commit
4fadb1171f
5 changed files with 137 additions and 3 deletions
|
@ -848,8 +848,10 @@ func (r OrRule) Evaluate(req *Request) (bool, error) {
|
|||
for _, v := range r {
|
||||
rv, err := v.Evaluate(req)
|
||||
if err != nil {
|
||||
if !IsParameterNodeError(err) {
|
||||
return false, err
|
||||
}
|
||||
}
|
||||
|
||||
res = res || rv
|
||||
if res {
|
||||
|
|
|
@ -657,13 +657,13 @@ var orRuleTests = []struct {
|
|||
},
|
||||
// failures
|
||||
{
|
||||
"invalid rule",
|
||||
"missing parameter node",
|
||||
OrRule{
|
||||
{Match: &MatchRule{"value", "", "", "z", Argument{"header", "a", "", false}, ""}},
|
||||
},
|
||||
map[string]interface{}{"Y": "Z"}, nil, nil,
|
||||
[]byte{},
|
||||
false, true,
|
||||
false, false,
|
||||
},
|
||||
}
|
||||
|
||||
|
|
|
@ -276,6 +276,76 @@
|
|||
}
|
||||
],
|
||||
},
|
||||
{
|
||||
"id": "issue-471",
|
||||
"execute-command": "{{ .Hookecho }}",
|
||||
"response-message": "success",
|
||||
"trigger-rule":
|
||||
{
|
||||
"or":
|
||||
[
|
||||
{
|
||||
"match":
|
||||
{
|
||||
"parameter":
|
||||
{
|
||||
"source": "payload",
|
||||
"name": "foo"
|
||||
},
|
||||
"type": "value",
|
||||
"value": "bar"
|
||||
}
|
||||
},
|
||||
{
|
||||
"match":
|
||||
{
|
||||
"parameter":
|
||||
{
|
||||
"source": "payload",
|
||||
"name": "exists"
|
||||
},
|
||||
"type": "value",
|
||||
"value": 1
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"id": "issue-471-and",
|
||||
"execute-command": "{{ .Hookecho }}",
|
||||
"response-message": "success",
|
||||
"trigger-rule":
|
||||
{
|
||||
"and":
|
||||
[
|
||||
{
|
||||
"match":
|
||||
{
|
||||
"parameter":
|
||||
{
|
||||
"source": "payload",
|
||||
"name": "foo"
|
||||
},
|
||||
"type": "value",
|
||||
"value": "bar"
|
||||
}
|
||||
},
|
||||
{
|
||||
"match":
|
||||
{
|
||||
"parameter":
|
||||
{
|
||||
"source": "payload",
|
||||
"name": "exists"
|
||||
},
|
||||
"type": "value",
|
||||
"value": 1
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"id": "empty-payload-signature",
|
||||
"execute-command": "{{ .Hookecho }}",
|
||||
|
|
|
@ -163,6 +163,42 @@
|
|||
execute-command: '{{ .Hookecho }} foo'
|
||||
include-command-output-in-response: true
|
||||
|
||||
- id: issue-471
|
||||
execute-command: '{{ .Hookecho }}'
|
||||
response-message: success
|
||||
trigger-rule:
|
||||
or:
|
||||
- match:
|
||||
parameter:
|
||||
source: payload
|
||||
name: foo
|
||||
type: value
|
||||
value: bar
|
||||
- match:
|
||||
parameter:
|
||||
source: payload
|
||||
name: exists
|
||||
type: value
|
||||
value: 1
|
||||
|
||||
- id: issue-471-and
|
||||
execute-command: '{{ .Hookecho }}'
|
||||
response-message: success
|
||||
trigger-rule:
|
||||
and:
|
||||
- match:
|
||||
parameter:
|
||||
source: payload
|
||||
name: foo
|
||||
type: value
|
||||
value: bar
|
||||
- match:
|
||||
parameter:
|
||||
source: payload
|
||||
name: exists
|
||||
type: value
|
||||
value: 1
|
||||
|
||||
- id: empty-payload-signature
|
||||
include-command-output-in-response: true
|
||||
execute-command: '{{ .Hookecho }}'
|
||||
|
|
|
@ -606,6 +606,32 @@ binary data
|
|||
``,
|
||||
},
|
||||
|
||||
{
|
||||
"issue-471",
|
||||
"issue-471",
|
||||
nil,
|
||||
"POST",
|
||||
nil,
|
||||
"application/json",
|
||||
`{"exists": 1}`,
|
||||
http.StatusOK,
|
||||
`success`,
|
||||
``,
|
||||
},
|
||||
|
||||
{
|
||||
"issue-471-and",
|
||||
"issue-471-and",
|
||||
nil,
|
||||
"POST",
|
||||
nil,
|
||||
"application/json",
|
||||
`{"exists": 1}`,
|
||||
http.StatusOK,
|
||||
`Hook rules were not satisfied.`,
|
||||
`parameter node not found`,
|
||||
},
|
||||
|
||||
{
|
||||
"missing-cmd-arg", // missing head_commit.author.email
|
||||
"github",
|
||||
|
|
Loading…
Add table
Reference in a new issue