Repository: adnanh/webhook (go)

Issue:
Switching from 2.6.11 to 2.7.0 causes the same payloads to not match
Thanks for webhook!

Here are my rules: https://gist.github.com/gamerson/3cc9162082b9fe916b2d04b570e251f6

When I switched from 2.6.11 to 2.70, the same payload that was working before will now no longer work with the following error message:

```
[webhook] 2020/10/21 17:19:01 [aac923] incoming HTTP POST request from 172.17.0.1:42746
[webhook] 2020/10/21 17:19:01 [aac923] lugbot got matched
[webhook] 2020/10/21 17:19:01 [aac923] parameter node not found: ref
[webhook] 2020/10/21 17:19:01 [aac923] lugbot got matched, but didn't get triggered because the trigger rules were not satisfied
[webhook] 2020/10/21 17:19:01 [aac923] 200 | 30 B | 446.6µs | 629d73f917f7.ngrok.io | POST /hooks/lugbot
```

Here is a copy of the payload that would not match: https://gist.github.com/gamerson/f8e05eb879e7c30a537190a10b0011fd

Pull request description:
Fix OrRule logic on parameter lookup failures
Fixes #471

Patch:
diff --git a/internal/hook/hook.go b/internal/hook/hook.go
index 157c457..c446aee 100644
--- a/internal/hook/hook.go
+++ b/internal/hook/hook.go
@@ -848,7 +848,9 @@ func (r OrRule) Evaluate(req *Request) (bool, error) {
 	for _, v := range r {
 		rv, err := v.Evaluate(req)
 		if err != nil {
-			return false, err
+			if !IsParameterNodeError(err) {
+				return false, err
+			}
 		}
 
 		res = res || rv


Test patch:
diff --git a/internal/hook/hook_test.go b/internal/hook/hook_test.go
index 32bc848..9a548d7 100644
--- a/internal/hook/hook_test.go
+++ b/internal/hook/hook_test.go
@@ -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,
 	},
 }
 
diff --git a/test/hooks.json.tmpl b/test/hooks.json.tmpl
index 3075762..b94ed1a 100644
--- a/test/hooks.json.tmpl
+++ b/test/hooks.json.tmpl
@@ -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 }}",
diff --git a/test/hooks.yaml.tmpl b/test/hooks.yaml.tmpl
index 16aa8c1..325ef27 100644
--- a/test/hooks.yaml.tmpl
+++ b/test/hooks.yaml.tmpl
@@ -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 }}'
diff --git a/webhook_test.go b/webhook_test.go
index c8a46cc..d12826d 100644
--- a/webhook_test.go
+++ b/webhook_test.go
@@ -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",