generic-webhook-trigger-plugin icon indicating copy to clipboard operation
generic-webhook-trigger-plugin copied to clipboard

x-www-form-urlencoded receiver is not properly converted in JSON

Open elrandira opened this issue 2 years ago • 3 comments

  • Plugin version used: 1.84
  • Jenkins version used: Jenkins 2.332.3
  • Build job log:
 Commit on master detected
Running as SYSTEM
Building on the built-in node in workspace /opt/jenkins/data/workspace/SOCSIV/services/robotframework_push_notifier
GenericWebhookEnvironmentContributor
 Received:

{
  "payload": [
    "{\"ref\":\"refs\\/heads\\/master\",\"after\":\"ee311c46a7df88f01aa7a8d35984b1fe89bd3d20\",\"before\":\"f03bec6afe3af8de2a75210eaaa6e5a51370773f\",\"repository\":{\"id\":4765,\"name\":\"robotframework\",\"full_name\":\"robotframework\"},\"pusher\":{\"name\":\"lpinson\",\"email\":\"<redacted>\"},\"sender\":{\"id\":841,\"uri\":\"users\\/841\",\"user_url\":\"\\/users\\/lpinson\",\"real_name\":\"lpinson\",\"display_name\":\"lpinson (lpinson)\",\"username\":\"lpinson\",\"ldap_id\":\"lpinson\",\"avatar_url\":"<redacted>",\"is_anonymous\":false,\"has_avatar\":true}}"
  ]
}


Contributing variables:

    ref = 
    ref_payload = 

ref is defined as JSONPath $.ref ref_payload is defined as JSONPath $.payload[0].ref

  • Post content received: see above
  • Expected result: receiver content available as JSON
  • actual result: "unreadable" receiver content

My employer is working with Tuleap to manage projects and it includes its own Git server. It is possible to configure Jenkins webhooks and custom webhooks. As the Jenkins webhook didn't allow me to trigger a build on a specific branch, I decided to look into generic-webhook-trigger plugin.

After struggling to understand that a token is necessary to properly trigger my job ( as in #234 ), I found out that the payload is not properly decoded as JSON. Tuleap uses only Content-Type: application/x-www-form-urlencoded, it is not configurable at the moment :(. I feared that is was not handled by this plugin but it seems to be solved since #225. However the payload stays in a string format instead of JSON format...

Any idea how to solve this?

ref: https://tuleap.net/doc/en/user-guide/integration/webhook.html

elrandira avatar Jun 16 '22 15:06 elrandira

I worked around this by parsing the whole payload string. payload is defined as JSONPath $.payload[0]

I compare then $payload to .*\"ref\":\"refs\\/heads\\/master\".*

not pretty but it works

elrandira avatar Jun 16 '22 15:06 elrandira

The problem is not in this plugin, it is on the sender side.

The body:

{
  "payload": [
    "{\"ref\":\"refs\\/heads\\/master\",\"after\":\"ee311c46a7df88f01aa7a8d35984b1fe89bd3d20\",\"before\":\"f03bec6afe3af8de2a75210eaaa6e5a51370773f\",\"repository\":{\"id\":4765,\"name\":\"robotframework\",\"full_name\":\"robotframework\"},\"pusher\":{\"name\":\"lpinson\",\"email\":\"<redacted>\"},\"sender\":{\"id\":841,\"uri\":\"users\\/841\",\"user_url\":\"\\/users\\/lpinson\",\"real_name\":\"lpinson\",\"display_name\":\"lpinson (lpinson)\",\"username\":\"lpinson\",\"ldap_id\":\"lpinson\",\"avatar_url\":"<redacted>",\"is_anonymous\":false,\"has_avatar\":true}}"
  ]
}

I being sent as x-www-form-urlencoded and what you see in the log is the decoded value.

Seems strange to wrap the json within payload attribute, but not much to do about that here on the receiver side.

tomasbjerre avatar Jun 19 '22 09:06 tomasbjerre

That's what I feared. I'll try to dig into the code since Tuleap is open source. Thanks for the feedback Tomas

elrandira avatar Jun 20 '22 07:06 elrandira