File: socksify_proxy_spec.rb

package info (click to toggle)
ruby-em-http-request 1.1.2-2
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 628 kB
  • ctags: 243
  • sloc: ruby: 3,478; makefile: 2
file content (60 lines) | stat: -rw-r--r-- 1,699 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
require 'helper'

requires_connection do

  requires_port(8080) do
    describe EventMachine::HttpRequest do

      # ssh -D 8080 igvita
      let(:proxy) { {:proxy => { :host => '127.0.0.1', :port => 8080, :type => :socks5 }} }

      it "should use SOCKS5 proxy" do
        EventMachine.run {
          http = EventMachine::HttpRequest.new('http://jsonip.com/', proxy).get

          http.errback { failed(http) }
          http.callback {
            http.response_header.status.should == 200
            http.response.should match('173.230.151.99')
            EventMachine.stop
          }
        }
      end
    end
  end

  requires_port(8081) do
    describe EventMachine::HttpRequest do

      # brew install tinyproxy
      let(:http_proxy) { {:proxy => { :host => '127.0.0.1', :port => 8081 }} }

      it "should use HTTP proxy by default" do
        EventMachine.run {
          http = EventMachine::HttpRequest.new('http://jsonip.com/', http_proxy).get

          http.errback { failed(http) }
          http.callback {
            http.response_header.status.should == 200
            http.response.should match(/\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}/)
            EventMachine.stop
          }
        }
      end

      it "should auto CONNECT via HTTP proxy for HTTPS requests" do
        EventMachine.run {
          http = EventMachine::HttpRequest.new('https://ipjson.herokuapp.com/', http_proxy).get

          http.errback { failed(http) }
          http.callback {
            http.response_header.status.should == 200
            http.response.should match(/\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}/)
            EventMachine.stop
          }
        }
      end
    end
  end

end