Skip to content
This repository has been archived by the owner on Dec 8, 2023. It is now read-only.

Commit

Permalink
Check for protocol in Webhook URLs
Browse files Browse the repository at this point in the history
This prevents an error when a user submits a webhook URL without a
protocol such as www.example.com or 192.0.2.0.
  • Loading branch information
akahn committed Oct 2, 2015
1 parent 8ef99b6 commit 3e19131
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
6 changes: 6 additions & 0 deletions services/webhook.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@ def receive_validate(errors = {})
return false
end

# Catches bare hostnames or IPs such as www.example.com or 192.0.2.0
if !uri.scheme
errors[:url] = 'Is missing protocol'
return false
end

return true
end

Expand Down
6 changes: 6 additions & 0 deletions test/webhook_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@ def test_validations
assert(!svc.receive_validate(errors))
assert_equal(1, errors.length)
assert(!errors[:url].nil?)

svc = service(:alert, {:url => "example.com/foo"}, alert_payload)
errors = {}
assert(!svc.receive_validate(errors))
assert_equal(1, errors.length)
assert(!errors[:url].nil?)
end

def test_alerts_multiple_measurements
Expand Down

0 comments on commit 3e19131

Please sign in to comment.