about summary refs log tree commit diff
path: root/spec
diff options
context:
space:
mode:
authorAkihiko Odaki <akihiko.odaki.4i@stu.hosei.ac.jp>2018-02-25 03:16:11 +0900
committerEugen Rochko <eugen@zeonfederated.com>2018-02-24 19:16:11 +0100
commit2e8a492e8843aa958c53636b24cf4d344e7ca47d (patch)
treee921f2ad9ecde98d57f7a65ff3d729ff003ec5d4 /spec
parent7cb49eaa3aad03b60a1e1620d2f700d6ed2b3ea0 (diff)
Raise Mastodon::HostValidationError when host for HTTP request is private (#6410)
Diffstat (limited to 'spec')
-rw-r--r--spec/lib/request_spec.rb31
1 files changed, 23 insertions, 8 deletions
diff --git a/spec/lib/request_spec.rb b/spec/lib/request_spec.rb
index 782f14b18..dc7daa52c 100644
--- a/spec/lib/request_spec.rb
+++ b/spec/lib/request_spec.rb
@@ -38,17 +38,32 @@ describe Request do
   end
 
   describe '#perform' do
-    before do
-      stub_request(:get, 'http://example.com')
-      subject.perform
-    end
+    context 'with valid host' do
+      before do
+        stub_request(:get, 'http://example.com')
+        subject.perform
+      end
+
+      it 'executes a HTTP request' do
+        expect(a_request(:get, 'http://example.com')).to have_been_made.once
+      end
 
-    it 'executes a HTTP request' do
-      expect(a_request(:get, 'http://example.com')).to have_been_made.once
+      it 'sets headers' do
+        expect(a_request(:get, 'http://example.com').with(headers: subject.headers)).to have_been_made
+      end
     end
 
-    it 'sets headers' do
-      expect(a_request(:get, 'http://example.com').with(headers: subject.headers)).to have_been_made
+    context 'with private host' do
+      around do |example|
+        WebMock.disable!
+        example.run
+        WebMock.enable!
+      end
+
+      it 'raises Mastodon::ValidationError' do
+        allow(IPSocket).to receive(:getaddress).with('example.com').and_return('0.0.0.0')
+        expect{ subject.perform }.to raise_error Mastodon::ValidationError
+      end
     end
   end
 end