File: test_ssl_ber.rb

package info (click to toggle)
ruby-net-ldap 0.12.1-2
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 616 kB
  • ctags: 551
  • sloc: ruby: 4,064; sh: 117; makefile: 4
file content (40 lines) | stat: -rw-r--r-- 1,018 bytes parent folder | download | duplicates (2)
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
require_relative 'test_helper'
require 'timeout'

class TestSSLBER < Test::Unit::TestCase
  # Transmits str to @to and reads it back from @from.
  #
  def transmit(str)
    Timeout::timeout(1) do
      @to.write(str)
      @to.close

      @from.read
    end
  end

  def setup
    @from, @to = IO.pipe

    # The production code operates on sockets, which do need #connect called
    # on them to work. Pipes are more robust for this test, so we'll skip
    # the #connect call since it fails.
    #
    # TODO: Replace test with real socket
    # https://github.com/ruby-ldap/ruby-net-ldap/pull/121#discussion_r18746386
    flexmock(OpenSSL::SSL::SSLSocket).
      new_instances.should_receive(:connect => nil)

    @to   = Net::LDAP::Connection.wrap_with_ssl(@to)
    @from = Net::LDAP::Connection.wrap_with_ssl(@from)
  end

  def test_transmit_strings
    assert_equal "foo", transmit("foo")
  end

  def test_transmit_ber_encoded_numbers
    @to.write 1234.to_ber
    assert_equal 1234, @from.read_ber
  end
end