File: ssl_spec.rb

package info (click to toggle)
ruby-em-http-request 1.1.7-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 680 kB
  • sloc: ruby: 4,011; makefile: 5
file content (71 lines) | stat: -rw-r--r-- 1,968 bytes parent folder | download
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
61
62
63
64
65
66
67
68
69
70
71
require 'helper'

requires_connection do

  describe EventMachine::HttpRequest do
    it "should initiate SSL/TLS on HTTPS connections" do
      EventMachine.run {
        http = EventMachine::HttpRequest.new('https://mail.google.com:443/mail/').get

        http.errback { failed(http) }
        http.callback {
          http.response_header.status.should == 302
          EventMachine.stop
        }
      }
    end

    describe "TLS hostname verification" do
      before do
        @cve_warning = "[WARNING; em-http-request] TLS hostname validation is disabled (use 'tls: {verify_peer: true}'), see" +
                       " CVE-2020-13482 and https://github.com/igrigorik/em-http-request/issues/339 for details"
        @orig_stderr = $stderr
        $stderr = StringIO.new
      end

      after do
        $stderr = @orig_stderr
      end

      it "should not warn if verify_peer is specified" do
        EventMachine.run {
          http = EventMachine::HttpRequest.new('https://mail.google.com:443/mail', {tls: {verify_peer: false}}).get

          http.callback {
            $stderr.rewind
            $stderr.string.chomp.should_not eq(@cve_warning)

            EventMachine.stop
          }
        }
      end

      it "should not warn if verify_peer is true" do
        EventMachine.run {
          http = EventMachine::HttpRequest.new('https://mail.google.com:443/mail', {tls: {verify_peer: true}}).get

          http.callback {
            $stderr.rewind
            $stderr.string.chomp.should_not eq(@cve_warning)

            EventMachine.stop
          }
        }
      end

      it "should warn if verify_peer is unspecified" do
        EventMachine.run {
          http = EventMachine::HttpRequest.new('https://mail.google.com:443/mail').get

          http.callback {
            $stderr.rewind
            $stderr.string.chomp.should eq(@cve_warning)

            EventMachine.stop
          }
        }
      end
    end
  end

end