Commit graph

20 commits

Author SHA1 Message Date
Cameron Moore
3414f34025 Add per-hook HTTP method restrictions 2019-12-26 14:54:01 -06:00
Cameron Moore
1c779a0d75 Update multipart form data logic
All form values are simply added to the payload map without processing.
JSON parsing of values happens later.
2019-12-25 09:08:23 -06:00
Cameron Moore
3463804a7c Add XML payload support
Fixes #238
2019-12-24 15:58:49 -06:00
Cameron Moore
40d9dcd6d4 Make hook package internal
The hook package API is not meant for public consumption.
2019-12-21 11:55:42 -06:00
Adnan Hajdarevic
1110f82443 Add test for unsupported content type error message. 2019-12-02 19:01:20 +01:00
Cameron Moore
6c77ff0a2c Fix TestWebhook tests
PR #266 appears to have changed the default response code to StatusOK.
waitForServerReady() was expected a StatusNotFound response, which was
preventing all TestWebhook tests from running.
2019-09-18 16:59:11 -05:00
Cameron Moore
471c849c50 Fix another race condition in TestWebhook
There's the potential for a race condition where we try to read the logs
buffer before the logs have been flushed by the webhook process. Kill
the process to flush the logs before testing against the log buffer.
2018-02-16 14:36:08 -06:00
Cameron Moore
337621998e Fix race in TestWebhook
Previous commit misused a bytes.Buffer. Protect the buffer with a
mutex.
2018-02-15 19:53:28 -06:00
Cameron Moore
0feeb945fc Fix some tests for Windows
This commit incorporates some tests into the main TestWebhook framework.  New features to TestWebhook:

- Check log output against Regexp
- Add Testing sub-tests

Updates #225
2018-02-15 19:20:39 -06:00
Greg Dubicki
e2f6e4eb37 Add tests for capturing command output
and fix running tests on macOS, where there is no
/bin/true...
2017-11-11 21:40:34 +01:00
Adnan Hajdarevic
027f2d7363 Fix tests 2017-11-07 19:22:32 +01:00
Adnan Hajdarevic
8c96ffd5f9 use /bin/true instead of /usr/bin/true 2017-09-14 20:50:59 +02:00
Ivan Pesin
241061c26d Improved TestStaticParams to check for log ouput 2017-09-10 21:08:15 -05:00
Ivan Pesin
c6febd35b5 Added a test for command static parameters handling 2017-09-10 19:35:08 -05:00
Will Rouesnel
53ec2e7acc Add tests for YAML file parsing. 2017-06-29 02:34:58 +10:00
Mathias Merscher
ddb1f2441a make http return code for mismatched rules configurable
Signed-off-by: Mathias Merscher <Mathias.Merscher@dg-i.net>
2017-02-10 12:32:11 +01:00
Adnan Hajdarevic
cc0d9b2cba fix tests, return raw output, return 500 if the command did not execute properly - fixes #87
return raw stdout instead of json wrapped message - fixes #88
2016-09-29 19:57:06 +02:00
Cameron Moore
d2e315d9c6 Fix environment and argument passing
Two issues are addressed in this commit:

1. Instead of only sending the predefined environment arguments, this
commit appends the arguments to the existing OS environment.  Fixes #53.

2. If an argument is not found in the payload, allow the command to run
and pass in an empty string as a placeholder.  Fixes #54.

Additionally, I replaced `hook.ErrInvalidPayloadSignature` with a new
`SignatureError` type so that we can embed the signature in the error.
2015-11-18 12:00:47 -06:00
Cameron Moore
ea3dbf3438 Add environment arguments and improve testing
There's a lot in this commit.

 1. Add `pass-environment-to-command` option that works much like
 `pass-arguments-to-command`.  You can see an example usage in the
 "github" test case.

 2. Add a test program called "hookecho" that is used to test the
 webhook package instead of relying upon a system `echo` command.

 3. Move hooks_test.json to a template so that we can update the path to
 hookecho on the fly.

 4. Don't return an error at the end of hook.MatchRule.Evaluate().  All
 tests succeed for me now.
2015-11-02 15:11:23 -06:00
Cameron Moore
802f3f572c Add testing framework for main webhook app
This commit adds a testing framework modeled after the godoc tests. It builds
webhook in a temporary directory, runs it with the supplied `hooks_test.json`
configuration, and then tests different payloads.  I use `/bin/echo` for the
test executable, so I've added build tags to exclude Windows.

Three minor (I hope) changes in functionality:

- I ended up moving everything from `init()` to `main()` because `init()` was
  firing while trying to build the tests, and it was dying since `hooks.json`
  didn't exist. I'm still not 100% sure `init()` was firing, but I didn't see
  any real need for anything to be in `init()` in the first place.

- make sure logger is using `os.Stderr`

- don't send `http.StatusBadRequest` when the Hook rules don't match.  "Bad
  Request" is used to identify malformed requests.  The request was properly
  formed and processed, so I think we should send back `http.StatusOK`.  For
  example, if I setup a webhook rule to only execute when commits are made to
  the `master` branch, we shouldn't send back `http.StatusBadRequest` when we
  ingest a payload for the `development` branch.

The test payloads are pretty verbose and could probably be shortened, but I kind
of like having an example payload for each service.  We can pare them down if we
want to do more focused, minimalist testing.
2015-10-30 21:32:48 -05:00