Skip to content
This repository was archived by the owner on Jul 19, 2025. It is now read-only.

Commit 290f407

Browse files
committed
Add test for SafeWebhook
1 parent c1d9216 commit 290f407

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
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

0 commit comments

Comments
 (0)