Skip to content

Commit f7dc37a

Browse files
authored
Merge pull request #1454 from Shopify/tdickers/0.44-log-unrecognized-github-org
v0.44.0: log when webhook is received for unknown github organization.
2 parents 81c9247 + 14e0828 commit f7dc37a

File tree

5 files changed

+35
-2
lines changed

5 files changed

+35
-2
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

Gemfile.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
PATH
22
remote: .
33
specs:
4-
shipit-engine (0.43.4)
4+
shipit-engine (0.44.0)
55
active_model_serializers (~> 0.9.3)
66
ansi_stream (~> 0.0.6)
77
autoprefixer-rails (~> 6.4.1)

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.4'
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)