Skip to content

Commit 9c771ec

Browse files
committed
v0.44.0: log when webhook is received for unknown github organization.
1 parent ac07691 commit 9c771ec

File tree

4 files changed

+34
-1
lines changed

4 files changed

+34
-1
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# Unreleased
22

3+
# 0.44.0
4+
* Return 422 and log when a webhook is from an unknown (unconfigured) GitHub organization.
5+
36
# 0.43.3
47
* (bugfix) Ensure we always call `bundle config set without`, even if the without group is empty
58

app/controllers/shipit/webhooks_controller.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,16 @@ def verify_signature
3636
"signature=#{request.headers['X-Hub-Signature']}",
3737
"status=#{status}"
3838
].join(' '))
39+
rescue Shipit::GithubOrganizationUnknown => e
40+
head(422)
41+
Rails.logger.warn([
42+
'WebhookController#verify_signature',
43+
'Webhook from unknown organization',
44+
"event=#{event}",
45+
"repository_owner=#{repository_owner}",
46+
"unknown_organization=#{e.message}",
47+
"status=#{status}"
48+
].join(' '))
3949
end
4050

4151
def check_if_ping

lib/shipit/version.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# frozen_string_literal: true
22

33
module Shipit
4-
VERSION = '0.43.3'
4+
VERSION = '0.44.0'
55
end

test/controllers/webhooks_controller_test.rb

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,26 @@ class WebhooksControllerTest < ActionController::TestCase
106106
assert_response :unprocessable_entity
107107
end
108108

109+
test "unknown github organization logs and returns unprocessable entity" do
110+
@request.headers['X-Github-Event'] = 'push'
111+
112+
payload = JSON.parse(payload(:push_master))
113+
payload["repository"]["owner"]["login"] = "unknown-org"
114+
115+
Shipit.stubs(:github).raises(Shipit::GithubOrganizationUnknown.new("unknown-org"))
116+
Rails.logger.expects(:warn).with([
117+
'WebhookController#verify_signature',
118+
'Webhook from unknown organization',
119+
"event=push",
120+
"repository_owner=unknown-org",
121+
"unknown_organization=unknown-org",
122+
"status=422"
123+
].join(' '))
124+
125+
post :create, body: payload.to_json, as: :json
126+
assert_response :unprocessable_entity
127+
end
128+
109129
test ":membership creates the mentioned team on the fly" do
110130
@request.headers['X-Github-Event'] = 'membership'
111131
assert_difference -> { Team.count }, 1 do

0 commit comments

Comments
 (0)