mirror of
https://github.com/discourse/discourse.git
synced 2024-11-29 04:03:57 -06:00
FIX: strip webhook payload_url
This commit is contained in:
parent
4b53be81cf
commit
3c56c9b637
@ -71,7 +71,7 @@ module Jobs
|
||||
end
|
||||
|
||||
def web_hook_request(args, web_hook)
|
||||
uri = URI(web_hook.payload_url)
|
||||
uri = URI(web_hook.payload_url.strip)
|
||||
|
||||
conn = Excon.new(
|
||||
uri.to_s,
|
||||
|
@ -13,6 +13,8 @@ class WebHook < ActiveRecord::Base
|
||||
validates_presence_of :last_delivery_status
|
||||
validates_presence_of :web_hook_event_types, unless: :wildcard_web_hook?
|
||||
|
||||
before_save :strip_url
|
||||
|
||||
def self.content_types
|
||||
@content_types ||= Enum.new('application/json' => 1,
|
||||
'application/x-www-form-urlencoded' => 2)
|
||||
@ -47,6 +49,10 @@ class WebHook < ActiveRecord::Base
|
||||
def self.enqueue_post_hooks(event, post, user = nil)
|
||||
WebHook.enqueue_hooks(:post, post_id: post.id, category_id: post&.topic&.category_id, event_name: event.to_s)
|
||||
end
|
||||
|
||||
def strip_url
|
||||
self.payload_url = (payload_url || "").strip.presence
|
||||
end
|
||||
end
|
||||
|
||||
# == Schema Information
|
||||
|
@ -35,9 +35,13 @@ describe WebHook do
|
||||
end
|
||||
|
||||
context 'web hooks' do
|
||||
let!(:post_hook) { Fabricate(:web_hook) }
|
||||
let!(:post_hook) { Fabricate(:web_hook, payload_url: " https://example.com ") }
|
||||
let!(:topic_hook) { Fabricate(:topic_web_hook) }
|
||||
|
||||
it "removes whitspace from payload_url before saving" do
|
||||
expect(post_hook.payload_url).to eq("https://example.com")
|
||||
end
|
||||
|
||||
describe '#find_by_type' do
|
||||
it 'find relevant hooks' do
|
||||
expect(WebHook.find_by_type(:post)).to eq([post_hook])
|
||||
|
Loading…
Reference in New Issue
Block a user