Skip to content

Commit

Permalink
Only call webhook for POST requests
Browse files Browse the repository at this point in the history
  • Loading branch information
bkeepers committed Mar 15, 2017
1 parent 60827ea commit ca6f119
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
2 changes: 1 addition & 1 deletion github-webhook-handler.js
Expand Up @@ -36,7 +36,7 @@ function create (options) {


function handler (req, res, callback) {
if (req.url.split('?').shift() !== options.path)
if (req.url.split('?').shift() !== options.path || req.method !== 'POST')
return callback()

function hasError (msg) {
Expand Down
19 changes: 18 additions & 1 deletion test.js
Expand Up @@ -11,8 +11,9 @@ function signBlob (key, blob) {
}


function mkReq (url) {
function mkReq (url, method) {
var req = through2()
req.method = method || 'POST'
req.url = url
req.headers = {
'x-hub-signature' : 'bogus'
Expand Down Expand Up @@ -76,6 +77,22 @@ test('handler ignores invalid urls', function (t) {
})
})

test('handler ingores non-POST requests', function (t) {
var options = { path: '/some/url', secret: 'bogus' }
, h = handler(options)

t.plan(4)

h(mkReq('/some/url', 'GET'), mkRes(), function (err) {
t.error(err)
t.ok(true, 'request was ignored')
})

h(mkReq('/some/url?test=param', 'GET'), mkRes(), function (err) {
t.error(err)
t.ok(true, 'request was ignored')
})
})

test('handler accepts valid urls', function (t) {
var options = { path: '/some/url', secret: 'bogus' }
Expand Down

0 comments on commit ca6f119

Please sign in to comment.