This repository was archived by the owner on Jul 19, 2025. It is now read-only.
File tree Expand file tree Collapse file tree 1 file changed +41
-0
lines changed Expand file tree Collapse file tree 1 file changed +41
-0
lines changed Original file line number Diff line number Diff line change 1+ require "spec_helper"
2+
3+ class CC ::Service
4+ describe SafeWebhook do
5+ describe ".ensure_safe!" do
6+ it "does not allow internal URLs" do
7+ %w[ 127.0.0.1 192.168.0.1 10.0.1.18 ] . each do |address |
8+ stub_resolv ( "github.com" , address )
9+
10+ expect do
11+ SafeWebhook . ensure_safe! ( "https://github.com/api/v1/user" )
12+ end . to raise_error ( SafeWebhook ::InternalWebhookError )
13+ end
14+ end
15+
16+ it "allows internal URLs when configured to do so" do
17+ allow ( ENV ) . to receive ( :[] ) .
18+ with ( "CODECLIMATE_ALLOW_INTERNAL_WEBHOOKS" ) .
19+ and_return ( "1" )
20+
21+ stub_resolv ( "github.com" , "10.0.1.18" )
22+
23+ SafeWebhook . ensure_safe! ( "https://github.com/api/v1/user" )
24+ end
25+
26+ it "allows non-internal URLs" do
27+ stub_resolv ( "github.com" , "1.1.1.2" )
28+
29+ SafeWebhook . ensure_safe! ( "https://github.com/api/v1/user" )
30+ end
31+
32+ it "ensures future dns queries get the same answer" do
33+ stub_resolv ( "github.com" , "1.1.1.3" )
34+
35+ SafeWebhook . ensure_safe! ( "https://github.com/api/v1/user" )
36+
37+ expect ( Resolv . getaddress ( "github.com" ) . to_s ) . to eq "1.1.1.3"
38+ end
39+ end
40+ end
41+ end
You can’t perform that action at this time.
0 commit comments