Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Unreleased

# 0.44.0
* Return 422 and log when a webhook is from an unknown (unconfigured) GitHub organization.

# 0.43.3
* (bugfix) Ensure we always call `bundle config set without`, even if the without group is empty

Expand Down
2 changes: 1 addition & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
shipit-engine (0.43.4)
shipit-engine (0.44.0)
active_model_serializers (~> 0.9.3)
ansi_stream (~> 0.0.6)
autoprefixer-rails (~> 6.4.1)
Expand Down
10 changes: 10 additions & 0 deletions app/controllers/shipit/webhooks_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,16 @@ def verify_signature
"signature=#{request.headers['X-Hub-Signature']}",
"status=#{status}"
].join(' '))
rescue Shipit::GithubOrganizationUnknown => e
head(422)
Rails.logger.warn([
'WebhookController#verify_signature',
'Webhook from unknown organization',
"event=#{event}",
"repository_owner=#{repository_owner}",
"unknown_organization=#{e.message}",
"status=#{status}"
].join(' '))
end

def check_if_ping
Expand Down
2 changes: 1 addition & 1 deletion lib/shipit/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true

module Shipit
VERSION = '0.43.4'
VERSION = '0.44.0'
end
20 changes: 20 additions & 0 deletions test/controllers/webhooks_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,26 @@ class WebhooksControllerTest < ActionController::TestCase
assert_response :unprocessable_entity
end

test "unknown github organization logs and returns unprocessable entity" do
@request.headers['X-Github-Event'] = 'push'

payload = JSON.parse(payload(:push_master))
payload["repository"]["owner"]["login"] = "unknown-org"

Shipit.stubs(:github).raises(Shipit::GithubOrganizationUnknown.new("unknown-org"))
Rails.logger.expects(:warn).with([
'WebhookController#verify_signature',
'Webhook from unknown organization',
"event=push",
"repository_owner=unknown-org",
"unknown_organization=unknown-org",
"status=422"
].join(' '))

post :create, body: payload.to_json, as: :json
assert_response :unprocessable_entity
end

test ":membership creates the mentioned team on the fly" do
@request.headers['X-Github-Event'] = 'membership'
assert_difference -> { Team.count }, 1 do
Expand Down